Exercises — Chapter 12: Indexed File Processing (VSAM KSDS)

Exercise 12.1: Building a Student Records KSDS

Difficulty: Beginner

Create a COBOL program that manages a student records file using indexed organization.

Requirements:

  1. Define a STUDENT-FILE with the following layout: - STUDENT-ID (PIC X(08)) — primary key - STUDENT-NAME (PIC X(30)) - STUDENT-MAJOR (PIC X(20)) - STUDENT-GPA (PIC 9V99) - STUDENT-CREDITS (PIC 9(03)) - STUDENT-STATUS (PIC X(01)) — 'A' active, 'G' graduated, 'W' withdrawn

  2. Write a loader program that: - Opens the file for OUTPUT - Writes at least 10 records with varying data - Checks file status after every WRITE - Displays a count of records written - Closes the file

  3. Write a separate inquiry program that: - Opens the file for INPUT - Accepts a student ID from ACCEPT statement - Reads the record by key - Displays all fields in a formatted layout - Handles the "not found" case gracefully

Deliverables: Two programs — STUD-LOAD.cbl and STUD-INQ.cbl


Exercise 12.2: Range Browsing

Difficulty: Intermediate

Extend Exercise 12.1 by writing a browse program.

Requirements:

  1. Accept a starting student ID and ending student ID
  2. Use START to position at the beginning of the range
  3. Use READ NEXT to iterate through the range
  4. Display each record found within the range
  5. After browsing, display: - Total records found - Average GPA of students in range - Count of active vs. graduated vs. withdrawn

Challenge: Add a "filter" option — browse only students with GPA above a user-specified threshold.


Exercise 12.3: Full CRUD Operations

Difficulty: Intermediate

Build a complete account maintenance program modeled on the ACCT-MAINT example from Section 12.9.

Requirements:

  1. Use the student records file from Exercise 12.1
  2. Read transaction commands from a sequential input file
  3. Support operations: - 'A' — Add new student - 'U' — Update student (change major, GPA, credits, or status) - 'D' — Withdraw student (logical delete — set status to 'W') - 'I' — Inquiry (display student record)
  4. Write all results to a report file
  5. Track counters for each operation type
  6. Write a summary at end of processing

Test Data: Create a transaction file with at least 15 transactions including: - 3 adds (one duplicate to test error handling) - 4 updates (one for non-existent student) - 2 deletes (one for non-existent student) - 6 inquiries


Exercise 12.4: Alternate Key Access

Difficulty: Intermediate-Advanced

Add alternate key access to the student records system.

Requirements:

  1. Add ALTERNATE RECORD KEY on STUDENT-MAJOR WITH DUPLICATES
  2. Write a program that: - Browses all students in a user-specified major - Counts students per major - Calculates average GPA per major - Displays results sorted by major

  3. Add a second alternate key on STUDENT-NAME WITH DUPLICATES

  4. Write a name-lookup function that finds students by name

Question to consider: What performance impact would three alternate keys have on WRITE operations? How would you evaluate the trade-off for a file with 100,000 records that gets 500 inserts/day and 10,000 lookups/day?


Exercise 12.5: Error Handling Drill

Difficulty: Intermediate

This exercise focuses on defensive programming with status codes.

Requirements:

  1. Write a program that intentionally triggers each of the following status codes, then handles them: - '00' — Successful operation - '10' — End of file - '22' — Duplicate key - '23' — Record not found - '35' — File not found on OPEN

  2. For each status code: - Display a descriptive message - Log the error to an error file - Continue processing (for recoverable errors) or abend gracefully (for fatal errors)

  3. Create a reusable CHECK-FILE-STATUS paragraph that can be called after any I/O operation. It should accept the operation name and handle all known status codes.


Exercise 12.6: Production-Quality Loader

Difficulty: Advanced

Write a production-quality file loader that reads customer data from a sequential extract file and loads it into a VSAM KSDS.

Requirements:

  1. Input: Sequential file with pipe-delimited fields
  2. Output: VSAM KSDS customer file
  3. Processing: - Validate all input fields before writing - Reject records with invalid data (write to reject file with reason) - Handle duplicate keys (write to duplicate file) - Checkpoint every 1,000 records (display progress message) - Write processing statistics at end of job

  4. Validation rules: - Customer ID must be numeric - Name must not be blank - State must be a valid 2-letter code - Balance must be numeric with valid sign

Deliverables: The loader program, sample input data, expected output


Exercise 12.7: Multi-Mode Access Program

Difficulty: Advanced

Write a program that demonstrates all three access modes (SEQUENTIAL, RANDOM, DYNAMIC) by processing the same file in different ways within a single execution.

Requirements:

  1. Use DYNAMIC access mode
  2. Phase 1: Load records sequentially (WRITE in key order)
  3. Phase 2: Random lookups of specific records (READ with key)
  4. Phase 3: Browse from a starting point (START + READ NEXT)
  5. Phase 4: Update specific records (READ + REWRITE)
  6. Phase 5: Delete specific records (DELETE)
  7. Phase 6: Final sequential browse to display all remaining records

Display timing information (ACCEPT FROM TIME) at the start and end of each phase.


Exercise 12.8: GlobalBank Mini-Project

Difficulty: Advanced (Project)

Build a simplified version of GlobalBank's account system with the following components:

  1. Account Master File (VSAM KSDS): - Account number (key), name, type, balance, status, branch

  2. Programs to build: - ACCT-LOAD: Initial file loader - ACCT-INQ: Single account inquiry - ACCT-BRW: Range browse - ACCT-UPD: Balance update (deposit/withdrawal) - ACCT-RPT: Full account listing report

  3. Requirements: - All programs share a COPYBOOK for the record layout - All programs include comprehensive file status checking - ACCT-UPD must validate sufficient balance for withdrawals - ACCT-RPT must include subtotals by account type

This exercise prepares you for the full banking system capstone in Chapter 43.