Chapter 29: Exercises – Mainframe Utilities for COBOL Developers
These exercises progress through five tiers of cognitive complexity. Detailed solutions are provided for exercises 1–3, and hints are given for exercises 4–5. All remaining exercises include only the problem statement so you can practice independently.
Tier 1 — Recall
Exercise 1: Identifying Utility Purposes
Problem: Match each mainframe utility with its primary purpose.
| Utility | Purpose |
|---|---|
| IDCAMS | ? |
| IEBGENER | ? |
| IEBCOPY | ? |
| DFSORT | ? |
| IEFBR14 | ? |
| ICEGENER | ? |
| SuperC | ? |
Choose from: (A) Sort and merge datasets, (B) Copy sequential datasets, (C) Manage VSAM and catalog operations, (D) Copy and compress PDS members, (E) Do-nothing utility for JCL allocation/deletion, (F) High-performance sequential copy, (G) Compare datasets or members.
Solution
| Utility | Purpose | |-----------|---------| | IDCAMS | (C) Manage VSAM and catalog operations | | IEBGENER | (B) Copy sequential datasets | | IEBCOPY | (D) Copy and compress PDS members | | DFSORT | (A) Sort and merge datasets | | IEFBR14 | (E) Do-nothing utility for JCL allocation/deletion | | ICEGENER | (F) High-performance sequential copy | | SuperC | (G) Compare datasets or members |Exercise 2: IDCAMS Command Recall
Problem: List the five most commonly used IDCAMS functional commands and write a one-sentence description of what each does.
Solution
1. **DEFINE CLUSTER** — Creates a VSAM dataset (KSDS, ESDS, RRDS, or LDS) along with its DATA and INDEX components. 2. **REPRO** — Copies records from one dataset to another, commonly used to load data into VSAM files or to back them up. 3. **DELETE** — Removes a VSAM cluster, alternate index, or non-VSAM dataset from the catalog and DASD. 4. **PRINT** — Displays the contents of a VSAM or sequential dataset in character, hexadecimal, or dump format. 5. **LISTCAT** — Lists catalog entries and their attributes such as record counts, space allocation, and key definitions.Exercise 3: DFSORT SORT Fields Syntax
Problem: A payroll file has the following layout:
| Field | Position | Length | Format |
|---|---|---|---|
| Employee-ID | 1–8 | 8 | Character |
| Department-Code | 9–12 | 4 | Character |
| Annual-Salary | 13–21 | 9 | Packed Decimal |
| Hire-Date (YYYYMMDD) | 22–29 | 8 | Character |
Write the DFSORT SORT FIELDS control statement to sort this file in ascending order by Department-Code and then descending order by Annual-Salary within each department.
Solution
SORT FIELDS=(9,4,CH,A,13,9,PD,D)
Explanation:
- `9,4,CH,A` — Start position 9, length 4, Character format, Ascending (Department-Code).
- `13,9,PD,D` — Start position 13, length 9, Packed Decimal format, Descending (Annual-Salary).
The sort first groups records by department and then arranges employees from highest to lowest salary within each department.
Exercise 4: IEBGENER DD Statements
Problem: Name the four DD statements required in a standard IEBGENER job step and describe the purpose of each.
Hint
Think about what IEBGENER needs: an input source, an output destination, a control card source, and a place to write messages. The DD names follow a standard naming convention specific to IEBGENER.Exercise 5: IDCAMS LISTCAT Output Fields
Problem: When you run LISTCAT ENTRIES(dataset-name) ALL, what key pieces of information does IDCAMS report for a VSAM KSDS cluster? List at least six attributes.
Hint
Consider attributes related to the cluster itself, the DATA component, and the INDEX component. Think about record sizes, key definitions, space allocation, CI/CA sizes, and record counts.Tier 2 — Understand
Exercise 6: REPRO vs. IEBGENER for VSAM Loading
Explain why IDCAMS REPRO is preferred over IEBGENER when loading data into a VSAM KSDS. In your explanation, address what happens if the input data is not in key sequence.
Exercise 7: Interpreting a DFSORT INCLUDE Condition
Given the following DFSORT control statements, describe in plain English which records will appear in the output:
SORT FIELDS=(1,10,CH,A)
INCLUDE COND=(25,2,CH,EQ,C'NY',
OR,
25,2,CH,EQ,C'NJ',
OR,
25,2,CH,EQ,C'CT')
OMIT COND=(50,6,PD,LT,+100000)
Exercise 8: IEBCOPY Compress-in-Place
A production PDS named PROD.COBOL.COPYLIB has run out of directory blocks even though there is unused space inside. Explain how IEBCOPY can resolve this issue and write the JCL to do so.
Exercise 9: IEFBR14 for Dataset Allocation
A junior developer claims that IEFBR14 is useless because it does nothing. Write a paragraph explaining why IEFBR14 is actually one of the most frequently used utilities in production JCL, and give two concrete use cases.
Exercise 10: DFSORT SUM FIELDS Behavior
Explain what happens when you code SUM FIELDS=(45,8,PD) in a DFSORT job. What prerequisite must be true about the SORT FIELDS for SUM to work correctly? What happens to duplicate keys?
Tier 3 — Apply
Exercise 11: Writing a Complete IDCAMS DEFINE CLUSTER
A banking application requires a new VSAM KSDS to store customer account records. The specifications are:
- Dataset name:
BANK.PROD.ACCTMSTR - Record size: average 350 bytes, maximum 500 bytes
- Key: 12 bytes starting at offset 0 (Account Number)
- Primary space: 50 cylinders, secondary: 10 cylinders
- Shareoptions: (2,3)
- Freespace: 20% CI, 10% CA
Write the complete IDCAMS DEFINE CLUSTER command and the surrounding JCL to execute it.
Exercise 12: DFSORT Report with OUTFIL
The payroll file from Exercise 3 needs a formatted report. Using DFSORT OUTFIL, produce output that:
- Includes a header line:
DEPARTMENT SALARY REPORT - Reformats each record to show Department-Code (positions 9–12), a space, Employee-ID (positions 1–8), a space, and Annual-Salary edited with commas and a dollar sign.
- Includes a trailer line with the total number of records processed.
Write the complete DFSORT control statements.
Exercise 13: IDCAMS REPRO with Selection Criteria
Write an IDCAMS REPRO command that copies records from BANK.PROD.ACCTMSTR to BANK.BACKUP.ACCTMSTR but only includes records whose keys fall within the range 100000000001 through 199999999999.
Exercise 14: Multi-Step Utility Job
Write a complete JCL job with three steps:
- Step 1: Delete the dataset
FINANCE.WORK.SORTOUTif it exists (should not fail if it does not exist). - Step 2: Sort the input file
FINANCE.PROD.TRANFILEby transaction date (positions 15–22, character, ascending) and amount (positions 23–31, packed decimal, descending), excluding records where the status code at position 40 equals'V'(voided). Output toFINANCE.WORK.SORTOUT. - Step 3: Print the first 100 records of
FINANCE.WORK.SORTOUTusing IDCAMS PRINT.
Exercise 15: ICEGENER vs. IEBGENER
You have been asked to replace all IEBGENER steps in a suite of 200 batch jobs with ICEGENER. Write the JCL for a sample ICEGENER step that copies INPUT.DATA.FILE to OUTPUT.DATA.FILE (FB, LRECL=150, BLKSIZE=27750). Explain what performance benefit this provides.
Exercise 16: SuperC Comparison Job
Two versions of a COBOL copybook exist: DEV.COPYLIB(ACCTFMT) and PROD.COPYLIB(ACCTFMT). Write the JCL to run SuperC (ISRSUPC) to compare them and produce a listing dataset with the differences.
Exercise 17: DFSORT INREC Reformatting
An input transaction file has fields scattered across positions that make sorting inefficient. The file layout is:
| Field | Position | Length |
|---|---|---|
| Filler | 1–20 | 20 |
| Account-Number | 21–32 | 12 |
| Transaction-Amt | 33–40 | 8 (PD) |
| Branch-Code | 41–44 | 4 |
| Transaction-Date | 45–52 | 8 |
Using INREC, rearrange the record so that Branch-Code comes first, followed by Transaction-Date, Account-Number, and Transaction-Amt. Then sort by Branch-Code ascending and Transaction-Date ascending.
Tier 4 — Analyze
Exercise 18: Diagnosing IDCAMS Return Codes
A production job fails with the following IDCAMS output:
IDC3003I FUNCTION IS COMPLETED, FOR
CLUSTER BANK.PROD.ACCTMSTR
IDC3009I ** VSAM CATALOG RETURN CODE IS 8 -
REASON CODE IS IGG0CLEG-42
IDC0551I ** ENTRY BANK.PROD.ACCTMSTR NOT FOUND
IDC0001I FUNCTION COMPLETED, HIGHEST CONDITION CODE WAS 8
Analyze this output. What went wrong? What corrective actions should be taken? How should the JCL be structured to prevent this job from failing in production?
Exercise 19: DFSORT Performance Analysis
A DFSORT job sorting a 50-million-record file takes 45 minutes to run. The current control statements are:
SORT FIELDS=(1,80,CH,A)
OPTION EQUALS
The actual sort key should be positions 1–10 (Account Number). Analyze what is causing poor performance and rewrite the control statements for optimal execution. Estimate the performance improvement.
Exercise 20: Choosing the Right Utility
For each of the following scenarios, identify the best utility to use and justify your choice:
- Copy a single PDS member to a sequential file.
- Delete a GDG base and all its generations.
- Create a summary report from a sorted transaction file showing totals by region.
- Allocate an empty dataset for later use by an application.
- Copy all members from one PDS to another, retaining ISPF statistics.
- Compare two load modules to see if they are identical.
Exercise 21: IDCAMS DELETE and IF-THEN-ELSE Logic
A job stream must delete three VSAM clusters and recreate them. However, on the first run, the clusters do not exist. Write IDCAMS control statements that use IF LASTCC / SET MAXCC logic so that the DELETE commands do not cause the step to end with a non-zero return code, but any error in the DEFINE CLUSTER commands is still detected.
Exercise 22: DFSORT OUTFIL for Multiple Outputs
A financial institution needs to split a sorted transaction file into three separate output files based on transaction type:
- Type
'CR'(positions 10–11) goes to DD nameCREDITS - Type
'DB'(positions 10–11) goes to DD nameDEBITS - All other types go to DD name
OTHER
Additionally, each output file must have a header record containing the file description and processing date. Write the complete DFSORT control statements.
Exercise 23: Utility Error Recovery Strategy
A nightly batch cycle runs 15 IDCAMS steps that define, load, and verify VSAM clusters for the next day's processing. Step 9 fails because of a B37 abend (out of space). Analyze the following concerns and propose a recovery strategy:
- Which steps may need to be rerun, and which can be skipped?
- How should IDCAMS conditional logic be structured to allow restart?
- What JCL changes could prevent the space issue from recurring?
Tier 5 — Create
Exercise 24: End-of-Day Batch Utility Suite
Design a complete end-of-day batch processing JCL job stream for a banking system. The stream must:
- Back up the current VSAM account master using IDCAMS REPRO to a sequential file.
- Sort the daily transaction file by account number using DFSORT, omitting voided transactions.
- Run the COBOL update program against the master file.
- Produce three DFSORT-generated reports: a transaction summary by branch, an exception report for transactions over $100,000, and a record count reconciliation.
- Back up the updated master file to a GDG.
- Include appropriate condition code checking, restart logic, and error handling throughout.
Write all JCL and utility control statements. Document your design decisions.
Exercise 25: DFSORT-Based Data Quality Framework
Create a data quality validation framework using DFSORT that processes an incoming customer file and:
- Produces a "clean" output file with only valid records.
- Produces an "error" output file with rejected records, each prefixed with an error code.
- Validates: (a) Account number (positions 1–12) is numeric, (b) State code (positions 25–26) matches a list of valid codes (NY, NJ, CT, PA, CA, TX, FL, IL), (c) Balance field (positions 50–57, PD) is not negative.
- Produces a summary report showing counts of records processed, accepted, and rejected by each validation rule.
Write all DFSORT control statements with detailed comments explaining each section.
Exercise 26: Automated VSAM Cluster Migration Utility
A bank is migrating from one VSAM naming convention to another. There are 40 clusters whose names must change from OLD.PROD.xxxxx to NEW.PROD.xxxxx. Design a utility job stream (using IDCAMS and any other needed utilities) that:
- Reads a control file containing old-name/new-name pairs.
- For each pair: exports data from the old cluster via REPRO, deletes the old cluster, defines the new cluster with identical attributes, and loads data into the new cluster.
- Verifies record counts match before and after migration.
- Produces an audit report of all actions taken.
Describe the approach, write the key JCL and IDCAMS control statements for a single iteration, and explain how you would automate the full 40-cluster migration.
Exercise 27: ISPF-Based Developer Productivity Toolkit
Design an ISPF panel and the corresponding REXX or CLIST logic that allows a COBOL developer to:
- Select a COBOL program from a PDS and automatically generate the JCL to compile, link-edit, and run it with test data.
- Compare the current version of any copybook against the production version using SuperC.
- Run IDCAMS LISTCAT against any dataset and display the results in a scrollable ISPF browse.
- Invoke DFSORT to create a sample extract from any sequential or VSAM file.
Provide the ISPF panel definition, the driving REXX/CLIST code, and all utility JCL templates.
Exercise 28: Cross-Utility Reconciliation Process
A financial reconciliation process must verify that data across three systems (general ledger, accounts receivable, and accounts payable) is in balance at end-of-day. Design and write a JCL job stream that:
- Uses DFSORT to extract and summarize total debits and credits from each of three input files.
- Uses ICEGENER to merge the summaries into a single reconciliation file.
- Uses IDCAMS PRINT to produce an audit-quality printout.
- Uses a COBOL program stub (provide the PROCEDURE DIVISION logic) to compare totals and set a return code of 0 if balanced or 16 if out of balance.
- Uses IEFBR14 and condition code checking to control whether downstream jobs should run.
Write all JCL, DFSORT control statements, and the COBOL comparison logic.
Exercise 29: Building a Reusable DFSORT Procedure Library
Create a library of at least five reusable DFSORT procedures (cataloged procedures or INCLUDE members) for common financial data processing tasks:
- Date format conversion (YYYYMMDD to MM/DD/YYYY and vice versa).
- Record deduplication with duplicate count reporting.
- Fixed-width to delimited file conversion for downstream analytics systems.
- Running balance calculation across sorted transaction records.
- Data masking for sensitive fields (account numbers, SSNs) for use in test environments.
For each procedure, provide the DFSORT control statements, a sample JCL invocation, sample input data, and expected output. Explain how each procedure leverages DFSORT features like INREC, OUTREC, OUTFIL, IFTHEN, and OVERLAY.
Exercise 30: Comprehensive Utility Decision Matrix
Create a decision matrix document that a junior developer could use to select the right mainframe utility for any given task. The matrix should cover:
- All utilities discussed in this chapter.
- At least 20 common mainframe tasks.
- For each task: recommended utility, alternate utility, key DD names, common return codes, and a one-line JCL template.
- A troubleshooting section with the 10 most common utility errors and their resolutions.
- A performance comparison showing when to choose ICEGENER over IEBGENER, and when DFSORT can replace both.
Present this as a structured reference with tables and examples.