Exercises — Chapter 16: Report Writer

Exercise 16.1: Basic Report Writer Program

Difficulty: Beginner

Write a Report Writer program that produces a simple employee listing: - Page heading with report title, date, and page number - Detail line with employee ID, name, department, and salary - Page footing with "Continued" message - Report footing with "End of Report"

No control breaks are required. Input file should be a simple sequential employee file. Target 132-column output.

Exercise 16.2: Single-Level Control Break

Difficulty: Beginner

Extend Exercise 16.1 to add a single control break by department: - Control heading showing the department code and name - Detail lines for employees within each department - Control footing showing the department's total salary and employee count - Control footing FINAL showing grand total salary and total employees

Input must be pre-sorted by department.

Exercise 16.3: Multi-Level Control Breaks

Difficulty: Intermediate

Write a Report Writer program for a sales report with three control levels: - Region (major): Control heading and footing with region totals - Branch (intermediate): Control heading and footing with branch totals - Salesperson (minor): Control heading and footing with individual totals

Detail lines show individual sales transactions. All SUM values should cascade correctly from salesperson to branch to region to FINAL grand totals.

Create test data with at least 3 regions, 2 branches per region, and 3 salespeople per branch.

Exercise 16.4: GROUP INDICATE

Difficulty: Intermediate

Modify Exercise 16.3 to use GROUP INDICATE on the region and branch fields in detail lines. The region should appear only on the first detail line of each region group, and the branch should appear only on the first detail line of each branch group. Compare the output with and without GROUP INDICATE.

Exercise 16.5: Summary Report

Difficulty: Intermediate

Using the same input file as Exercise 16.3, write a second Report Writer program that produces a summary-only report (no detail lines). Use GENERATE report-name instead of GENERATE detail-name. The report should show only control headings, control footings with subtotals, and the FINAL grand total.

Exercise 16.6: Manual Control Break Report

Difficulty: Intermediate

Rewrite Exercise 16.2 (single-level control break by department) using manual control break logic — no Report Writer. Your manual version must: - Track line counts and handle page overflow - Detect control breaks by comparing current department to previous - Maintain subtotals and grand totals manually - Handle the first-record and last-record edge cases

Compare the two programs (Report Writer vs. manual) in terms of lines of code, readability, and maintenance effort.

Exercise 16.7: USE BEFORE REPORTING

Difficulty: Advanced

Write a Report Writer program that uses the USE BEFORE REPORTING declarative to look up additional information before printing a control heading. Specifically: - Input file contains transaction records with account numbers - In the CONTROL HEADING for each account, display the account holder's name - Use USE BEFORE REPORTING to perform a lookup (from a table in WORKING-STORAGE or a reference file) to find the name for the current account number

Exercise 16.8: Dual Report Program

Difficulty: Advanced

Write a single program that produces two reports simultaneously from the same input data: 1. A detailed transaction report (GENERATE detail-name) showing every transaction 2. A summary report (GENERATE report-name) showing only subtotals

Both reports should be defined with separate RD entries and written to separate files. Process the input file only once, generating both reports in the same loop.

Exercise 16.9: Complex Manual Report

Difficulty: Advanced

Write a manual report program (no Report Writer) that produces a two-level control break report with the following features: - Conditional detail line formatting: positive amounts in one format, negative in another - Percentage calculations in control footings (e.g., each department's percentage of grand total) - A summary section at the end with averages - These features would be difficult to implement in Report Writer alone

Exercise 16.10: Report Writer with Sort

Difficulty: Challenge

Combine Chapter 15 (Sort) with Chapter 16 (Report Writer). Write a program that: 1. Reads an unsorted transaction file 2. Validates records in an INPUT PROCEDURE (filtering invalid records) 3. Sorts by region, then branch, then date 4. In the OUTPUT PROCEDURE, feeds sorted records to a Report Writer report with two control levels (region and branch)

This requires careful management of the interaction between SORT's OUTPUT PROCEDURE and Report Writer's GENERATE. The OUTPUT PROCEDURE opens the report file, INITIATEs the report, RETURNs and GENERATEs in a loop, and TERMINATEs before closing.