Capstone: Modernizing a Legacy COBOL System

COBOL Intermediate/Advanced

Chapter 10 · Capstone: Modernizing a Legacy COBOL System

Fundamentals' own TXNBATCH shipped as a clean, working batch program. A few real years of maintenance later, it has aged into exactly the kind of system Chapter 9 described — real cryptic patches, a lingering ALTER, a customer file that's outgrown sequential access, and no real error-handling discipline at all. This capstone modernizes it, one real technique at a time, using everything Course 2 covered.

Step 1 — Fixing the Legacy Control Flow (Ch. 9)

A maintainer's real patch from years ago used ALTER to skip validation on a "trusted" batch run. It's replaced with a real, explicit EVALUATE flag check instead — the exact fix Chapter 9 documented:

EVALUATE WS-RUN-MODE WHEN "TRUSTED" CONTINUE WHEN OTHER PERFORM VALIDATE-TRANSACTION END-EVALUATE.

Step 2 — Sharing the Record Layout via a Copybook (Ch. 2)

CUSTOMER-RECORD, hand-typed separately in TXNBATCH and in this capstone's own new CICS program (Step 8), moves into one real shared copybook, CUSTREC, included with REPLACING wherever it's needed.

Step 3 — Converting to a Real Indexed Customer File (Ch. 1)

SELECT CUSTOMER-FILE ASSIGN TO CUSTMSTR ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC RECORD KEY IS CUST-ID FILE STATUS IS WS-FILE-STATUS.

TXNBATCH's own original sequential scan for a specific customer is replaced with a real direct-by-key READ, dropping the linear search entirely.

Step 4 — Centralizing File Error Handling (Ch. 6)

DECLARATIVES. CUSTOMER-FILE-ERROR SECTION. USE AFTER STANDARD ERROR PROCEDURE ON CUSTOMER-FILE. CUSTOMER-FILE-ERROR-PARA. EVALUATE WS-FILE-STATUS WHEN "23" DISPLAY "CUSTOMER NOT FOUND" WHEN OTHER MOVE 16 TO RETURN-CODE STOP RUN END-EVALUATE. END DECLARATIVES.

Every real READ against the newly-indexed file drops its own inline INVALID KEY clause — this one declared section now covers all of them.

Step 5 — Sorting Transactions Before Processing (Ch. 5)

SORT SORT-WORK-FILE ON ASCENDING KEY TXN-CUSTOMER-ID USING RAW-TRANSACTION-FILE GIVING SORTED-TRANSACTION-FILE.

Ordering transactions by customer first lets the modernized batch loop group each customer's own transactions together, rather than jumping around the indexed file at random.

Step 6 — Real-Time Balance Verification via Embedded SQL (Ch. 4)

EXEC SQL SELECT CUST_BALANCE INTO :WS-LIVE-BALANCE FROM CUSTOMER WHERE CUST_ID = :WS-CUST-ID END-EXEC. IF SQLCODE = 0 AND WS-LIVE-BALANCE NOT = CUST-BALANCE DISPLAY "WARNING: FILE/DATABASE BALANCE MISMATCH" END-IF.

A genuine cross-check against DB2's own live balance catches drift between the batch file and the real system of record before it compounds.

Step 7 — Running the Modernized Job (Ch. 3)

//TXNRUN2 JOB (ACCT123),'MODERNIZED BATCH',CLASS=A //STEP1 EXEC PGM=TXNBATCH2 //CUSTMSTR DD DSN=PROD.CUST.INDEXED,DISP=SHR //TXNFILE DD DSN=PROD.TXN.DAILY,DISP=SHR //STEP2 EXEC PGM=TXNRPT,COND=(4,LT,STEP1)

Step 8 — Wrapping With a Real CICS Front-End (Ch. 7, Ch. 9)

Rather than rewriting the whole system, a new, small CICS transaction — reusing the exact same CUSTREC copybook and the same real indexed CUSTOMER-FILE — is wrapped around it, letting a real teller look up a live balance without touching TXNBATCH2's own proven batch logic at all:

EXEC CICS READ FILE('CUSTMSTR') INTO(CUSTOMER-RECORD) RIDFLD(WS-CUST-ID) END-EXEC. EXEC CICS SEND MAP('CUSTMAP') MAPSET('CUSTSET') FROM(CUSTOMER-RECORD) END-EXEC. EXEC CICS RETURN TRANSID('CUST') COMMAREA(WS-COMM-AREA) END-EXEC.

Step 9 — One Shared, Reusable Validation Class (Ch. 8)

Both TXNBATCH2 (Step 1) and the new CICS transaction (Step 8) need the exact same balance validation. Rather than duplicating it, both genuinely INVOKE the same real class method:

INVOKE VALIDATOR-OBJ "IS-VALID-BALANCE" USING WS-BALANCE WS-RESULT.

Chapter-Attribution Table

ChapterWhat This Modernization Step Draws From It
Ch. 1 — Indexed & Relative FilesConverting CUSTOMER-FILE to real ORGANIZATION IS INDEXED with direct-by-key access
Ch. 2 — CopybooksOne shared CUSTREC layout, included in both the batch program and the new CICS transaction
Ch. 3 — JCLThe real JOB/EXEC/DD job stream running the modernized batch step and its downstream report
Ch. 4 — Embedded SQLA real DB2 cross-check catching file/database balance drift
Ch. 5 — SortOrdering transactions by customer before the main processing loop
Ch. 6 — DECLARATIVESOne centralized error-handling section covering every I/O against the newly-indexed file
Ch. 7 — CICSThe new real-time customer-lookup transaction wrapped around the existing system
Ch. 8 — OO COBOLOne shared, INVOKE-able validation class used by both the batch job and the CICS transaction
Ch. 9 — Legacy MaintenanceRecognizing and replacing the real ALTER-based patch, and choosing to wrap rather than rewrite

Hands-On Exercises

Exercise 1

Using this capstone's own real Step 3 and Step 4, explain in your own words why converting CUSTOMER-FILE to an indexed organization made the real DECLARATIVES-based error handling in Step 4 genuinely more valuable than it would have been for the original sequential file.

📄 View solution
Exercise 2

Using this capstone's own real Step 9, explain in your own words why a shared, INVOKE-able validation class is genuinely a better fit here than either duplicating the validation logic in both programs, or reusing Fundamentals' own plain BALCHECK subprogram unchanged via two separate CALL statements.

📄 View solution
Exercise 3

Using this capstone's own real Step 8, explain in your own words why wrapping a new CICS transaction around the existing, modernized batch system's own indexed file and copybook is a genuine, direct application of Chapter 9's own "wrap rather than rewrite" recommendation, rather than simply a convenient shortcut.

📄 View solution

Chapter 10 Quick Reference — This Capstone's Own Real Modernization Steps

  • Control flow — a real ALTER-based patch replaced with EVALUATE
  • Data — a shared copybook; a sequential file converted to indexed with direct-by-key access
  • Error handling — centralized via DECLARATIVES, covering the whole indexed file at once
  • Processing order — SORT grouping transactions by customer before the main loop
  • Data integrity — a real embedded SQL cross-check against DB2's own live balance
  • Execution — a real JCL job stream tying the modernized batch step to a downstream report
  • Modernization strategy — a new CICS front-end wrapped around proven logic, not a rewrite; one shared OO validation class reused by both paths
Course Complete COBOL Intermediate/Advanced is now complete, 10/10 chapters — and with it, the full two-course COBOL project (Fundamentals + Intermediate/Advanced) is complete at 20 chapters total.