Exercises: Legacy System Modernization Case Study
Exercise 44.1: Code Archaeology — Assess a Legacy Program
You are given a legacy COBOL program (CLM-INTAKE from this chapter) and asked to perform a code archaeology assessment. Create the following documentation artifacts:
- Program specification: A one-page summary of inputs, outputs, processing logic, and known issues
- Business rule catalog: List every business rule embedded in the code with line number references, plain-English descriptions, and confidence levels (High/Medium/Low)
- Data flow diagram: Show which files the program reads and writes and how data flows through the major sections
Which modernization tier (1-4) would you assign to this program? Justify your answer.
Exercise 44.2: Copybook Consolidation
The following two copybooks exist in a legacy system. Both define the same record — a provider record — but with slightly different field names, sizes, and structures:
Version A (used by 4 programs):
01 PROV-REC.
05 PROV-ID PIC X(10).
05 PROV-NAME PIC X(30).
05 PROV-STAT PIC X(01).
05 PROV-TYPE PIC 9(02).
05 PROV-REST PIC X(57).
Version B (used by 3 programs):
01 PROVIDER-RECORD.
05 PR-PROVIDER-NUM PIC X(10).
05 PR-PROV-NAME PIC X(25).
05 PR-STATUS PIC X(01).
05 PR-CATEGORY PIC X(02).
05 PR-TAX-ID PIC X(09).
05 PR-FILLER PIC X(53).
Design a single consolidated copybook that can replace both versions. Address the following challenges: - The name field is different sizes (30 vs 25) - The type field is numeric in A but alphanumeric in B - Version B has an additional field (TAX-ID) that A does not - Seven programs need to be modified
What is your migration strategy? How do you verify that the consolidation did not break anything?
Exercise 44.3: Refactor GO TO to Structured Code
Refactor the following legacy paragraph to eliminate the GO TO statements while preserving the exact same logic:
2000-PROC.
ADD 1 TO WS-CTR1.
MOVE CI-MEMB-ID TO MEMB-ID.
READ MEMB-FILE.
IF WS-FS5 NOT = '00'
MOVE 'MEMBER NOT FOUND' TO WS-ERR-MSG
PERFORM 8000-ERR
GO TO 2000-EXIT
END-IF.
IF CI-SVC-DATE < MEMB-EFF-DT
MOVE 'DATE BEFORE COVERAGE' TO WS-ERR-MSG
PERFORM 8000-ERR
GO TO 2000-EXIT
END-IF.
IF CI-AMOUNT NOT > 0
MOVE 'INVALID AMOUNT' TO WS-ERR-MSG
PERFORM 8000-ERR
GO TO 2000-EXIT
END-IF.
WRITE CLAIM-OUT-REC FROM CLAIM-IN-REC.
ADD 1 TO WS-CTR2.
2000-EXIT.
READ CLAIM-IN AT END MOVE 'Y' TO WS-EOF.
Write the refactored version using the cascading-IF pattern (with a WS-VALID flag) or nested IF-ELSE. Explain why you chose your approach.
Exercise 44.4: Write DB2 COBOL for Provider Lookup
Write a complete COBOL paragraph that replaces a VSAM random READ of the provider file with a DB2 SQL SELECT. The paragraph should:
- Accept a provider ID as input (already in CLM-PROVIDER-ID)
- Execute an SQL SELECT to retrieve provider name, type, status, and NPI number
- Handle SQLCODE 0 (found), +100 (not found), and negative (error)
- Move retrieved data into working storage variables
- Set appropriate validation flags on failure
Include the WORKING-STORAGE host variable definitions and any necessary EXEC SQL INCLUDE statements.
Exercise 44.5: Build a JSON Response
Using Enterprise COBOL's JSON GENERATE statement, write a program fragment that takes claim data from a DB2 query result and generates a JSON response with the following structure:
{
"status": "success",
"claim": {
"claimId": "CLM000012345",
"memberId": "MBR100000001",
"memberName": "John Smith",
"serviceDate": "2024-03-15",
"chargedAmount": "1250.00",
"paidAmount": "1000.00",
"claimStatus": "PD"
}
}
Define the COBOL data structure that maps to this JSON and write the JSON GENERATE statement. How would you handle the case where the claim is not found?
Exercise 44.6: Design Automated Test Cases
Design a comprehensive automated test suite for the refactored CLM-INTAKE program. Your test suite should include:
- At least 10 unit test cases covering valid claims, each validation rule failure, and edge cases
- Input data files for each test case
- Expected output descriptions (what should be in the accepted claims file? The error report? The audit file?)
- JCL to run the tests and verify results using IEBCOMPR or a similar utility
- A test summary report format
How would you handle the dependency on the provider and member lookup files in your tests?
Exercise 44.7: Modernization Planning Exercise
You have been given a legacy system with the following characteristics: - 120 COBOL programs - 200 copybooks (estimated 40% duplicates) - 3 developers who understand the system - No automated tests - Mix of VSAM and DB2 - 2 CICS transactions - Nightly batch window of 8 hours (currently using 7.5) - Management wants API access within 12 months
Create a modernization plan with: 1. Prioritized phases (what do you do first, second, third?) 2. Resource estimates for each phase 3. Risk assessment (what could go wrong?) 4. Success metrics (how do you measure progress?) 5. Go/no-go criteria for each phase transition
Exercise 44.8: Parallel Run Verification
Write a JCL job stream and COBOL comparison program that performs a parallel run verification. The job should:
- Run the legacy version of CLM-INTAKE against a test dataset
- Run the refactored version against the same test dataset
- Compare the output files byte-by-byte
- Report any differences with the record number and content of both the legacy and refactored output
- Set a return code of 0 if outputs match, 4 if differences were found
This is the key quality gate for any refactoring effort.