Exercises — Chapter 38: Batch Processing Patterns
Exercise 38.1: Basic Checkpoint/Restart
Objective: Implement a checkpoint/restart mechanism for a sequential file processing program.
Setup: Create a test file with 50,000 sequential records, each containing a 6-digit record number, a 10-character name, and a 9(7)V99 amount field.
Tasks: 1. Write a program that reads the input file, validates each record (reject records with negative amounts), and writes valid records to an output file. 2. Add checkpoint logic that writes a checkpoint record every 5,000 input records. The checkpoint must store: records read, records written, records rejected, the last key processed, and financial total of amounts. 3. Modify the initialization logic to detect a prior checkpoint and resume from the restart point. 4. Test your restart by running the program, then killing it at approximately record 25,000. Verify that restarting skips the already-processed records.
Deliverables: - Complete COBOL program with checkpoint/restart - JCL to run the program (or GnuCOBOL compile/run script) - Test results showing successful restart
Hints: - Use a separate sequential file for the checkpoint record - Remember to REWRITE the checkpoint record, not WRITE a new one each time - On restart, read through the input file to skip already-processed records
Exercise 38.2: Control Total Verification
Objective: Implement comprehensive control totals in a two-step batch process.
Tasks: 1. Write Program A that reads a transaction file, processes records, and writes both an output file and a control total file. Track: record count, hash total of account numbers, and financial total of amounts. 2. Write Program B that reads Program A's output file as input. Before processing, Program B reads the control total file and verifies that the input file matches Program A's output totals. 3. If control totals do not match, Program B should abort with return code 16 and display the mismatched values. 4. Test by manually editing Program A's output file to introduce a mismatch, then verify that Program B catches it.
Deliverables: - Two complete COBOL programs - Control total file layout - JCL or scripts for both steps - Test results showing both balanced and unbalanced scenarios
Exercise 38.3: Audit Trail Implementation
Objective: Build a field-level audit trail for a master file update program.
Tasks: 1. Create a simple customer master file (VSAM KSDS or indexed sequential) with fields: customer-id, name, address, credit-limit, balance, status. 2. Write an update program that reads transaction records specifying field-level changes (e.g., "change credit-limit from 5000 to 10000"). 3. For each field that changes, write an audit trail record containing: timestamp, program-id, customer-id, field-name, before-value, after-value. 4. Write a simple audit report program that reads the audit trail and produces a formatted report of all changes.
Deliverables: - Master file creation program (or IDCAMS definition) - Update program with audit trail - Audit report program - Sample output showing before/after images
Exercise 38.4: Balanced Update Pattern
Objective: Implement the classic balanced line update algorithm.
Tasks: 1. Create a sorted master file with 1,000 records (keys 0001–1000), each containing a key, name, and balance. 2. Create a sorted transaction file with approximately 500 records. Include: updates to existing keys, additions of new keys (1001–1050), deletions of some existing keys, and multiple transactions for the same key. 3. Implement the balanced update pattern. Your program must handle: matched updates, matched deletes, unmatched adds, unmatched updates/deletes (error), multiple transactions per master key. 4. Produce a new master file and an error/exception report.
Deliverables: - Master file creation program - Transaction file creation program - Balanced update program - Error report output - Final master file record count verification
Challenge Extension: Add checkpoint/restart to your balanced update program.
Exercise 38.5: GDG Simulation
Objective: Understand GDG concepts by simulating them on a non-mainframe system (or using actual GDGs on z/OS).
For z/OS students: 1. Define a GDG base with a limit of 5 using IDCAMS. 2. Write a program that creates a new generation with today's transactions. 3. Write JCL that runs the program, creating generation (+1). 4. Run the job five times to fill the GDG, then run it a sixth time to observe rolloff. 5. Write a comparison program that reads generation (0) and generation (-1).
For GnuCOBOL students: 1. Simulate GDGs using a naming convention: TXNARCH.G0001, TXNARCH.G0002, etc. 2. Write a shell script that manages generation numbers (increment, rolloff at limit). 3. Write a COBOL program that accepts the generation filename as a parameter and writes the archive. 4. Demonstrate the creation and rolloff of 5 generations.
Exercise 38.6: Multi-Step Job Stream Design
Objective: Design and implement a three-step batch job stream with inter-step control total verification.
Scenario: Process a student grade file through three steps: 1. Step 1 — Extract: Read raw grade records, validate format, write valid records to an intermediate file. Write control totals. 2. Step 2 — Calculate: Read the intermediate file, compute GPA for each student (average of grades weighted by credit hours), write results. Verify input control totals from Step 1. Write output control totals. 3. Step 3 — Report: Read the results file, produce a dean's list report (GPA >= 3.5) and a probation report (GPA < 2.0). Verify input control totals from Step 2.
Requirements: - Each step must verify input against prior step's output control totals - Each step must set appropriate return codes (0, 4, 8, 12) - JCL (or scripts) must use conditional execution based on return codes - Each step must be independently restartable
Deliverables: - Three COBOL programs - JCL or shell scripts with conditional execution - Control total files between steps - Sample output for all three steps
Exercise 38.7: Error Threshold Management
Objective: Implement configurable error threshold management in a batch program.
Tasks: 1. Write a program that processes records with intentional validation rules (e.g., amount must be positive, date must be valid, code must be in a valid set). 2. Add error threshold logic with configurable parameters: maximum error count, maximum error percentage, and rolling error rate (errors in last N records). 3. Create a test file with varying error rates — clean records at the start, increasingly bad records in the middle, clean records at the end. 4. Run the program with different threshold settings and observe the behavior.
Deliverables: - COBOL program with error threshold logic - Parameter file with configurable thresholds - Test data with varying error rates - Results showing threshold triggering at different settings
Exercise 38.8: Comprehensive Batch System (Integration Exercise)
Objective: Build a complete mini batch system that integrates all patterns from this chapter.
Scenario: You are building a simplified payroll batch system with the following steps: 1. Extract time records from a flat file 2. Validate time records against employee master file 3. Calculate gross pay, taxes, deductions, net pay 4. Update employee master with YTD totals 5. Generate pay stubs and a payroll register report
Requirements: - Checkpoint/restart on the Calculate step (largest volume) - Control totals at every step boundary - Audit trail for all master file updates - GDG (or simulated GDG) for archiving each run's output - Error threshold management - Proper return codes at every step - JCL or scripts with conditional execution
This is a substantial project. Plan your data layouts first, then implement one step at a time. This exercise is suitable for a multi-week assignment.
Deliverables: - Five COBOL programs - All supporting JCL/scripts - Data file layouts document - Test data - Execution results showing successful run, restart after failure, and control total verification