Capstone: fixed-width file processor
| The goal | |
| Design | |
| Build steps |
The goal
Build a batch program that reads a fixed-width employee file, computes the total and average salary per department, and writes a summary report with a heading, detail lines, and a grand total.
Design
Two files: an input FD with one 01 record, and an output report file. Working storage holds the running totals, the current department for control breaks, and the line counter. A level 88 marks end of file:
01 WS-EOF PIC X VALUE "N".
88 WS-END-OF-FILE VALUE "Y".
01 WS-TOTAL PIC 9(9)V99 VALUE 0.
Build steps
OPEN both files, then PERFORM UNTIL WS-END-OF-FILE: READ with AT END, add the salary to the department and grand totals, and detect a department change to print a control line. After the loop, WRITE the grand-total line and CLOSE both files. Test with a five-row fixture and a one-row file so the first-record and last-record paths both run. Compile, run, and diff the report against the expected output.
Next: Performance: tuning COBOL
Article author: Arthur Isaev