-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproject3.cbl
470 lines (417 loc) · 17.8 KB
/
project3.cbl
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
******************************************************************
* Author: Tyler BRown
* Date: 11/19/2017
* Purpose: create a report form file PR3FA17.txt
* Tectonics: cobc -xo PROJECT3.exe --std=mf PROJECT3.cbl
******************************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. PROJECT3.
**************************COMMENT SECTION*************************
*THIS PROGRAM PRODUCES AN SALES REPORT FOR DR. CHEEB WITH ALL
*FINAL SALES VALUES AND HOW MANY PRODUCTS HAVE BEEN SOLD
******************************************************************
************************ENVIRONMENT DIVISION**********************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT UNSORTED-FILE
ASSIGN TO "PR3FA17.txt"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT SORTED-FILE
ASSIGN TO "PR3 SORTED.TXT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT REPORT-FILE ASSIGN TO "PROJECT 3 REPORT.TXT".
SELECT SORT-FILE
ASSIGN TO PRINTER "SORT.TMP".
***********************DATA DIVISION******************************
DATA DIVISION.
FILE SECTION.
FD UNSORTED-FILE
RECORD CONTAINS 126 CHARACTERS.
01 UNSORTED-RECORD.
05 US-WAREHOUSE-STATE PIC A(2).
05 FILLER PIC X(1).
05 US-WAREHOUSE-CITY PIC X(2).
05 FILLER PIC X(1).
05 US-CUSTOMER-ID PIC X(2).
05 US-CUSTOMER-NAME PIC X(20).
05 US-CUSTOMER-RATING PIC 9(1).
05 FILLER PIC X(1).
05 PRODUCT-DATA OCCURS 6 TIMES.
10 US-PRODUCT-ID PIC X(5).
10 US-PRODUCT-CODE PIC X(1).
10 US-NUMBER-BOXES PIC 9(3).
10 US-BOX-PRICE PIC 999V99.
10 US-MOUNTH-BOUGHT PIC 99.
FD SORTED-FILE
RECORD CONTAINS 126 CHARACTERS.
01 SORTED-RECORD.
05 WAREHOUSE-STATE PIC A(2).
05 FILLER PIC X(1).
05 WAREHOUSE-CITY PIC X(2).
05 FILLER PIC X(1).
05 CUSTOMER-ID PIC X(2).
05 CUSTOMER-NAME PIC X(20).
05 CUSTOMER-RATING PIC 9(1).
05 FILLER PIC X(1).
05 PRODUCT-DATA OCCURS 6 TIMES.
10 PRODUCT-ID PIC X(5) VALUE SPACES.
10 PRODUCT-CODE PIC X(1) VALUE SPACES.
10 NUMBER-BOXES PIC 9(3) VALUE ZEROES.
10 BOX-PRICE PIC 999V99 VALUE ZEROES.
10 MOUNTH-BOUGHT PIC 99 VALUE ZEROES.
FD REPORT-FILE.
01 REPORT-RECORD PIC X(56).
SD SORT-FILE.
01 SORT-RECORD.
05 S-WAREHOUSE-STATE PIC A(2).
05 FILLER PIC X(1).
05 S-WAREHOUSE-CITY PIC X(2).
05 FILLER PIC X(1).
05 S-CUSTOMER-ID PIC X(2).
05 S-CUSTOMER-NAME PIC X(20).
05 S-CUSTOMER-RATING PIC 9(1).
05 FILLER PIC X(1).
05 S-PRODUCT-DATA OCCURS 6 TIMES.
10 S-PRODUCT-ID PIC X(5).
10 S-PRODUCT-CODE PIC X(1).
10 S-NUMBER-BOXES PIC 9(3).
10 S-BOX-PRICE PIC 999V99.
10 S-MOUNTH-BOUGHT PIC 99.
WORKING-STORAGE SECTION.
01 FLAGS-N-SWITCHES.
05 EOF-FLAG PIC X VALUE ' '.
88 NO-MORE-DATA VALUE 'N'.
88 MORE-RECORDS VALUE 'Y'.
05 FIRST-RECORD PIC X(3) VALUE 'YES'.
05 SUB PIC 9 VALUE ZERO.
01 REPORT-FIELDS.
05 PROPER-SPACING PIC S9 VALUE +1.
05 LINE-COUNT PIC S9(2) VALUE +0.
05 PAGE-NO PIC S9(2) VALUE +0.
01 STATE-TEXT.
05 PIC X(9) VALUE "ALALABAMA".
05 PIC X(9) VALUE "GAGEORGIA".
01 STATE-TABLE REDEFINES STATE-TEXT.
05 STATE-ITEM OCCURS 2 TIMES INDEXED BY STA-INDEX.
10 ST-CODE PIC X(2).
10 ST-NAME PIC X(7).
01 CITY-TEXT.
05 PIC X(12) VALUE "BMBirmingham".
05 PIC X(12) VALUE "HUHuntsville".
05 PIC X(12) VALUE "MOMobile".
05 PIC X(12) VALUE "ATAtlanta".
05 PIC X(12) VALUE "SASavannah".
05 PIC X(12) VALUE "VAValdosta".
01 CITY-TABLE REDEFINES CITY-TEXT.
05 CITY-ITEM OCCURS 6 TIMES INDEXED BY CT-INDEX.
10 CT-CODE PIC X(2).
10 CT-NAME PIC X(10).
01 MONTH-TEXT.
05 PIC X(11) VALUE "01January".
05 PIC X(11) VALUE "02February".
05 PIC X(11) VALUE "03March".
05 PIC X(11) VALUE "04April".
05 PIC X(11) VALUE "05May".
05 PIC X(11) VALUE "06June".
05 PIC X(11) VALUE "07July".
05 PIC X(11) VALUE "08August".
05 PIC X(11) VALUE "09September".
05 PIC X(11) VALUE "10October".
05 PIC X(11) VALUE "11November".
05 PIC X(11) VALUE "12December".
01 MONTH-TABLE REDEFINES MONTH-TEXT.
05 MONTH-ITEM OCCURS 12 TIMES INDEXED BY MO-INDEX.
10 MO-CODE PIC X(2).
10 MO-NAME PIC X(9).
01 ACTIVITY-TEXT.
05 PIC X(11) VALUE "1AGGRESSIVE".
05 PIC X(11) VALUE "2ACTIVE".
05 PIC X(11) VALUE "3MODERATE".
05 PIC X(11) VALUE "4INACTIVE".
01 ACTIVITY-TABLE REDEFINES ACTIVITY-TEXT.
05 ACTIVITY-ITEM OCCURS 4 TIMES INDEXED BY AC-INDEX.
10 AC-CODE PIC X(1).
10 AC-NAME PIC X(10).
**************************REPORT SECTION**************************
01 DETAIL-LINE.
05 DL-PRODUCT-ID PIC X(5).
05 PIC X(2).
05 DL-PRODUCT-TYPE PIC X(8).
05 PIC X(2).
05 DL-MOUNTH-BOUGHT PIC X(9).
05 PIC X(3).
05 DL-NUM-SOLD PIC ZZ9.
05 PIC X(3).
05 DL-BOX-PRICE PIC ZZ9.99.
05 PIC X(3).
05 DL-MONTH-TOTAL-SOLD PIC $ZZZ,ZZ9.99.
01 TITLE-HEADING.
05 PIC X(26) VALUE SPACES.
05 PIC X(10) VALUE "DR. CHEEBS".
01 PAGE-HEADER-LINE.
05 PIC X(20) VALUE SPACES.
05 PIC X(20) VALUE "NEW PRODUCT ANALYSIS".
05 PIC X(9) VALUE SPACES.
05 PIC X(5) VALUE "PAGE:".
05 PAGE-OUT PIC Z9.
01 STATE-HEADING.
05 PIC X(7) VALUE "STATE: ".
05 STATE-OUT PIC X(10).
01 CITY-HEADING.
05 PIC X(7) VALUE " CITY: ".
05 CITY-OUT PIC X(10).
01 ID-HEADING.
05 PIC X(10) VALUE " ID: ".
05 CUST-ID-OUT PIC X(5).
01 NAME-HEADING.
05 PIC X(10) VALUE " NAME: ".
05 NAME-OUT PIC X(19).
01 RATING-HEADING.
05 PIC X(10) VALUE " RATING: ".
05 RATING-OUT PIC X(10).
01 CUSTOMER-HEADING-1.
05 PIC X(19) VALUE " P R O D U C T S ".
05 PIC X(23) VALUE "MONTH NUM BOX ".
05 PIC X(13) VALUE " TOTAL SOLD".
01 CUSTOMER-HEADING-2.
05 PIC X(19) VALUE " ID TYPE ".
05 PIC X(17) VALUE "BOUGHT SOLD ".
05 PIC X(18) VALUE "PRICE PER MONTH".
01 TOTAL-CUSTOMER-BREAK-LINE.
05 PIC X(27) VALUE SPACES.
05 PIC X(6) VALUE "TOTAL:".
05 PIC X(10) VALUE SPACES.
05 CUSTOMER-TOTAL-OUT PIC $$,$$$,$$9.99.
01 TOTAL-CITY-SOLD-LINE.
05 PIC X(8) VALUE SPACES.
05 PIC X(8) VALUE "CITY OF ".
05 TL-CITY-NAME PIC X(10).
05 PIC X(16) VALUE " TOTAL: ".
05 TL-CITY-SOLD PIC $$$,$$$,$$9.99.
01 TOTAL-STATE-SOLD-LINE.
05 PIC X(10) VALUE SPACES.
05 PIC X(9) VALUE "STATE OF ".
05 TL-STATE-NAME PIC X(7).
05 PIC X(12) VALUE " TOTAL: ".
05 TL-STATE-SOLD PIC $$$,$$$,$$$,$$9.99.
01 GRAND-TOTAL-SOLD-LINE.
05 PIC X(21) VALUE SPACES.
05 PIC X(13) VALUE "GRAND TOTAL: ".
05 GRAND-TOTAL-SOLD PIC $$$,$$$,$$$,$$$,$$9.99.
01 WS-TEMP.
05 SALES-MONTH-TOTAL PIC 9(13).
05 SALES-CUST-TOTAL PIC 9(13).
05 WS-STATE PIC X(7).
05 WS-CITY PIC X(15).
05 WS-CUSTOMER PIC X(5).
05 WS-CITY-TOTAL PIC 999999999V99.
05 WS-STATE-TOTAL PIC 999999999999V99.
05 WS-GRAND-TOTAL PIC 999999999999V99.
*************************PROCEDURE DIVISION***********************
PROCEDURE DIVISION.
100-MAIN-MODULE.
PERFORM 105-SORT-FILE
PERFORM 125-HOUSEKEEPING
PERFORM 150-READ-SOURCE-FILE
PERFORM 250-CLOSE-ROUTINE
.
105-SORT-FILE.
SORT SORT-FILE
ON ASCENDING KEY US-WAREHOUSE-STATE
US-WAREHOUSE-CITY
US-CUSTOMER-ID
USING UNSORTED-FILE
GIVING SORTED-FILE
.
125-HOUSEKEEPING.
OPEN INPUT SORTED-FILE
OUTPUT REPORT-FILE
MOVE 1 TO PROPER-SPACING
WRITE REPORT-RECORD FROM TITLE-HEADING
AFTER ADVANCING PROPER-SPACING
MOVE 2 TO PROPER-SPACING
PERFORM 145-PAGE-HEADING-ROUTINE
ADD 5 TO LINE-COUNT
.
145-PAGE-HEADING-ROUTINE.
MOVE 2 TO LINE-COUNT
ADD 1 TO PAGE-NO
MOVE PAGE-NO TO PAGE-OUT
WRITE REPORT-RECORD FROM PAGE-HEADER-LINE
AFTER ADVANCING PROPER-SPACING
.
150-READ-SOURCE-FILE.
MOVE "Y" TO EOF-FLAG
PERFORM UNTIL EOF-FLAG = "N"
READ SORTED-FILE
AT END
MOVE "N" TO EOF-FLAG
PERFORM 225-PUBLISH-FINAL-TOTALS
NOT AT END
PERFORM 175-CONSTRUCT-DATA
END-READ
END-PERFORM
.
175-CONSTRUCT-DATA.
PERFORM 180-BREAK-CONTROL-ROUTINE
PERFORM VARYING SUB FROM 1 BY 1 UNTIL SUB > 6
IF PRODUCT-ID(SUB) NOT = SPACES
MOVE PRODUCT-ID(SUB) TO DL-PRODUCT-ID
EVALUATE TRUE
WHEN PRODUCT-CODE(SUB) = "E"
MOVE "EDIBLES" TO DL-PRODUCT-TYPE
WHEN PRODUCT-CODE(SUB) = "O"
MOVE "OILS" TO DL-PRODUCT-TYPE
WHEN PRODUCT-CODE(SUB) = "C"
MOVE "CAPSULES" TO DL-PRODUCT-TYPE
WHEN OTHER
MOVE "BAD CODE" TO DL-PRODUCT-TYPE
END-EVALUATE
SET MO-INDEX TO 1
SEARCH MONTH-ITEM
AT END
MOVE "BAD MONTH" TO DL-MOUNTH-BOUGHT
WHEN MOUNTH-BOUGHT(SUB) = MO-CODE(MO-INDEX)
MOVE MO-NAME(MO-INDEX) TO DL-MOUNTH-BOUGHT
END-SEARCH
MOVE NUMBER-BOXES(SUB) TO DL-NUM-SOLD
MOVE BOX-PRICE(SUB) TO DL-BOX-PRICE
MULTIPLY NUMBER-BOXES(SUB) BY BOX-PRICE(SUB)
GIVING SALES-MONTH-TOTAL
ADD SALES-MONTH-TOTAL TO SALES-CUST-TOTAL
MOVE SALES-MONTH-TOTAL TO DL-MONTH-TOTAL-SOLD
WRITE REPORT-RECORD FROM DETAIL-LINE
AFTER ADVANCING PROPER-SPACING
ADD 2 TO LINE-COUNT
PERFORM 200-LINE-COUNT-CHECK
END-PERFORM
MOVE SALES-CUST-TOTAL TO CUSTOMER-TOTAL-OUT
WRITE REPORT-RECORD FROM TOTAL-CUSTOMER-BREAK-LINE
AFTER ADVANCING 3
ADD SALES-CUST-TOTAL TO WS-CITY-TOTAL
ADD SALES-CUST-TOTAL TO WS-STATE-TOTAL
ADD SALES-CUST-TOTAL TO WS-GRAND-TOTAL
MOVE ZEROES TO SALES-MONTH-TOTAL SALES-CUST-TOTAL
ADD 6 TO LINE-COUNT
.
180-BREAK-CONTROL-ROUTINE.
EVALUATE TRUE
WHEN FIRST-RECORD = "YES"
MOVE "NO" TO FIRST-RECORD
PERFORM 185-STATE-BREAK
WHEN WAREHOUSE-STATE NOT = WS-STATE
MOVE WS-CITY-TOTAL TO TL-CITY-SOLD
MOVE CITY-OUT TO TL-CITY-NAME
WRITE REPORT-RECORD FROM TOTAL-CITY-SOLD-LINE
AFTER ADVANCING PROPER-SPACING
MOVE WS-STATE-TOTAL TO TL-STATE-SOLD
MOVE STATE-OUT TO TL-STATE-NAME
WRITE REPORT-RECORD FROM TOTAL-STATE-SOLD-LINE
AFTER ADVANCING PROPER-SPACING
MOVE ZEROES TO WS-STATE-TOTAL WS-CITY-TOTAL
PERFORM 185-STATE-BREAK
WHEN WAREHOUSE-CITY NOT = WS-CITY
MOVE WS-CITY-TOTAL TO TL-CITY-SOLD
MOVE CITY-OUT TO TL-CITY-NAME
WRITE REPORT-RECORD FROM TOTAL-CITY-SOLD-LINE
AFTER ADVANCING PROPER-SPACING
PERFORM 190-CITY-BREAK
MOVE ZEROES TO WS-CITY-TOTAL
WHEN CUSTOMER-ID NOT = WS-CUSTOMER
PERFORM 195-ID-BREAK
END-EVALUATE
.
185-STATE-BREAK.
SET STA-INDEX TO 1
SEARCH STATE-ITEM
AT END
STRING "INVALID "
WAREHOUSE-STATE DELIMITED BY SIZE
INTO STATE-OUT
END-STRING
WHEN WAREHOUSE-STATE = ST-CODE(STA-INDEX)
MOVE ST-NAME(STA-INDEX) TO STATE-OUT
END-SEARCH
WRITE REPORT-RECORD FROM STATE-HEADING
AFTER ADVANCING PROPER-SPACING
MOVE WAREHOUSE-STATE TO WS-STATE
ADD 2 TO LINE-COUNT
PERFORM 200-LINE-COUNT-CHECK
PERFORM 190-CITY-BREAK
.
190-CITY-BREAK.
SET CT-INDEX TO 1
SEARCH CITY-ITEM
AT END
STRING "INVALID "
WAREHOUSE-CITY
INTO CITY-OUT
END-STRING
WHEN WAREHOUSE-CITY = CT-CODE(CT-INDEX)
MOVE CT-NAME(CT-INDEX) TO CITY-OUT WS-CITY
END-SEARCH
WRITE REPORT-RECORD FROM CITY-HEADING
AFTER ADVANCING PROPER-SPACING
MOVE WAREHOUSE-CITY TO WS-CITY
ADD 2 TO LINE-COUNT
PERFORM 200-LINE-COUNT-CHECK
PERFORM 195-ID-BREAK
.
195-ID-BREAK.
MOVE CUSTOMER-ID TO CUST-ID-OUT WS-CUSTOMER
MOVE CUSTOMER-NAME TO NAME-OUT
WRITE REPORT-RECORD FROM ID-HEADING
AFTER ADVANCING PROPER-SPACING
WRITE REPORT-RECORD FROM NAME-HEADING
AFTER ADVANCING 1
SET AC-INDEX TO 1
SEARCH ACTIVITY-ITEM
AT END
STRING "INVALID "
CUSTOMER-RATING
INTO RATING-OUT
END-STRING
WHEN CUSTOMER-RATING = AC-CODE(AC-INDEX)
MOVE AC-NAME(AC-INDEX) TO RATING-OUT
END-SEARCH
WRITE REPORT-RECORD FROM RATING-HEADING
AFTER ADVANCING 1
WRITE REPORT-RECORD FROM CUSTOMER-HEADING-1
AFTER ADVANCING PROPER-SPACING
WRITE REPORT-RECORD FROM CUSTOMER-HEADING-2
AFTER ADVANCING 1
ADD 8 TO LINE-COUNT
PERFORM 200-LINE-COUNT-CHECK
.
200-LINE-COUNT-CHECK.
DISPLAY LINE-COUNT
IF LINE-COUNT > 50
MOVE SPACES TO REPORT-RECORD
WRITE REPORT-RECORD
AFTER ADVANCING PAGE
PERFORM 145-PAGE-HEADING-ROUTINE
IF SUB < 6
WRITE REPORT-RECORD FROM CUSTOMER-HEADING-1
AFTER ADVANCING PROPER-SPACING
WRITE REPORT-RECORD FROM CUSTOMER-HEADING-2
AFTER ADVANCING 1
.
225-PUBLISH-FINAL-TOTALS.
MOVE WS-CITY-TOTAL TO TL-CITY-SOLD
MOVE CITY-OUT TO TL-CITY-NAME
WRITE REPORT-RECORD FROM TOTAL-CITY-SOLD-LINE
AFTER ADVANCING PROPER-SPACING
MOVE WS-STATE-TOTAL TO TL-STATE-SOLD
MOVE STATE-OUT TO TL-STATE-NAME
WRITE REPORT-RECORD FROM TOTAL-STATE-SOLD-LINE
AFTER ADVANCING PROPER-SPACING
MOVE WS-GRAND-TOTAL TO GRAND-TOTAL-SOLD
WRITE REPORT-RECORD FROM GRAND-TOTAL-SOLD-LINE
AFTER ADVANCING 3
.
250-CLOSE-ROUTINE.
CLOSE SORTED-FILE
CLOSE REPORT-FILE
STOP RUN
.