Exercises — Chapter 14: Advanced File Techniques
Exercise 14.1: Simple Balanced-Line Update
Difficulty: Intermediate
Implement the balanced-line algorithm for a student records system.
Requirements:
- Master file (sorted by Student ID): Student ID, Name, Major, GPA, Credits, Status
-
Transaction file (sorted by Student ID): Student ID, Transaction Type, Data - Type 'A': Add new student (data = Name, Major) - Type 'U': Update GPA (data = new GPA value) - Type 'G': Graduate (change status to 'G') - Type 'D': Drop (change status to 'D')
-
Output files: - New master file (updated student records) - Exception file (rejected transactions with reason codes) - Summary report
-
Test scenarios to include: - Master-only records (no transactions) - Single transaction per master - Multiple transactions per master (e.g., update GPA then graduate) - Add transaction (no matching master) - Transaction for non-existent student - Duplicate add attempt
-
Create test data with 10 master records and 15+ transactions.
Exercise 14.2: Two-File Merge
Difficulty: Beginner-Intermediate
Write a program that merges two sorted files into one.
Requirements:
- File A: Employee records from East region (sorted by Employee ID)
- File B: Employee records from West region (sorted by Employee ID)
-
Output: Merged file with all employees in Employee ID order
-
Handle: - Records unique to File A - Records unique to File B - Records with the same Employee ID in both files (flag as duplicate in report)
-
Produce a merge summary showing counts from each source and total output.
Exercise 14.3: Single-Level Control Break Report
Difficulty: Intermediate
Build a control break report for account data.
Requirements:
- Input: Account file sorted by Branch Code, Account Number
- Report layout: - Header with report title and date - Detail lines: Branch, Account Number, Name, Balance - Branch subtotals: count of accounts, total balance, average balance - Grand totals: total accounts, total balance, average balance
- Page break handling: Start a new page after 50 detail lines
- Format balances with commas and dollar signs
Exercise 14.4: Multi-Level Control Break
Difficulty: Advanced
Extend Exercise 14.3 to a three-level control break.
Requirements:
- Input: Account file sorted by Region, Branch, Account Type
- Break levels: - Account Type subtotal (within branch) - Branch subtotal (within region) - Region subtotal - Grand total
- Each level shows: count, total balance, percentage of parent total
- Higher-level breaks must trigger all lower-level breaks
- Add sort-order verification (abort if input is not properly sorted)
Exercise 14.5: File Comparison and Reconciliation
Difficulty: Intermediate
Write a reconciliation program for two extracts of the same data.
Requirements:
- File A: Yesterday's account extract (Account Number, Name, Balance)
- File B: Today's account extract (same layout)
- Output reconciliation report showing: - Records in both files with no changes - Records in both files with balance changes (show old and new balance) - Records in File A only (accounts that disappeared) - Records in File B only (new accounts) - Summary counts for each category
- Calculate: total balance change from yesterday to today
Exercise 14.6: Checkpoint/Restart Implementation
Difficulty: Advanced
Add checkpoint/restart capability to a long-running program.
Requirements:
- Processing program: Read a large sequential file, perform calculations on each record, write results to an output file
- Checkpoint every 1,000 records: - Save: last key processed, record count, running totals, timestamp - Write checkpoint record to a checkpoint file
- Restart logic: - Check for existing checkpoint file on startup - If found, restore state and position to restart point - If not found, start from beginning
- Test by: - Running with 5,000 records — verify it completes normally - Simulating a failure at record 3,000 (add a forced STOP RUN) - Restarting — verify it resumes from the last checkpoint - Verify final output is identical to the non-interrupted run
Exercise 14.7: MedClaim Claims Matching
Difficulty: Advanced
Build a simplified claims adjudication program.
Requirements:
-
Claims file (sequential, sorted by Claim ID): - Claim ID, Member ID, Provider ID, Procedure Code, Billed Amount, Service Date
-
Provider file (indexed, VSAM KSDS): - Provider ID (key), Name, Specialty, Contract Status, Max Allowed Amount
-
Member file (indexed, VSAM KSDS): - Member ID (key), Name, Plan Code, Effective Date, Term Date
-
Processing: - For each claim, look up provider (random access) - Look up member (random access) - Validate: provider is in-network, member is active, service date within coverage period, billed amount <= max allowed - Write approved claims, denied claims (with reason), and processing report
-
Create test data: 50 claims, 20 providers, 30 members. Include scenarios for all denial reasons.
Exercise 14.8: GlobalBank Mini-Project — Daily Batch Cycle
Difficulty: Advanced (Project)
Build a simplified version of GlobalBank's daily batch cycle as a series of coordinated programs.
Step 1: SORT-TXN — Sort the daily transaction file by account number
Step 2: DAILY-UPDATE — Balanced-line update of account master (old master + sorted transactions = new master + exceptions)
Step 3: BRANCH-RPT — Control break report of the new master file by branch
Step 4: RECONCILE — Compare old master + transactions against new master to verify correctness
Requirements for each step: - File status checking on all I/O - Comprehensive counters and summary report - Error handling that writes to exception files, never silently skips - Clear paragraph naming and documentation
This exercise prepares you for the full banking system capstone in Chapter 43.