Write per-region totals at end of the daily feed
Cobol · COBOL · intermediate · modification
Adds the end-of-run summary step to REGSUM: after the feed is exhausted, the program sweeps the region table and writes one SUM-FILE record per accumulated region, exactly as the downstream reconciliation job expects.
The summary file is compared against the source system's own per-region totals; a region missing from SUM-FILE shows up as a reconciliation break the next morning.
Requirements
- After the daily transaction feed is fully read, write one summary record per region present in the region table.
- Each summary record carries the region code, the accumulated amount total, and the transaction count.
- Regions are accumulated in WS-REGION-TABLE during the read loop; the table's live size is WS-REGION-COUNT.
- The daily feed always contains at least one transaction; empty feeds abort upstream before REGSUM runs.
Files touched
- src/batch/REGSUM.cbl
--- src/batch/REGSUM.cbl
END-READ
END-PERFORM
+ PERFORM 300-WRITE-SUMMARY
CLOSE TXN-FILE
CLOSE SUM-FILE
ADD TXN-AMOUNT TO WS-REG-TOTAL (WS-IX)
ADD 1 TO WS-REG-COUNT (WS-IX).
+ 300-WRITE-SUMMARY.
+ PERFORM VARYING WS-IX FROM 1 BY 1
+ UNTIL WS-IX = WS-REGION-COUNT
+ MOVE WS-REG-CODE (WS-IX) TO SUM-REGION-CODE
+ MOVE WS-REG-TOTAL (WS-IX) TO SUM-TOTAL
+ MOVE WS-REG-COUNT (WS-IX) TO SUM-TXN-COUNT
+ WRITE SUM-REC
+ END-PERFORM.