-
Notifications
You must be signed in to change notification settings - Fork 59
/
SAM1.cbl
576 lines (535 loc) · 22.2 KB
/
SAM1.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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
****************************************************************
* LICENSED MATERIALS - PROPERTY OF IBM
* "RESTRICTED MATERIALS OF IBM"
* (C) COPYRIGHT IBM CORPORATION 2022. ALL RIGHTS RESERVED
* US GOVERNMENT USERS RESTRICTED RIGHTS - USE, DUPLICATION,
* OR DISCLOSURE RESTRICTED BY GSA ADP SCHEDULE
* CONTRACT WITH IBM CORPORATION
****************************************************************
* PROGRAM: SAM1
*
* AUTHOR : Doug Stout
*
* READS A SEQUENTIAL TRANSACTION FILE AND MAKES UPDATES
* TO A SORTED SEQUENTIAL CUSTOMER FILE
*
* CAN BE MADE TO ABEND WITH BAD INPUT DATA FOR FAULT ANALYSIS LAB
*****************************************************************
*
* Transaction file record descriptions:
* 0 1 1 2 2 3 3 4 4 5 5 6 6
*....5....0....5....0....5....0....5....0....5....0....5....0....5
*
* * <== an asterisk in first column is a comment
*UPDATE ---key---- -command-- field-name ss -----------value------
* can be: valid formats:
* REPLACE character_string______
* ADD +99999999
* SUBTRACT +99999999.99
* (The "ss" field is a subscript, used for the MONTH field only)
* DELETE ___key____ <== Delete Record
* ADD ___key____ <== Add a new blank record
*
*****************************************************************
* Change Log
R2 * V02 * Add logic to show number of customers on report
R2 * * Add logic to process Crunch transactions
***************************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. SAM1.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT CUSTOMER-FILE ASSIGN TO CUSTFILE
ACCESS IS SEQUENTIAL
FILE STATUS IS WS-CUSTFILE-STATUS.
SELECT CUSTOMER-FILE-OUT ASSIGN TO CUSTOUT
ACCESS IS SEQUENTIAL
FILE STATUS IS WS-CUSTOUT-STATUS.
SELECT TRANSACTION-FILE ASSIGN TO TRANFILE
FILE STATUS IS WS-TRANFILE-STATUS.
SELECT REPORT-FILE ASSIGN TO CUSTRPT
FILE STATUS IS WS-REPORT-STATUS.
*****************************************************************
DATA DIVISION.
FILE SECTION.
FD CUSTOMER-FILE
RECORDING MODE IS V
RECORD IS VARYING FROM 20 TO 596 CHARACTERS.
COPY CUSTCOPY REPLACING ==:TAG:== BY ==CUST==.
FD CUSTOMER-FILE-OUT
RECORDING MODE IS V
BLOCK CONTAINS 0 RECORDS
RECORD IS VARYING FROM 20 TO 596 CHARACTERS.
COPY CUSTCOPY REPLACING ==:TAG:== BY ==CSTOUT==.
FD TRANSACTION-FILE
RECORDING MODE IS F.
COPY TRANREC.
FD REPORT-FILE
RECORDING MODE IS F.
01 REPORT-RECORD PIC X(132).
*****************************************************************
WORKING-STORAGE SECTION.
*****************************************************************
*
01 SYSTEM-DATE-AND-TIME.
05 CURRENT-DATE.
10 CURRENT-YEAR PIC 9(2).
10 CURRENT-MONTH PIC 9(2).
10 CURRENT-DAY PIC 9(2).
05 CURRENT-TIME.
10 CURRENT-HOUR PIC 9(2).
10 CURRENT-MINUTE PIC 9(2).
10 CURRENT-SECOND PIC 9(2).
10 CURRENT-HNDSEC PIC 9(2).
*
* some comments
* some more comments
*
01 WS-FIELDS.
05 WS-CUSTFILE-STATUS PIC X(2) VALUE SPACES.
05 WS-CUSTOUT-STATUS PIC X(2) VALUE SPACES.
05 WS-TRANFILE-STATUS PIC X(2) VALUE SPACES.
05 WS-REPORT-STATUS PIC X(2) VALUE SPACES.
05 WS-TRAN-EOF PIC X VALUE SPACES.
05 WS-TRAN-OK PIC X VALUE 'N'.
05 WS-CUST-FILE-OK PIC X VALUE 'N'.
05 WS-CUST-FILE-EOF PIC X VALUE 'N'.
05 WS-TRAN-MSG PIC X(50) VALUE SPACES.
05 WS-PREV-TRAN-KEY PIC X(13) VALUE LOW-VALUES.
05 INCR-CUST-ID PIC 9(5) VALUE 0.
05 START-CUST-ID PIC 9(5) VALUE 0.
05 MAX-CUST-ID PIC 9(5) VALUE 0.
05 SAM2 PIC X(8) VALUE 'SAM2'.
*
* some additional comments
* some more additional comments
*
01 WORK-VARIABLES.
05 I PIC S9(9) COMP-3 VALUE +0.
05 WORK-NUM PIC S9(8) COMP.
*
01 REPORT-TOTALS.
05 NUM-TRAN-RECS PIC S9(9) COMP-3 VALUE +0.
05 NUM-TRAN-ERRORS PIC S9(9) COMP-3 VALUE +0.
05 NUM-ADD-REQUESTS PIC S9(9) COMP-3 VALUE +0.
05 NUM-ADD-PROCESSED PIC S9(9) COMP-3 VALUE +0.
05 NUM-UPDATE-REQUESTS PIC S9(9) COMP-3 VALUE +0.
05 NUM-UPDATE-PROCESSED PIC S9(9) COMP-3 VALUE +0.
05 NUM-DELETE-REQUESTS PIC S9(9) COMP-3 VALUE +0.
05 NUM-DELETE-PROCESSED PIC S9(9) COMP-3 VALUE +0.
05 NUM-CRUNCH-REQUESTS PIC S9(9) COMP-3 VALUE +0.
05 NUM-CRUNCH-PROCESSED PIC S9(9) COMP-3 VALUE +0.
05 NUM-RPTALL-REQUESTS PIC S9(9) COMP-3 VALUE +0.
05 NUM-RPTALL-PROCESSED PIC S9(9) COMP-3 VALUE +0.
05 NUM-GEN-REQUESTS PIC S9(9) COMP-3 VALUE +0.
05 NUM-GEN-PROCESSED PIC S9(9) COMP-3 VALUE +0.
R2 05 NUM-PRE-CUSTOMERS PIC S9(9) COMP-3 VALUE +0.
R2 05 NUM-POST-CUSTOMERS PIC S9(9) COMP-3 VALUE +0.
COPY CUSTCOPY REPLACING ==:TAG:== BY ==WS-CUST==.
R2 COPY SAM2PARM.
* *******************
* report lines
* *******************
01 ERR-MSG-BAD-TRAN.
05 FILLER PIC X(31)
VALUE 'Error Processing Transaction. '.
05 ERR-MSG-DATA1 PIC X(35) VALUE SPACES.
05 ERR-MSG-DATA2 PIC X(66) VALUE SPACES.
01 ERR-MSG-BAD-TRAN-2.
05 FILLER PIC X(21) VALUE SPACES.
05 ERR-MSG-DATA3 PIC X(80).
05 FILLER PIC X(31) VALUE SPACES.
01 MSG-TRAN-SCALE-1.
05 FILLER PIC X(21) VALUE SPACES.
05 FILLER PIC X(35)
VALUE ' 1 1 2 2 3 3'.
05 FILLER PIC X(35)
VALUE ' 4 4 5 5 6 6 7'.
05 FILLER PIC X(41) VALUE SPACES.
01 MSG-TRAN-SCALE-2.
05 FILLER PIC X(21) VALUE ' Transaction Record: '
.
05 FILLER PIC X(35)
VALUE '....5....0....5....0....5....0....5'.
05 FILLER PIC X(35)
VALUE '....0....5....0....5....0....5....0'.
05 FILLER PIC X(41) VALUE SPACES.
01 RPT-HEADER1.
05 FILLER PIC X(40)
VALUE 'CUSTOMER FILE UPDATE REPORT DATE: '.
05 RPT-MM PIC 99.
05 FILLER PIC X VALUE '/'.
05 RPT-DD PIC 99.
05 FILLER PIC X VALUE '/'.
05 RPT-YY PIC 99.
05 FILLER PIC X(20)
VALUE ' (mm/dd/yy) TIME: '.
05 RPT-HH PIC 99.
05 FILLER PIC X VALUE ':'.
05 RPT-MIN PIC 99.
05 FILLER PIC X VALUE ':'.
05 RPT-SS PIC 99.
05 FILLER PIC X(55) VALUE SPACES.
01 RPT-TRAN-DETAIL1.
05 RPT-TRAN-MSG1 PIC X(31)
VALUE ' Transaction processed: '.
05 RPT-TRAN-RECORD PIC X(80) VALUE SPACES.
05 FILLER PIC X(21) VALUE SPACES.
R2 01 RPT-CRUNCH-RECORD.
R2 05 RPT-CRUNCH-CUST PIC X(14) VALUE SPACES.
R2 05 FILLER PIC X(06) VALUE 'TOTAL '.
R2 05 RPT-CRUNCH-TOTAL PIC ZZZ,ZZZ,ZZZ,ZZ9.
R2 05 FILLER PIC X(05) VALUE ' AVG '.
R2 05 RPT-CRUNCH-AVG PIC ZZZ,ZZZ,ZZZ,ZZ9.
R2 05 FILLER PIC X(25) VALUE SPACES.
01 RPT-STATS-HDR1.
05 FILLER PIC X(26) VALUE
'Transaction Totals: '.
05 FILLER PIC X(107) VALUE SPACES.
01 RPT-STATS-HDR2.
05 FILLER PIC X(26) VALUE
'Transaction Number of'.
05 FILLER PIC X(28) VALUE
' Number Number'.
05 FILLER PIC X(79) VALUE SPACES.
01 RPT-STATS-HDR3.
05 FILLER PIC X(26) VALUE
'Type Transactions'.
05 FILLER PIC X(28) VALUE
' Processed In Error'.
05 FILLER PIC X(79) VALUE SPACES.
01 RPT-STATS-HDR4.
05 FILLER PIC X(26) VALUE
'----------- ------------'.
05 FILLER PIC X(28) VALUE
' ----------- -----------'.
05 FILLER PIC X(79) VALUE SPACES.
01 RPT-STATS-DETAIL.
05 RPT-TRAN PIC X(10).
05 FILLER PIC X(4) VALUE SPACES.
05 RPT-NUM-TRANS PIC ZZZ,ZZZ,ZZ9.
05 FILLER PIC X(3) VALUE SPACES.
05 RPT-NUM-TRAN-PROC PIC ZZZ,ZZZ,ZZ9.
05 FILLER PIC X(3) VALUE SPACES.
05 RPT-NUM-TRAN-ERR PIC ZZZ,ZZZ,ZZ9.
05 FILLER PIC X(80) VALUE SPACES.
R2 01 RPT-STATS-HDR5.
R2 05 FILLER PIC X(26) VALUE
'Customer Acct Totals: '.
R2 05 FILLER PIC X(107) VALUE SPACES.
R2 01 RPT-STATS-CUST-DETAIL.
R2 05 CUST-CNT-NAME PIC X(30).
R2 05 FILLER PIC X(5) VALUE SPACES.
R2 05 RPT-NUM-CUST PIC ZZZ,ZZZ,ZZ9.
R2 05 FILLER PIC X(87) VALUE SPACES.
*****************************************************************
PROCEDURE DIVISION.
*****************************************************************
000-MAIN.
ACCEPT CURRENT-DATE FROM DATE.
ACCEPT CURRENT-TIME FROM TIME.
DISPLAY 'SAM1 STARTED DATE = '
CURRENT-MONTH
'/'
CURRENT-DAY
'/'
CURRENT-YEAR
' (mm/dd/yy)'.
DISPLAY ' TIME = '
CURRENT-HOUR
':'
CURRENT-MINUTE
':'
CURRENT-SECOND.
* TODO this is a task tag
PERFORM 700-OPEN-FILES.
PERFORM 800-INIT-REPORT.
PERFORM 730-READ-CUSTOMER-FILE.
PERFORM 100-PROCESS-TRANSACTIONS
UNTIL WS-TRAN-EOF = 'Y'.
PERFORM 850-REPORT-TRAN-STATS.
PERFORM 790-CLOSE-FILES.
ACCEPT CURRENT-DATE FROM DATE.
ACCEPT CURRENT-TIME FROM TIME.
DISPLAY 'SAM1 STOPPED DATE = '
CURRENT-MONTH
'/'
CURRENT-DAY
'/'
CURRENT-YEAR
' (mm/dd/yy)'.
DISPLAY ' TIME = '
CURRENT-HOUR
':'
CURRENT-MINUTE
':'
CURRENT-SECOND.
GOBACK.
100-PROCESS-TRANSACTIONS.
PERFORM 710-READ-TRAN-FILE.
IF WS-TRAN-EOF NOT = 'Y'
COMPUTE NUM-TRAN-RECS = NUM-TRAN-RECS + 1
MOVE 'Y' TO WS-TRAN-OK
IF TRAN-KEY < WS-PREV-TRAN-KEY AND TRAN-COMMENT NOT = '*'
MOVE 'TRANSACTION OUT OF SEQUENCE' TO ERR-MSG-DATA1
MOVE SPACES TO ERR-MSG-DATA2
PERFORM 299-REPORT-BAD-TRAN
ELSE
EVALUATE TRAN-CODE
WHEN 'UPDATE'
R2 WHEN 'CRUNCH'
PERFORM 200-PROCESS-UPDATE-TRAN
WHEN 'ADD '
PERFORM 210-PROCESS-ADD-TRAN
WHEN 'DELETE'
PERFORM 220-PROCESS-DELETE-TRAN
WHEN OTHER
IF TRAN-COMMENT NOT = '*'
MOVE 'INVALID TRAN CODE:' TO ERR-MSG-DATA1
MOVE TRAN-CODE TO ERR-MSG-DATA2
PERFORM 299-REPORT-BAD-TRAN
END-IF
END-EVALUATE
END-IF
MOVE TRAN-KEY TO WS-PREV-TRAN-KEY
IF WS-TRAN-OK = 'Y'
PERFORM 830-REPORT-TRAN-PROCESSED
END-IF
END-IF.
200-PROCESS-UPDATE-TRAN.
R2 IF TRAN-CODE = 'UPDATE'
ADD +1 TO NUM-UPDATE-REQUESTS
R2 ELSE
R2 ADD +1 TO NUM-CRUNCH-REQUESTS
R2 END-IF.
PERFORM 720-POSITION-CUST-FILE.
IF CUST-KEY NOT = TRAN-KEY OR WS-CUST-FILE-EOF = 'Y'
MOVE 'NO MATCHING KEY: ' TO ERR-MSG-DATA1
MOVE TRAN-KEY TO ERR-MSG-DATA2
PERFORM 299-REPORT-BAD-TRAN
ELSE
*
* Subroutine SAM2 will apply an update to a customer record
*
CALL SAM2 USING CUST-REC, TRANSACTION-RECORD,
WS-TRAN-OK, WS-TRAN-MSG,
R2 SAM2-PARMS
IF WS-TRAN-OK NOT = 'Y'
MOVE WS-TRAN-MSG TO ERR-MSG-DATA1
MOVE SPACES TO ERR-MSG-DATA2
PERFORM 299-REPORT-BAD-TRAN
ELSE
R2 IF TRAN-CODE = 'UPDATE'
ADD +1 TO NUM-UPDATE-PROCESSED
R2 ELSE
R2 ADD +1 TO NUM-CRUNCH-PROCESSED
R2 END-IF
END-IF
END-IF.
210-PROCESS-ADD-TRAN.
ADD +1 TO NUM-ADD-REQUESTS.
PERFORM 720-POSITION-CUST-FILE.
IF CUST-KEY = TRAN-KEY
MOVE 'DUPLICATE KEY: ' TO ERR-MSG-DATA1
MOVE TRAN-KEY TO ERR-MSG-DATA2
PERFORM 299-REPORT-BAD-TRAN
ELSE
MOVE SPACES TO WS-CUST-REC
MOVE TRAN-KEY TO WS-CUST-KEY
MOVE +0 TO WS-CUST-ACCT-BALANCE
MOVE +0 TO WS-CUST-ORDERS-YTD
PERFORM TEST AFTER VARYING I FROM 1 BY 1
UNTIL I > 12
MOVE +0 TO WS-CUST-MONTH(I)
END-PERFORM
PERFORM 740-WRITE-CUSTOUT-FILE
ADD +1 TO NUM-ADD-PROCESSED
END-IF.
220-PROCESS-DELETE-TRAN.
ADD +1 TO NUM-DELETE-REQUESTS.
PERFORM 720-POSITION-CUST-FILE.
IF CUST-KEY NOT = TRAN-KEY OR WS-CUST-FILE-EOF = 'Y'
MOVE 'NO MATCHING KEY: ' TO ERR-MSG-DATA1
MOVE TRAN-KEY TO ERR-MSG-DATA2
PERFORM 299-REPORT-BAD-TRAN
ELSE
ADD +1 TO NUM-DELETE-PROCESSED
PERFORM 730-READ-CUSTOMER-FILE
END-IF.
299-REPORT-BAD-TRAN.
ADD +1 TO NUM-TRAN-ERRORS.
MOVE 'N' TO WS-TRAN-OK.
WRITE REPORT-RECORD FROM ERR-MSG-BAD-TRAN AFTER 2.
WRITE REPORT-RECORD FROM MSG-TRAN-SCALE-1.
WRITE REPORT-RECORD FROM MSG-TRAN-SCALE-2.
MOVE TRANSACTION-RECORD TO ERR-MSG-DATA3.
WRITE REPORT-RECORD FROM ERR-MSG-BAD-TRAN-2.
700-OPEN-FILES.
OPEN INPUT TRANSACTION-FILE
CUSTOMER-FILE
OUTPUT CUSTOMER-FILE-OUT
REPORT-FILE.
IF WS-CUSTFILE-STATUS NOT = '00'
DISPLAY 'ERROR OPENING CUSTOMER INPUT FILE. RC:'
WS-CUSTFILE-STATUS
DISPLAY 'Terminating Program due to File Error'
MOVE 16 TO RETURN-CODE
MOVE 'Y' TO WS-TRAN-EOF
END-IF.
IF WS-CUSTOUT-STATUS NOT = '00'
DISPLAY 'ERROR OPENING CUSTOMER OUTPUT FILE. RC:'
WS-CUSTOUT-STATUS
DISPLAY 'Terminating Program due to File Error'
MOVE 16 TO RETURN-CODE
MOVE 'Y' TO WS-TRAN-EOF
END-IF.
IF WS-TRANFILE-STATUS NOT = '00'
DISPLAY 'ERROR OPENING TRAN FILE. RC:' WS-TRANFILE-STATUS
DISPLAY 'Terminating Program due to File Error'
MOVE 16 TO RETURN-CODE
MOVE 'Y' TO WS-TRAN-EOF
END-IF.
IF WS-REPORT-STATUS NOT = '00'
DISPLAY 'ERROR OPENING REPT FILE. RC:' WS-REPORT-STATUS
DISPLAY 'Terminating Program due to File Error'
MOVE 16 TO RETURN-CODE
MOVE 'Y' TO WS-TRAN-EOF
END-IF.
710-READ-TRAN-FILE.
READ TRANSACTION-FILE
AT END
MOVE 'Y' TO WS-TRAN-EOF.
EVALUATE WS-TRANFILE-STATUS
WHEN '00'
CONTINUE
WHEN '10'
MOVE 'Y' TO WS-TRAN-EOF
WHEN OTHER
MOVE 'Error on tran file read. Code:'
TO ERR-MSG-DATA1
MOVE WS-CUSTFILE-STATUS TO ERR-MSG-DATA2
PERFORM 299-REPORT-BAD-TRAN
MOVE 'Y' TO WS-TRAN-EOF
END-EVALUATE.
IF WS-TRAN-EOF = 'Y'
PERFORM 721-COPY-RECORDS
UNTIL WS-CUST-FILE-EOF = 'Y'
END-IF.
720-POSITION-CUST-FILE.
IF CUST-KEY < TRAN-KEY
IF WS-CUST-FILE-EOF NOT = 'Y'
PERFORM 721-COPY-RECORDS
UNTIL CUST-KEY >= TRAN-KEY
OR WS-CUST-FILE-EOF = 'Y'
END-IF
END-IF.
721-COPY-RECORDS.
MOVE CUST-REC TO WS-CUST-REC.
PERFORM 740-WRITE-CUSTOUT-FILE.
PERFORM 730-READ-CUSTOMER-FILE.
730-READ-CUSTOMER-FILE.
READ CUSTOMER-FILE
AT END
MOVE 'Y' TO WS-CUST-FILE-EOF.
EVALUATE WS-CUSTFILE-STATUS
WHEN '00'
WHEN '04'
R2 ADD +1 TO NUM-PRE-CUSTOMERS
WHEN '10'
MOVE 'Y' TO WS-CUST-FILE-EOF
WHEN OTHER
MOVE 'Customer input File I/O Error on Read. RC: '
TO ERR-MSG-DATA1
MOVE WS-CUSTFILE-STATUS TO ERR-MSG-DATA2
PERFORM 299-REPORT-BAD-TRAN
END-EVALUATE.
740-WRITE-CUSTOUT-FILE.
IF WS-CUST-REC-TYPE = 'A'
WRITE CSTOUT-REC FROM WS-CUST-REC
ELSE
MOVE WS-CUST-REC TO WS-CUST-CONTACT-REC
WRITE CSTOUT-CONTACT-REC FROM WS-CUST-CONTACT-REC
END-IF.
EVALUATE WS-CUSTOUT-STATUS
WHEN '00'
R2 ADD +1 TO NUM-POST-CUSTOMERS
WHEN OTHER
MOVE 'CUSTOMER OUTPUT FILE I/O ERROR ON WRITE. RC: '
TO ERR-MSG-DATA1
MOVE WS-CUSTFILE-STATUS TO ERR-MSG-DATA2
PERFORM 299-REPORT-BAD-TRAN
END-EVALUATE.
790-CLOSE-FILES.
CLOSE TRANSACTION-FILE.
CLOSE REPORT-FILE.
CLOSE CUSTOMER-FILE.
800-INIT-REPORT.
MOVE CURRENT-YEAR TO RPT-YY.
MOVE CURRENT-MONTH TO RPT-MM.
MOVE CURRENT-DAY TO RPT-DD.
MOVE CURRENT-HOUR TO RPT-HH.
MOVE CURRENT-MINUTE TO RPT-MIN.
MOVE CURRENT-SECOND TO RPT-SS.
WRITE REPORT-RECORD FROM RPT-HEADER1 AFTER PAGE.
830-REPORT-TRAN-PROCESSED.
R2 INITIALIZE RPT-TRAN-RECORD.
R2 IF TRAN-CODE = 'CRUNCH'
R2 MOVE TRANSACTION-RECORD(1:14) TO RPT-CRUNCH-CUST
R2 MOVE CRUNCH-TOTAL TO RPT-CRUNCH-TOTAL
R2 MOVE CRUNCH-AVG TO RPT-CRUNCH-AVG
R2 MOVE RPT-CRUNCH-RECORD TO RPT-TRAN-RECORD
R2 ELSE
MOVE TRANSACTION-RECORD TO RPT-TRAN-RECORD
IF TRAN-COMMENT = '*'
MOVE SPACES TO RPT-TRAN-MSG1
ELSE
MOVE ' Transaction processed: ' TO RPT-TRAN-MSG1
END-IF
END-IF.
WRITE REPORT-RECORD FROM RPT-TRAN-DETAIL1.
850-REPORT-TRAN-STATS.
WRITE REPORT-RECORD FROM RPT-STATS-HDR1 AFTER 2.
WRITE REPORT-RECORD FROM RPT-STATS-HDR2 AFTER 2.
WRITE REPORT-RECORD FROM RPT-STATS-HDR3 AFTER 1.
WRITE REPORT-RECORD FROM RPT-STATS-HDR4 AFTER 1.
MOVE 'ADD ' TO RPT-TRAN.
MOVE NUM-ADD-REQUESTS TO RPT-NUM-TRANS.
MOVE NUM-ADD-PROCESSED TO RPT-NUM-TRAN-PROC.
COMPUTE RPT-NUM-TRAN-ERR =
NUM-ADD-REQUESTS - NUM-ADD-PROCESSED.
WRITE REPORT-RECORD FROM RPT-STATS-DETAIL.
MOVE 'DELETE ' TO RPT-TRAN.
MOVE NUM-DELETE-REQUESTS TO RPT-NUM-TRANS.
MOVE NUM-DELETE-PROCESSED TO RPT-NUM-TRAN-PROC.
COMPUTE RPT-NUM-TRAN-ERR =
NUM-DELETE-REQUESTS - NUM-DELETE-PROCESSED.
WRITE REPORT-RECORD FROM RPT-STATS-DETAIL.
MOVE 'UPDATE ' TO RPT-TRAN.
MOVE NUM-UPDATE-REQUESTS TO RPT-NUM-TRANS.
MOVE NUM-UPDATE-PROCESSED TO RPT-NUM-TRAN-PROC.
COMPUTE RPT-NUM-TRAN-ERR =
NUM-UPDATE-REQUESTS - NUM-UPDATE-PROCESSED.
WRITE REPORT-RECORD FROM RPT-STATS-DETAIL.
R2 MOVE 'CRUNCH ' TO RPT-TRAN.
R2 MOVE NUM-CRUNCH-REQUESTS TO RPT-NUM-TRANS.
R2 MOVE NUM-CRUNCH-PROCESSED TO RPT-NUM-TRAN-PROC.
R2 COMPUTE RPT-NUM-TRAN-ERR =
R2 NUM-CRUNCH-REQUESTS - NUM-CRUNCH-PROCESSED .
R2 WRITE REPORT-RECORD FROM RPT-STATS-DETAIL.
R2 WRITE REPORT-RECORD FROM RPT-STATS-HDR5 AFTER 2.
R2 MOVE 'Pre Report Customer Count' TO CUST-CNT-NAME.
R2 MOVE NUM-PRE-CUSTOMERS TO RPT-NUM-CUST.
R2 WRITE REPORT-RECORD FROM RPT-STATS-CUST-DETAIL.
R2 MOVE 'Customers Added' TO CUST-CNT-NAME.
R2 MOVE NUM-ADD-PROCESSED TO RPT-NUM-CUST.
R2 WRITE REPORT-RECORD FROM RPT-STATS-CUST-DETAIL.
R2 MOVE 'Customers Deleted' TO CUST-CNT-NAME.
R2 MOVE NUM-DELETE-PROCESSED TO RPT-NUM-CUST.
R2 WRITE REPORT-RECORD FROM RPT-STATS-CUST-DETAIL.
R2 COMPUTE NUM-POST-CUSTOMERS = NUM-PRE-CUSTOMERS +
R2 NUM-ADD-PROCESSED -
R2 NUM-DELETE-PROCESSED.
R2 MOVE 'Post Report Customer Count' TO CUST-CNT-NAME.
R2 MOVE NUM-POST-CUSTOMERS TO RPT-NUM-CUST.
R2 WRITE REPORT-RECORD FROM RPT-STATS-CUST-DETAIL.