-
Notifications
You must be signed in to change notification settings - Fork 2
/
DISTRICT.txt
328 lines (327 loc) · 13.8 KB
/
DISTRICT.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
IDENTIFICATION DIVISION.
PROGRAM-ID
DISTRICT.
*
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SALES ASSIGN TO SALES
FILE STATUS IS SALES-FS.
SELECT RPTA ASSIGN TO RPTA.
SELECT RPTB ASSIGN TO RPTB.
*
DATA DIVISION.
FILE SECTION.
FD SALES.
01 SALES-IN.
05 FIRST-NAME PIC X(15).
05 LAST-NAME PIC X(20).
05 DISTRICT-NUM PIC 9(3).
05 SSNUM PIC 9(9).
05 QTR-SALE OCCURS 4 TIMES PIC 9(6)V99.
05 FILLER PIC X.
FD RPTA.
01 RPT-OUTA PIC X(132).
FD RPTB.
01 RPT-OUTB PIC X(80).
*
WORKING-STORAGE SECTION.
77 EOF-FLAG PIC XXX.
77 BLANK-LINE PIC X(132) VALUE SPACES.
77 BLANK-LINE-SMALL PIC X(80) VALUE SPACES.
77 TOTAL-EMPS PIC 999 VALUE 0.
77 TOTAL-DISTRICTS PIC 999 VALUE 0.
77 LOOP-COUNTER PIC 999 VALUE 0.
77 GRAND-TOTALS PIC 9(6)V99.
77 TOTAL-GRAND-TOTALS PIC 9(6)V99.
77 DISTRICT-TOTALS PIC 9(6)V99.
77 SALES-FS PIC 99 VALUE 0.
77 DOTS PIC X(36) VALUE ALL '.'.
*
01 REPORT-VALUES.
05 PAGE-NUMBER PIC 9(4).
05 PAGE-NUMBER-B PIC 9(4).
05 LINES-PRINTED PIC 99 VALUE 66.
05 LINES-PER-PAGE PIC 99 VALUE 66.
05 LINES-PRINTED-B PIC 99 VALUE 66.
05 RECORD-COUNTER PIC 9(4).
*
01 CURRENT-DATE-FIELDS PIC X(21).
01 CURRENT-DATE-INFO REDEFINES CURRENT-DATE-FIELDS.
05 CURRENT-DATE-DIGITS.
10 CURRENT-YEAR PIC 9(4).
10 CURRENT-MONTH PIC 99.
10 CURRENT-DAY PIC 99.
05 CURRENT-TIME-DIGITS.
10 CURRENT-HOUR PIC 99.
10 CURRENT-MINUTE PIC 99.
10 CURRENT-SECOND PIC 99.
05 DIFF-FROM-GMT PIC 9(4).
*
01 REPORT-DATE.
05 CURRENT-MONTH PIC 99.
05 CURRENT-DAY PIC 99.
05 CURRENT-YEAR PIC 9(4).
*
01 PAGE-HEADER.
05 DATE-FIELD PIC 99/99/9999.
05 PIC X(44) VALUE SPACES.
05 PIC X(23) VALUE 'ANNUAL SALES FOR AGENTS'.
05 PIC X(45) VALUE SPACES.
05 PIC X(6) VALUE 'PAGE #'.
05 PAGE-NUM PIC 9(4).
*
01 PAGE-HEADER-B.
05 DATE-FIELD-B PIC 99/99/9999.
05 PIC X(18) VALUE SPACES.
05 PIC X(24) VALUE
'ANNUAL SALES BY DISTRICT'.
05 PIC X(18) VALUE SPACES.
05 PIC X(6) VALUE 'PAGE #'.
05 PAGE-NUM-B PIC 9(4).
*
01 COLUMN-HEADER.
05 PIC X(5) VALUE SPACES.
05 PIC X(11) VALUE 'SS NUMBER'.
05 PIC XX VALUE SPACES.
05 PIC X(21) VALUE
'LAST NAME, FIRST NAME'.
05 PIC X(17) VALUE SPACES.
05 PIC X(11) VALUE 'QUARTER #1 '.
05 PIC XX VALUE SPACES.
05 PIC X(11) VALUE 'QUARTER #2 '.
05 PIC XX VALUE SPACES.
05 PIC X(11) VALUE 'QUARTER #3 '.
05 PIC XX VALUE SPACES.
05 PIC X(11) VALUE 'QUARTER #4 '.
05 PIC XX VALUE SPACES.
05 PIC X(11) VALUE 'AVG SALES '.
05 PIC XX VALUE SPACES.
05 PIC X(11) VALUE 'GRAND TOTAL'.
*
01 COLUMN-RULER.
05 PIC X(5) VALUE SPACES.
05 PIC X(11) VALUE ALL '='.
05 PIC XX VALUE SPACES.
05 PIC X(36) VALUE ALL '='.
05 PIC XX VALUE SPACES.
05 PIC X(11) VALUE ALL '='.
05 PIC XX VALUE SPACES.
05 PIC X(11) VALUE ALL '='.
05 PIC XX VALUE SPACES.
05 PIC X(11) VALUE ALL '='.
05 PIC XX VALUE SPACES.
05 PIC X(11) VALUE ALL '='.
05 PIC XX VALUE SPACES.
05 PIC X(11) VALUE ALL '='.
05 PIC XX VALUE SPACES.
05 PIC X(11) VALUE ALL '='.
*
01 DISTRICT-HEADER.
05 PIC X VALUE SPACES.
05 PIC X(9) VALUE 'DISTRICT '.
05 DISTRICT-NUM PIC 9(3) VALUE 0.
05 PIC X(119) VALUE SPACES.
*
01 DETAIL-LINE.
05 PIC X(5) VALUE SPACES.
05 SSNUM PIC 999/99/9999.
05 PIC XX VALUE SPACES.
05 LAST-NAME PIC X(20).
05 PIC X VALUE ','.
05 FIRST-NAME PIC X(15).
05 PIC XX VALUE SPACES.
05 QTR-SALE1 PIC $ZZZ,ZZ9.99.
05 PIC XX VALUE SPACES.
05 QTR-SALE2 PIC $ZZZ,ZZ9.99.
05 PIC XX VALUE SPACES.
05 QTR-SALE3 PIC $ZZZ,ZZ9.99.
05 PIC XX VALUE SPACES.
05 QTR-SALE4 PIC $ZZZ,ZZ9.99.
05 PIC XX VALUE SPACES.
05 AVG-SALE PIC $ZZZ,ZZ9.99.
05 PIC XX VALUE SPACES.
05 GRAND-TOTAL PIC $ZZZ,ZZ9.99.
*
01 DETAIL-LINE-B.
05 DISTRICT-NUM PIC 9(3).
05 PIC X(5) VALUE SPACES.
05 DISTRICT-TOTAL PIC $ZZZ,ZZ9.99.
05 PIC X(61) VALUE SPACES.
*
01 ANNUAL-RULER.
05 PIC X(121) VALUE SPACES.
05 PIC X(11) VALUE ALL '='.
*
01 DISTRICT-FOOTER.
05 PIC X(18) VALUE SPACES.
05 PIC X(17) VALUE 'TOTAL EMPLOYEES: '.
05 TOTAL-EMP PIC 999 VALUE 0.
05 PIC X(83) VALUE SPACES.
05 DISTRICT-TOTAL PIC $ZZZ,ZZ9.99.
*
01 DASHES-LINE.
05 PIC X(60) VALUE ALL '-'.
05 PIC X(12) VALUE 'Report Recap'.
05 PIC X(60) VALUE ALL '-'.
*
01 TOTAL-LINE.
05 PIC X(9) VALUE SPACES.
05 PIC X(13) VALUE 'GRAND TOTAL: '.
05 GRAND-TOTAL PIC $ZZZ,ZZ9.99.
05 PIC XX VALUE SPACES.
05 PIC X(17) VALUE 'TOTAL DISTRICTS: '.
05 TOTAL-DISTRICT PIC 999 VALUE 0.
05 PIC XX VALUE SPACES.
05 PIC X(17) VALUE 'TOTAL EMPLOYEES: '.
05 TOTAL-EMP PIC 999 VALUE 0.
05 PIC X(55) VALUE SPACES.
*
01 TOTAL-LINE-B.
05 PIC X(9) VALUE SPACES.
05 PIC X(13) VALUE 'GRAND TOTAL: '.
05 GRAND-TOTAL PIC $ZZZ,ZZ9.99.
05 PIC XX VALUE SPACES.
05 PIC X(17) VALUE 'TOTAL DISTRICTS: '.
05 TOTAL-DISTRICT PIC 999 VALUE 0.
05 PIC XX VALUE SPACES.
05 PIC X(17) VALUE 'TOTAL EMPLOYEES: '.
05 TOTAL-EMP PIC 999 VALUE 0.
05 PIC X(3) VALUE SPACES.
*
PROCEDURE DIVISION.
MAIN-LINE-ROUTINE.
OPEN INPUT SALES.
OPEN OUTPUT RPTA.
OPEN OUTPUT RPTB.
MOVE 'NO' TO EOF-FLAG.
MOVE FUNCTION CURRENT-DATE TO CURRENT-DATE-FIELDS.
MOVE CORRESPONDING CURRENT-DATE-DIGITS TO REPORT-DATE.
MOVE REPORT-DATE (1:8) TO DATE-FIELD.
MOVE REPORT-DATE (1:8) TO DATE-FIELD-B.
READ SALES RECORD.
PERFORM PROCESS-REPORT
UNTIL EOF-FLAG = 'YES'.
READ SALES RECORD AT END MOVE 'YES' TO EOF-FLAG.
CLOSE SALES.
CLOSE RPTA.
CLOSE RPTB.
STOP RUN.
*
PROCESS-REPORT.
PERFORM PROCESS-HEADER.
PERFORM PROCESS-DISTRICT-HEADER.
PERFORM PROCESS-DETAIL-LINE.
PERFORM PROCESS-DISTRICT-FOOTER.
IF EOF-FLAG = 'YES'
PERFORM PROCESS-END-OF-REPORT
END-IF.
*
PROCESS-HEADER.
IF LINES-PRINTED = 66
ADD 1 TO PAGE-NUMBER
INITIALIZE LINES-PRINTED
MOVE PAGE-NUMBER TO PAGE-NUM
MOVE PAGE-HEADER TO RPT-OUTA
WRITE RPT-OUTA
MOVE BLANK-LINE TO RPT-OUTA
WRITE RPT-OUTA
MOVE COLUMN-HEADER TO RPT-OUTA
WRITE RPT-OUTA
MOVE COLUMN-RULER TO RPT-OUTA
WRITE RPT-OUTA
ADD 4 TO LINES-PRINTED
END-IF.
IF LINES-PRINTED-B = 66
ADD 1 TO PAGE-NUMBER-B
MOVE PAGE-NUMBER-B TO PAGE-NUM-B
MOVE PAGE-HEADER-B TO RPT-OUTB
WRITE RPT-OUTB
MOVE BLANK-LINE TO RPT-OUTB
WRITE RPT-OUTB
ADD 2 TO LINES-PRINTED-B
END-IF.
*
PROCESS-DISTRICT-HEADER.
IF DISTRICT-NUM IN SALES-IN
NOT EQUAL TO DISTRICT-NUM IN DISTRICT-HEADER
MOVE BLANK-LINE TO RPT-OUTA
WRITE RPT-OUTA
INITIALIZE TOTAL-EMPS
INITIALIZE DISTRICT-TOTALS
MOVE DISTRICT-NUM IN SALES-IN
TO DISTRICT-NUM IN DISTRICT-HEADER
MOVE DISTRICT-HEADER TO RPT-OUTA
WRITE RPT-OUTA
ADD 2 TO LINES-PRINTED
ADD 1 TO TOTAL-DISTRICTS
END-IF.
*
PROCESS-DETAIL-LINE.
ADD 1 TO TOTAL-EMPS.
ADD 1 TO TOTAL-EMP IN TOTAL-LINE.
ADD 1 TO TOTAL-EMP IN TOTAL-LINE-B.
INITIALIZE GRAND-TOTALS, AVG-SALE.
MOVE DOTS TO DETAIL-LINE (19:54).
STRING LAST-NAME OF SALES-IN DELIMITED BY " "
", " DELIMITED BY SIZE
FIRST-NAME OF SALES-IN DELIMITED BY " "
INTO DETAIL-LINE (19:).
MOVE SSNUM IN SALES-IN TO SSNUM IN DETAIL-LINE.
MOVE QTR-SALE(1) TO QTR-SALE1.
MOVE QTR-SALE(2) TO QTR-SALE2.
MOVE QTR-SALE(3) TO QTR-SALE3.
MOVE QTR-SALE(4) TO QTR-SALE4.
MOVE 1 TO LOOP-COUNTER.
PERFORM UNTIL LOOP-COUNTER = 5
ADD QTR-SALE(LOOP-COUNTER) TO GRAND-TOTALS
ADD 1 TO LOOP-COUNTER
END-PERFORM.
DIVIDE GRAND-TOTALS BY 4 GIVING AVG-SALE.
MOVE GRAND-TOTALS TO GRAND-TOTAL IN DETAIL-LINE.
ADD GRAND-TOTALS TO DISTRICT-TOTALS.
ADD GRAND-TOTALS TO TOTAL-GRAND-TOTALS.
MOVE DETAIL-LINE TO RPT-OUTA.
WRITE RPT-OUTA.
ADD 1 TO LINES-PRINTED.
READ SALES RECORD AT END MOVE 'YES' TO EOF-FLAG.
*
PROCESS-DISTRICT-FOOTER.
IF DISTRICT-NUM IN SALES-IN
NOT EQUAL DISTRICT-NUM IN DISTRICT-HEADER
OR EOF-FLAG = 'YES'
MOVE COLUMN-RULER TO RPT-OUTA
WRITE RPT-OUTA
MOVE TOTAL-EMPS TO TOTAL-EMP IN DISTRICT-FOOTER
MOVE DISTRICT-TOTALS TO DISTRICT-TOTAL
IN DISTRICT-FOOTER
MOVE DISTRICT-FOOTER TO RPT-OUTA
WRITE RPT-OUTA
ADD 2 TO LINES-PRINTED
MOVE DISTRICT-NUM IN DISTRICT-HEADER TO DISTRICT-NUM
IN DETAIL-LINE-B
MOVE DISTRICT-TOTALS TO DISTRICT-TOTAL
IN DETAIL-LINE-B
MOVE DETAIL-LINE-B TO RPT-OUTB
WRITE RPT-OUTB
ADD 1 TO LINES-PRINTED-B
END-IF.
*
PROCESS-END-OF-REPORT.
MOVE BLANK-LINE TO RPT-OUTA.
WRITE RPT-OUTA.
WRITE RPT-OUTA.
MOVE DASHES-LINE TO RPT-OUTA.
WRITE RPT-OUTA.
MOVE TOTAL-DISTRICTS TO TOTAL-DISTRICT IN TOTAL-LINE.
MOVE TOTAL-GRAND-TOTALS TO GRAND-TOTAL IN TOTAL-LINE.
MOVE TOTAL-LINE TO RPT-OUTA.
WRITE RPT-OUTA.
ADD 4 TO LINES-PRINTED.
MOVE BLANK-LINE TO RPT-OUTB.
WRITE RPT-OUTB.
MOVE TOTAL-DISTRICTS TO TOTAL-DISTRICT IN TOTAL-LINE-B.
MOVE TOTAL-GRAND-TOTALS TO GRAND-TOTAL IN TOTAL-LINE-B.
MOVE TOTAL-LINE-B TO RPT-OUTB.
WRITE RPT-OUTB.
ADD 2 TO LINES-PRINTED-B.