Exercises — Chapter 41: Legacy Code Archaeology
Exercise 41.1: Call Graph Construction
Objective: Build a complete call graph for a COBOL program.
Tasks: 1. Using the MYSTERY.cbl program from this chapter's code directory, identify every paragraph in the PROCEDURE DIVISION. 2. For each paragraph, list every PERFORM statement and its target. 3. Draw a hierarchical call graph showing the complete flow. 4. Identify any paragraphs that are never called (dead code). 5. Identify any circular references (paragraph A PERFORMs B which PERFORMs A).
Exercise 41.2: Data Flow Tracing
Objective: Trace data from input to output through a COBOL program.
Tasks: 1. Choose a primary output field in the MYSTERY.cbl program. 2. Trace backward: find every statement that assigns a value to this field. 3. For each assignment, trace the source fields backward until you reach input fields. 4. Draw a data flow diagram showing the complete chain. 5. Identify any intermediate transformations (calculations, conditionals).
Exercise 41.3: Business Rule Extraction
Objective: Extract business rules from undocumented code.
Tasks: 1. Find every EVALUATE statement in MYSTERY.cbl and document each WHEN clause as a business rule. 2. Find every IF block that contains financial calculations and extract the rules. 3. Document each rule using the standard template from section 41.5. 4. Organize rules by category (validation, calculation, routing, error handling). 5. Identify any rules that appear to contradict each other.
Exercise 41.4: Impact Analysis
Objective: Perform a complete impact analysis for a proposed change.
Scenario: You are asked to change the way a discount percentage is calculated in a program. The field WS-DISCOUNT-PCT is currently set in paragraph 3200 based on customer type.
Tasks: 1. Find every reference to WS-DISCOUNT-PCT in the program. 2. Map downstream effects: what calculations use this field? 3. Identify output fields affected by the change. 4. Check if WS-DISCOUNT-PCT appears in any copybooks used by other programs. 5. Write an impact analysis report listing: direct changes, downstream effects, testing requirements.
Exercise 41.5: Documentation Recovery
Objective: Create documentation for an undocumented program.
Tasks: 1. Using your analysis from Exercises 41.1-41.4, create the following documents for MYSTERY.cbl: - Data dictionary (at least 15 key fields) - Program inventory entry - Business rule catalog - One-page program summary 2. Format the documentation professionally — as if it would be read by a new developer joining the team.
Exercise 41.6: Cross-Reference Report
Objective: Build an automated cross-reference for a COBOL program.
Tasks: 1. Write a script (bash, Python, or any language) that reads a COBOL source file and produces: - A list of all paragraph names with line numbers - For each paragraph, the number of times it is PERFORMed - A list of all variables with their PIC clauses - For each variable, the number of references 2. Run your script on MYSTERY.cbl and on any other COBOL program from earlier chapters. 3. Identify dead code (unreferenced paragraphs or variables).
Exercise 41.7: Anti-Pattern Identification
Objective: Identify and document legacy anti-patterns.
Tasks: 1. Search MYSTERY.cbl for the following anti-patterns: - GO TO statements (how many? where do they go?) - PERFORM THRU ranges (what paragraphs are included?) - Generic work fields (WS-WORK-1, etc.) reused for different purposes - Numeric status codes without 88-level names - Commented-out code (is it dead or dormant?) 2. For each anti-pattern found, document: location, risk, and how you would refactor it in modern COBOL.
Exercise 41.8: Knowledge Transfer Simulation
Objective: Practice the knowledge transfer interview process.
Tasks (pair exercise): 1. Student A writes a 200-line COBOL program with intentional complexity (nested IFs, multiple record types, business rules without comments). 2. Student B receives only the compiled program's output (or the source code without comments). 3. Student B has 30 minutes to analyze the code, then 15 minutes to interview Student A about the design decisions. 4. Student B writes a one-page program summary. 5. Compare Student B's summary with Student A's original design intent. Where did understanding fail?
This exercise simulates the real-world challenge of knowledge transfer from a retiring developer.