Part 5
Practice
Worked programs that solve a real task end to end: reports, batch jobs, validation, reconciliation.
Part 5 is whole programs, each one a task that batch shops actually run, worked end to end. They use the statements from the earlier parts together, which makes them the best test of whether those lessons stuck, and the closest thing on this site to the code you will meet on the job.
Read the bank-statement batch job first. In about 200 lines it reads sorted transactions, sends bad records to a reject file, breaks on account change and writes a statement with totals; the twelve-record input carries two deliberate faults, and a Python companion computes the statement the program should produce. Reconciling two files matches two sorted files and puts every reference in one of four boxes (matched, amount differs, bank only, book only) with control totals that must balance. Input validation goes further than the bank job, which stops at the first fault in a record: it checks every field with CLASS, INSPECT, TEST-NUMVAL and TEST-DATE-YYYYMMDD and logs each error with a code. STRING and UNSTRING takes apart a comma-separated export that was never designed for COBOL and builds a label from the pieces.
When a statement in these programs is new to you, the earlier parts teach it on its own: Files and Records for the file handling, Data and Tables for the layouts. New lessons rotate across all five parts, so this one keeps growing as the queue (SORT and MERGE next) gives it new material.
5.1
A COBOL bank-statement batch job: read, validate, total, report
A complete GnuCOBOL batch program that reads sorted transactions, rejects bad records to a file, breaks on account change, and writes a statement with totals.
6 min
5.2
Reconciling two files in COBOL: matched, left-only, right-only
A complete GnuCOBOL match of two sorted files that reports every reference as matched, amount differs, bank only or book only, with control totals that must balance.
6 min
5.3
COBOL input validation: class tests, INSPECT and TEST-NUMVAL
A GnuCOBOL edit program that checks every field of a fixed-width feed with CLASS, INSPECT, TEST-NUMVAL and TEST-DATE-YYYYMMDD, and logs every error with a code.
17 min
5.4
COBOL STRING and UNSTRING: splitting a CSV line into fields
A GnuCOBOL program that splits a comma-separated export with UNSTRING, checks each field with COUNT IN and TALLYING IN, and builds a label with STRING.
10 min