Capstone: Writing a Complete Batch Processing Program
COBOL Fundamentals
Chapter 10 · Capstone: Writing a Complete Batch Processing Program
Nine chapters built individual real pieces — divisions, PICTURE clauses, arithmetic, control flow, tables, string handling, file I/O, subprograms. Real COBOL work is almost always exactly this shape combined into one program: a nightly batch job that reads a transaction file, updates an in-memory customer table, and reports what happened. This capstone builds one, TXNBATCH, using every real piece from Chapters 1 through 9.
The Scenario
TXNBATCH reads a real sequential transaction file — one record per deposit or withdrawal, each carrying a customer ID, a transaction code, an amount, and a composite reference/branch string — validates each amount, applies it to an in-memory table of customer balances, and prints a real, running report line for every transaction processed.
File & Data Declarations
WS-CUSTOMER-TABLE is Chapter 6's own real OCCURS/INDEXED BY/ASCENDING KEY table, assumed loaded from a customer master file before TXNBATCH's own transaction loop begins — the real focus here is what happens once it's populated.
The Main Processing Loop
Chapter-Attribution Table
| Chapter | What TXNBATCH Draws From It |
|---|---|
| Ch. 2 — Four Divisions | The genuine ENVIRONMENT/DATA/PROCEDURE division structure the whole program is built on |
| Ch. 3 — Data Types & PICTURE | Every field's real PICTURE clause, and level numbers grouping TRANSACTION-RECORD and WS-CUSTOMER-ENTRY |
| Ch. 4 — MOVE, COMPUTE & Arithmetic | The real ADD/SUBTRACT/COMPUTE statements applying each transaction and tracking WS-GRAND-TOTAL |
| Ch. 5 — IF, EVALUATE & PERFORM | The real EVALUATE TXN-CODE dispatch, and PERFORM UNTIL driving the whole batch loop |
| Ch. 6 — OCCURS & Tables | WS-CUSTOMER-TABLE itself, its real INDEXED BY, and the real SEARCH ALL binary-search lookup |
| Ch. 7 — STRING, UNSTRING & Reference Modification | Splitting TXN-DETAIL with real UNSTRING, building WS-REPORT-LINE with real STRING, and WS-BRANCH-CODE(1:2) as a real substring |
| Ch. 8 — Sequential Files | The real SELECT/FD, OPEN, the priming-read PERFORM UNTIL pattern, WRITE-free reading, and CLOSE |
| Ch. 9 — Subprograms & CALL | The real CALL "BALCHECK", reused unchanged from Chapter 9, validating each amount before it's applied |
Hands-On Exercises
Using this chapter's own real TXNBATCH program, explain in your own words why SEARCH ALL, rather than a plain sequential SEARCH, is the genuinely correct choice for finding a customer by TXN-CUSTOMER-ID in WS-CUSTOMER-TABLE — and what real, silent risk this chapter's own Chapter 6 warning would apply here if the customer table were ever loaded out of order.
📄 View solutionUsing this chapter's own real TXNBATCH program, explain in your own words what genuinely happens to a real transaction record whose TXN-CUSTOMER-ID doesn't match any entry in WS-CUSTOMER-TABLE, and separately, what happens to one whose TXN-CODE is neither "D" nor "W".
📄 View solutionUsing this chapter's own real TXNBATCH program, explain in your own words why CALL "BALCHECK" USING TXN-AMOUNT WS-VALID-FLAG works correctly here even though BALCHECK's own LINKAGE SECTION, back in Chapter 9, was written using the names LS-BALANCE and LS-VALID-FLAG, and was originally called with WS-BALANCE rather than TXN-AMOUNT.
📄 View solutionChapter 10 Quick Reference — TXNBATCH's Own Real Pieces
- File I/O — real SELECT/FD, OPEN INPUT, priming-read PERFORM UNTIL, CLOSE
- Table lookup — WS-CUSTOMER-TABLE with real INDEXED BY and SEARCH ALL
- Subprogram validation — CALL "BALCHECK" reused unchanged from Chapter 9, matched purely by real position
- Control flow — real EVALUATE dispatch on TXN-CODE, nested IF for validation results
- String handling — real UNSTRING splitting TXN-DETAIL, STRING building the report line, reference modification for a real 2-character branch substring
- Arithmetic — real ADD/SUBTRACT applying each transaction, COMPUTE tracking the running grand total