Chapter 15 Exercises: Report Writer Module
Tier 1: Recall and Recognition (Exercises 1-7)
Exercise 1: Report Writer Terminology
Match each Report Writer element with its purpose:
| Element | Purpose |
|---|---|
| a) RD | 1) Produces a detail line and triggers control break processing |
| b) INITIATE | 2) Defines report-level properties: page size, control fields |
| c) GENERATE | 3) Deactivates the report and triggers final footings |
| d) TERMINATE | 4) Activates the report and triggers the report heading |
| e) PAGE-COUNTER | 5) Automatically incremented page number register |
| f) LINE-COUNTER | 6) Tracks the current line position on the page |
Answers: a-2, b-4, c-1, d-3, e-5, f-6
Exercise 2: Report Group Types
Fill in the blanks with the correct report group TYPE keyword:
a) _ HEADING -- printed once at the very beginning of the report b) _ HEADING -- printed at the top of every page c) _ HEADING -- printed when a control field value changes (before new group) d) _ -- the main body line, one per input record e) _ FOOTING -- printed when a control field value changes (after group ends) f) _ FOOTING -- printed at the bottom of every page g) ____ FOOTING -- printed once at the very end of the report
Answers: a) REPORT, b) PAGE, c) CONTROL, d) DETAIL, e) CONTROL, f) PAGE, g) REPORT
Exercise 3: RD Entry Syntax
Write an RD entry for a monthly bank account statement with the following requirements: - Report name: ACCOUNT-STMT-REPORT - Page limit: 66 lines, heading at line 1, first detail at line 7, last detail at line 60, footing at line 63 - Control fields: branch code (major), account type (intermediate), account number (minor)
Answer:
RD ACCOUNT-STMT-REPORT
PAGE LIMIT IS 66 LINES
HEADING 1
FIRST DETAIL 7
LAST DETAIL 60
FOOTING 63
CONTROLS ARE FINAL
ST-BRANCH-CODE
ST-ACCOUNT-TYPE
ST-ACCOUNT-NUMBER.
Exercise 4: SOURCE vs. SUM vs. VALUE
Explain the difference between the three data-sourcing clauses used in report group entries:
a) SOURCE IS data-name b) SUM data-name-1 [data-name-2 ...] c) VALUE IS literal
Answers: a) SOURCE IS copies the current value of the named data item into the report field each time the group is presented. It is used for detail lines and headings to display the value of input fields or working-storage fields.
b) SUM automatically accumulates (adds up) the values of the named fields across all GENERATE executions. It is used in CONTROL FOOTING groups to produce subtotals and grand totals. SUM fields are automatically reset when their control group is presented.
c) VALUE IS places a constant literal value in the report field. It is used for labels, column headings, separators, and other fixed text that does not change.
Exercise 5: GENERATE Statement Behavior
A Report Writer program has the following control hierarchy: FINAL, BRANCH-CODE, DEPARTMENT-CODE. When the program executes GENERATE DETAIL-LINE and BRANCH-CODE has changed since the last GENERATE, list the exact sequence of report groups that the Report Writer presents:
Answer: 1. CONTROL FOOTING for DEPARTMENT-CODE (close the minor group) 2. CONTROL FOOTING for BRANCH-CODE (close the intermediate group) 3. CONTROL HEADING for BRANCH-CODE (open the new intermediate group) 4. CONTROL HEADING for DEPARTMENT-CODE (open the new minor group) 5. DETAIL line (the actual detail)
The rule is: all footings fire from minor to major, then all headings fire from major to minor, then the detail line is presented. This ensures proper nesting of group boundaries.
Exercise 6: LINE and COLUMN Clauses
Write a report group entry for a page heading that produces this output at lines 1-3:
FIRST NATIONAL BANK
MONTHLY TRANSACTION REPORT
DATE: XX/XX/XXXX PAGE: ZZZ9
Answer:
01 TYPE IS PAGE HEADING.
05 LINE 1.
10 COLUMN 21
VALUE "FIRST NATIONAL BANK".
05 LINE 2.
10 COLUMN 15
VALUE "MONTHLY TRANSACTION REPORT".
05 LINE 3.
10 COLUMN 3
VALUE "DATE: ".
10 COLUMN 9
PIC XX/XX/XXXX
SOURCE IS WS-REPORT-DATE.
10 COLUMN 39
VALUE "PAGE: ".
10 COLUMN 45
PIC ZZZ9
SOURCE IS PAGE-COUNTER.
Exercise 7: INITIATE and TERMINATE Rules
Answer True or False:
a) You must OPEN the report file before executing INITIATE. b) INITIATE automatically triggers the REPORT HEADING group. c) You can execute GENERATE before INITIATE. d) TERMINATE automatically triggers the REPORT FOOTING group and all pending CONTROL FOOTING groups. e) You must CLOSE the report file before executing TERMINATE.
Answers: a) True -- the report file must be open before INITIATE. b) True -- the first GENERATE triggers the report heading (some implementations present it on INITIATE, but the standard says it is presented before the first detail). c) False -- INITIATE must be executed before the first GENERATE. d) True -- TERMINATE fires all outstanding control footings and then the report footing. e) False -- you must TERMINATE before CLOSE, not the other way around. The sequence is: OPEN, INITIATE, GENERATE (loop), TERMINATE, CLOSE.
Tier 2: Comprehension and Application (Exercises 8-15)
Exercise 8: Predict the Report Output
Given the following data (already sorted by branch and department):
| Branch | Dept | Employee | Salary |
|---|---|---|---|
| NYC | IT | Adams | 75000 |
| NYC | IT | Baker | 82000 |
| NYC | FIN | Clark | 91000 |
| CHI | IT | Davis | 70000 |
| CHI | HR | Evans | 65000 |
And an RD with CONTROLS ARE FINAL, RP-BRANCH, RP-DEPT, with SUM fields on the CONTROL FOOTING groups, predict the complete report output including all control headings, detail lines, control footings with subtotals, and the final total.
Answer:
BRANCH: NYC
DEPARTMENT: IT
ADAMS $75,000.00
BAKER $82,000.00
DEPARTMENT IT TOTAL: $157,000.00 (2 EMPLOYEES)
DEPARTMENT: FIN
CLARK $91,000.00
DEPARTMENT FIN TOTAL: $91,000.00 (1 EMPLOYEE)
BRANCH NYC TOTAL: $248,000.00 (3 EMPLOYEES)
BRANCH: CHI
DEPARTMENT: IT
DAVIS $70,000.00
DEPARTMENT IT TOTAL: $70,000.00 (1 EMPLOYEE)
DEPARTMENT: HR
EVANS $65,000.00
DEPARTMENT HR TOTAL: $65,000.00 (1 EMPLOYEE)
BRANCH CHI TOTAL: $135,000.00 (2 EMPLOYEES)
GRAND TOTAL: $383,000.00 (5 EMPLOYEES)
Exercise 9: Write a Basic Report Writer Program
Write a complete Report Writer program that produces a simple account listing report. The input file contains bank account records: - Account Number: PIC X(10) - Customer Name: PIC X(30) - Account Type: PIC X(1) ('C'=Checking, 'S'=Savings, 'M'=Money Market) - Balance: PIC S9(9)V99
The report should have: - A report heading with the bank name and date - Page headings with column labels - Detail lines showing each account - A report footing with total record count and total balance - No control breaks (simple listing)
Answer:
IDENTIFICATION DIVISION.
PROGRAM-ID. RPTLIST.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT ACCT-FILE ASSIGN TO ACCTINP
FILE STATUS IS WS-ACCT-STATUS.
SELECT REPORT-FILE ASSIGN TO RPTOUT
FILE STATUS IS WS-RPT-STATUS.
DATA DIVISION.
FILE SECTION.
FD ACCT-FILE.
01 ACCT-REC.
05 AR-ACCOUNT-NUM PIC X(10).
05 AR-CUST-NAME PIC X(30).
05 AR-ACCT-TYPE PIC X(1).
05 AR-BALANCE PIC S9(9)V99.
FD REPORT-FILE
REPORT IS ACCOUNT-LIST-REPORT.
WORKING-STORAGE SECTION.
01 WS-ACCT-STATUS PIC XX.
01 WS-RPT-STATUS PIC XX.
01 WS-EOF-FLAG PIC X VALUE 'N'.
88 END-OF-FILE VALUE 'Y'.
01 WS-REPORT-DATE PIC X(10).
01 WS-RECORD-COUNT PIC 9(7) VALUE 0.
REPORT SECTION.
RD ACCOUNT-LIST-REPORT
PAGE LIMIT IS 66 LINES
HEADING 1
FIRST DETAIL 8
LAST DETAIL 60
FOOTING 63.
01 TYPE IS REPORT HEADING.
05 LINE 1.
10 COLUMN 20
VALUE "FIRST NATIONAL BANK".
05 LINE 2.
10 COLUMN 15
VALUE "ACCOUNT LISTING REPORT".
05 LINE 3.
10 COLUMN 1
VALUE "DATE: ".
10 COLUMN 7
PIC X(10)
SOURCE IS WS-REPORT-DATE.
01 TYPE IS PAGE HEADING.
05 LINE 6.
10 COLUMN 1 VALUE "ACCOUNT".
10 COLUMN 14 VALUE "CUSTOMER NAME".
10 COLUMN 46 VALUE "TYPE".
10 COLUMN 53 VALUE "BALANCE".
05 LINE 7.
10 COLUMN 1 VALUE "----------".
10 COLUMN 14 VALUE
"------------------------------".
10 COLUMN 46 VALUE "----".
10 COLUMN 53 VALUE "--------------".
01 ACCT-DETAIL-LINE TYPE IS DETAIL
LINE IS PLUS 1.
05 COLUMN 1 PIC X(10)
SOURCE IS AR-ACCOUNT-NUM.
05 COLUMN 14 PIC X(30)
SOURCE IS AR-CUST-NAME.
05 COLUMN 46 PIC X(1)
SOURCE IS AR-ACCT-TYPE.
05 COLUMN 50 PIC $$$,$$$, MATH1 $,$$$,$$9.99
SUM AR-BALANCE.
PROCEDURE DIVISION.
0000-MAIN.
OPEN INPUT ACCT-FILE
OPEN OUTPUT REPORT-FILE
MOVE FUNCTION CURRENT-DATE(1:8)
TO WS-REPORT-DATE
INITIATE ACCOUNT-LIST-REPORT
READ ACCT-FILE
AT END SET END-OF-FILE TO TRUE
END-READ
PERFORM UNTIL END-OF-FILE
ADD 1 TO WS-RECORD-COUNT
GENERATE ACCT-DETAIL-LINE
READ ACCT-FILE
AT END SET END-OF-FILE TO TRUE
END-READ
END-PERFORM
TERMINATE ACCOUNT-LIST-REPORT
CLOSE ACCT-FILE
REPORT-FILE
STOP RUN.
Exercise 10: Control Break Report
Write a Report Writer program that produces a monthly loan portfolio report for a bank. The input file is sorted by branch code and loan type. The report should include:
- Page heading with bank name, report title, date, and page number
- Control heading for each branch (branch code and branch name)
- Detail lines showing loan account, borrower name, original amount, current balance, and interest rate
- Control footing for each branch (count of loans and total current balance)
- Control footing for FINAL (grand total count and grand total balance)
Answer: See code/exercise-solutions.cob (EX10SOL)
Exercise 11: SUM Clause Mechanics
Given the following CONTROL FOOTING definitions, explain what values will be accumulated and when they reset:
01 TYPE IS CONTROL FOOTING RP-BRANCH.
05 LINE PLUS 1.
10 COLUMN 1 VALUE "BRANCH TOTAL: ".
10 COLUMN 20 PIC $$$,$$$, MATH4 MATH5 $,$$9.99
SUM AR-BALANCE.
10 COLUMN 40 PIC ZZZ,ZZ9
SUM WS-RECORD-COUNT.
```
**Answer:**
The SUM clause in the CONTROL FOOTING for RP-BRANCH accumulates AR-BALANCE and WS-RECORD-COUNT for each GENERATE within the current branch group. When the branch changes (and this footing is presented), the accumulated totals are printed and then automatically reset to zero for the next branch group.
The SUM clause in the CONTROL FOOTING for FINAL performs a **sum-of-sums** (also called "rolling forward"). It accumulates the subtotals from the branch-level control footing -- not from the individual GENERATE executions directly. Each time the branch footing fires and prints its subtotal, that subtotal value rolls up into the FINAL footing's SUM fields. At TERMINATE, the FINAL footing prints the grand total of all branch subtotals.
This automatic rollup eliminates the need for the programmer to maintain separate accumulators for each control level.
### Exercise 12: USE BEFORE REPORTING
Explain the purpose of the USE BEFORE REPORTING declarative. Write a USE BEFORE REPORTING section that modifies a detail line before it is printed -- specifically, if the account balance is negative, replace the balance with "*** OVERDRAWN ***" and set a flag.
**Answer:**
The USE BEFORE REPORTING declarative executes custom COBOL logic immediately before a specified report group is presented (printed). It allows you to modify field values, suppress a group, or perform conditional formatting that cannot be expressed purely through Report Writer declarations.
```cobol
DECLARATIVES.
DETAIL-OVERRIDE SECTION.
USE BEFORE REPORTING ACCT-DETAIL-LINE.
DETAIL-OVERRIDE-PARA.
IF AR-BALANCE < 0
MOVE "*** OVERDRAWN ***" TO DL-BALANCE-DISPLAY
SET OVERDRAWN-FLAG TO TRUE
ADD 1 TO WS-OVERDRAWN-COUNT
ELSE
MOVE AR-BALANCE TO DL-BALANCE-EDITED
SET OVERDRAWN-FLAG TO FALSE
END-IF.
END DECLARATIVES.
```
Note: The USE BEFORE REPORTING section must be within the DECLARATIVES area at the beginning of the PROCEDURE DIVISION. The report group name (ACCT-DETAIL-LINE) must match a 01-level group defined in the REPORT SECTION.
### Exercise 13: Page Overflow Behavior
A report is defined with PAGE LIMIT 66, HEADING 1, FIRST DETAIL 7, LAST DETAIL 58, FOOTING 63. The current LINE-COUNTER is at 57 when GENERATE is about to produce a 3-line detail group (LINE PLUS 1, LINE PLUS 1, LINE PLUS 1).
a) Will the detail group fit on the current page?
b) What happens if it does not fit?
c) How does Report Writer handle the page transition?
**Answer:**
a) The detail group needs lines 58, 59, and 60. Since LAST DETAIL is 58, only the first line of the group fits within the designated detail area. The remaining lines (59, 60) would exceed LAST DETAIL.
b) When a detail group would extend beyond LAST DETAIL, Report Writer triggers an automatic page break. The current page's PAGE FOOTING is presented (at line 63), the page is ejected, and the new page's PAGE HEADING is presented. Then the detail group is printed starting at FIRST DETAIL on the new page.
c) The page transition sequence is: present PAGE FOOTING on current page, advance to new page, increment PAGE-COUNTER, present PAGE HEADING on new page, then present the detail group. The entire 3-line detail group appears on the new page starting at line 7 (FIRST DETAIL), ensuring it is not split across pages.
### Exercise 14: Multiple Report Definitions
Can a single COBOL program produce multiple reports using Report Writer? If so, write the DATA DIVISION skeleton showing two reports: an ACCOUNT-SUMMARY-REPORT and a TRANSACTION-DETAIL-REPORT, both written to different output files.
**Answer:**
Yes, a single program can produce multiple reports. Each report has its own FD, RD, and set of report groups. Each report is independently INITIATEd, GENERATEd, and TERMINATEd.
```cobol
FILE SECTION.
FD SUMMARY-FILE
REPORT IS ACCOUNT-SUMMARY-REPORT.
FD DETAIL-FILE
REPORT IS TRANSACTION-DETAIL-REPORT.
REPORT SECTION.
RD ACCOUNT-SUMMARY-REPORT
PAGE LIMIT IS 66 LINES
HEADING 1
FIRST DETAIL 7
LAST DETAIL 60
FOOTING 63
CONTROLS ARE FINAL
SM-BRANCH-CODE.
01 TYPE IS PAGE HEADING.
...summary page heading groups...
01 SUMMARY-LINE TYPE IS DETAIL LINE PLUS 1.
...summary detail fields...
01 TYPE IS CONTROL FOOTING SM-BRANCH-CODE.
...branch subtotal...
01 TYPE IS CONTROL FOOTING FINAL.
...grand total...
RD TRANSACTION-DETAIL-REPORT
PAGE LIMIT IS 66 LINES
HEADING 1
FIRST DETAIL 8
LAST DETAIL 58
FOOTING 62
CONTROLS ARE FINAL
TD-ACCOUNT-NUM.
01 TYPE IS PAGE HEADING.
...transaction page heading groups...
01 TRANS-LINE TYPE IS DETAIL LINE PLUS 1.
...transaction detail fields...
01 TYPE IS CONTROL FOOTING TD-ACCOUNT-NUM.
...account subtotal...
01 TYPE IS CONTROL FOOTING FINAL.
...grand total...
```
In the PROCEDURE DIVISION, both reports are active simultaneously:
```cobol
INITIATE ACCOUNT-SUMMARY-REPORT
TRANSACTION-DETAIL-REPORT
...
GENERATE SUMMARY-LINE
GENERATE TRANS-LINE
...
TERMINATE ACCOUNT-SUMMARY-REPORT
TRANSACTION-DETAIL-REPORT
```
### Exercise 15: Report Writer vs. Manual Coding
A colleague argues that Report Writer is not worth learning because "you can do everything manually with WRITE AFTER ADVANCING." Write a brief comparison addressing:
a) Lines of code for a 3-level control break report (approximate)
b) Automatic subtotal accumulation and reset
c) Automatic page overflow handling
d) Maintenance effort when adding a new control break level
e) Situations where manual coding is actually preferable
**Answer:**
a) A 3-level control break report with page headings and footings typically requires 200-400 lines of manual procedural code (line counting, break detection, accumulator management, page handling). With Report Writer, the same report requires 80-150 lines of declarative code in the REPORT SECTION and 10-20 lines in the PROCEDURE DIVISION.
b) Report Writer automatically accumulates SUM fields and resets them when control footings fire. Manual coding requires declaring separate accumulators for each level, adding to them on every detail, printing and zeroing them on each break -- a major source of bugs.
c) Report Writer handles page overflow automatically, including splitting groups across pages, presenting page headings and footings, and managing LINE-COUNTER. Manual coding requires explicit line counting and conditional page-break logic at every write point.
d) Adding a new control break level to a Report Writer program means adding a CONTROL HEADING and CONTROL FOOTING group and listing the new field in the CONTROLS clause. Manual coding requires restructuring the break-detection logic, adding new accumulators, and modifying the control flow -- often touching dozens of lines.
e) Manual coding is preferable when: the report format is very simple (no control breaks), the output is not paginated (e.g., CSV export), complex conditional formatting is needed that exceeds USE BEFORE REPORTING capabilities, or the programming team has no Report Writer experience and maintenance is a concern.
---
## Tier 3: Apply (Exercises 16-22)
### Exercise 16: Fix This Report Writer Program
The following program compiles but produces a report with missing page headings after the first page and incorrect subtotals. Find and fix all bugs.
```cobol
REPORT SECTION.
RD LOAN-REPORT
PAGE LIMIT IS 66 LINES
FIRST DETAIL 7
LAST DETAIL 60.
01 RPT-HDG TYPE IS REPORT HEADING.
05 LINE 1 COLUMN 20
VALUE "LOAN PORTFOLIO REPORT".
01 DETAIL-LINE TYPE IS DETAIL LINE PLUS 1.
05 COLUMN 1 PIC X(10)
SOURCE IS LN-ACCOUNT.
05 COLUMN 14 PIC X(30)
SOURCE IS LN-BORROWER.
05 COLUMN 50 PIC $$$,$$$,$$9.99
SOURCE IS LN-BALANCE.
01 TYPE IS CONTROL FOOTING FINAL.
05 LINE PLUS 2.
10 COLUMN 1 VALUE "GRAND TOTAL:".
10 COLUMN 50 PIC $$$$,$$$,$$9.99
SOURCE IS WS-TOTAL-BALANCE.
Answer: There are three bugs:
Bug 1: The RD entry is missing the HEADING clause and FOOTING clause, and there is no PAGE HEADING group defined. Without a PAGE HEADING group, no heading appears on pages after the first. The REPORT HEADING only appears once.
Fix: Add HEADING 1 and FOOTING 63 to the RD entry. Add a PAGE HEADING group with column labels:
01 TYPE IS PAGE HEADING.
05 LINE 5.
10 COLUMN 1 VALUE "ACCOUNT".
10 COLUMN 14 VALUE "BORROWER".
10 COLUMN 50 VALUE "BALANCE".
05 LINE 6.
10 COLUMN 1
VALUE "----------".
10 COLUMN 14
VALUE "------------------------------".
10 COLUMN 50
VALUE "--------------".
Bug 2: The CONTROL FOOTING for FINAL uses SOURCE IS WS-TOTAL-BALANCE instead of SUM LN-BALANCE. SOURCE copies the current value of the field, which requires the programmer to manually accumulate it. SUM automatically accumulates across all GENERATE executions.
Fix: Change SOURCE IS WS-TOTAL-BALANCE to SUM LN-BALANCE.
Bug 3: The RD entry has no CONTROLS clause. Without CONTROLS, the CONTROL FOOTING FINAL group will not function correctly because the Report Writer does not know which fields to monitor for control breaks.
Fix: Add CONTROLS ARE FINAL to the RD entry.
Exercise 17: Multi-Level Control Break Report
Write a complete Report Writer program that produces a financial transaction report with three control break levels. The input file is sorted by branch code, account type, and account number. The report should include:
- Report heading with bank name and date
- Page heading with column titles and page number
- Control heading for each branch (branch name)
- Detail lines: account number, customer name, transaction type, amount
- Control footing for account number (account total)
- Control footing for branch (branch total, number of accounts)
- Control footing for FINAL (grand total, total number of branches, total accounts)
- Page footing with "CONTINUED..." message
Include the complete REPORT SECTION and PROCEDURE DIVISION.
Hint: Remember that control fields must be listed in the CONTROLS clause from major (FINAL) to minor. The SUM clause on the branch footing should sum the account-level subtotals (sum of sums), and the FINAL footing should sum the branch-level subtotals.
Exercise 18: GENERATE with Summary Reporting
Write a Report Writer program that produces a summary report (no detail lines) showing only branch-level and grand totals. Use GENERATE report-name (report-level GENERATE) instead of GENERATE detail-line-name.
The input file contains daily transaction records sorted by branch code. The summary report should show: - Branch code, total deposits, total withdrawals, net amount, and transaction count for each branch - Grand totals for all branches
Explain the difference between GENERATE detail-name and GENERATE report-name.
Answer: See code/exercise-solutions.cob (EX18SOL)
The difference: GENERATE detail-name presents the named detail line (after processing any control breaks) and increments all SUM accumulators. GENERATE report-name performs all the same control break processing and SUM accumulation, but does NOT present a detail line. This is called "summary reporting" -- only the control headings and footings appear in the output.
Exercise 19: Debug This Report Output
A Report Writer program produces the following incorrect output. The control footing for department should show the sum of salaries, but instead shows the last salary value. Identify the cause and fix.
Incorrect output:
DEPARTMENT: LENDING
JONES $85,000.00
SMITH $72,000.00
ADAMS $91,000.00
DEPARTMENT TOTAL: $91,000.00 <-- Should be $248,000.00
The CONTROL FOOTING is coded as:
01 TYPE IS CONTROL FOOTING RP-DEPARTMENT.
05 LINE PLUS 1.
10 COLUMN 1 VALUE "DEPARTMENT TOTAL: ".
10 COLUMN 20 PIC $$$,$$$, MATH11 $,$$$,$$9.99
SUM LN-BALANCE.
01 TYPE IS CONTROL FOOTING RP-REGION.
05 LINE PLUS 2.
10 COLUMN 1 VALUE "REGION TOTAL:".
10 COLUMN 50 PIC $$$$,$$$,$$9.99
SOURCE IS BR-TOT-BAL.
01 TYPE IS CONTROL FOOTING FINAL.
05 LINE PLUS 2.
10 COLUMN 1 VALUE "GRAND TOTAL:".
10 COLUMN 50 PIC $$$$$,$$$,$$9.99
SOURCE IS BR-TOT-BAL.
Identify the bug and explain the correct approach.
Hint: The region and final footings use SOURCE instead of SUM. Think about what SOURCE does versus what SUM does at higher control levels.
Exercise 26: Report Writer Limitations Assessment
For each of the following report requirements, determine whether Report Writer can handle it natively, can handle it with USE BEFORE REPORTING, or cannot handle it (requiring manual coding):
a) Cross-footing (row totals that must equal column totals) b) Conditional suppression of detail lines based on a threshold c) A running balance column that carries forward from line to line d) Multi-column (side-by-side) report layout (e.g., two accounts per line) e) Conditional page breaks (new page for each control group, not just on overflow) f) Sorting input data before reporting g) Producing the same report in two formats (print and CSV)
Hint: USE BEFORE REPORTING is very powerful and can handle many situations, but it cannot fundamentally change the report's structure (like multi-column layout).
Exercise 27: Migration from Report Writer to Modern Reporting
A legacy banking application uses Report Writer to produce 47 different reports. The bank is considering migrating to a modern reporting tool. Evaluate the trade-offs:
a) What features of Report Writer translate directly to modern tools (Crystal Reports, BIRT, etc.)? b) What features would require redesign? c) How would you handle the transition period when both old and new reports must be produced? d) Estimate the effort (in developer-months) to migrate 47 reports, given that each averages 200 lines of REPORT SECTION code.
Hint: Consider that modern reporting tools can connect directly to databases, eliminating the need for sorted flat files. But they may not support the same batch-oriented, page-precise formatting that Report Writer provides.
Exercise 28: Designing a Report Writer Template System
A bank has 15 branches, each needing the same monthly statement report but with different headers (branch name, address, manager). Design a system that uses a single Report Writer program but produces branch-specific reports:
a) How would you parameterize the branch-specific information? b) How would you control which branch's data is included? c) Could you produce all 15 branch reports in a single program execution? d) How would you handle page numbering (restart at 1 for each branch vs. continuous)?
Hint: Consider using WORKING-STORAGE fields (populated from a parameter file or the input data) as SOURCE references in the report heading. PAGE-COUNTER can be explicitly reset between branches.
Tier 5: Create (Exercises 29-33)
Exercise 29: Complete Bank Statement System
Design and write a complete Report Writer program that produces customer bank statements. Each customer gets a multi-page statement showing:
- Customer header: name, address, account number, statement period
- Previous balance brought forward
- Detail lines: date, description, reference number, debit, credit, running balance
- Page subtotals (total debits and credits per page)
- Account summary: opening balance, total debits, total credits, closing balance
- Promotional message or fee disclosure in the report footing
The input file is sorted by customer number and transaction date. Each customer should start on a new page. The running balance must be calculated in USE BEFORE REPORTING.
Hint: Use the customer number as a control field. The control heading for the customer would contain the account information. The running balance requires a working-storage field that persists across detail lines but resets on each customer break.
Exercise 30: Multi-Department Payroll Report
Write a complete Report Writer program for a bank's internal payroll department. The report has four control levels: division, department, pay grade, and employee. The input is sorted accordingly. Include:
- SUM fields that automatically roll up from employee to pay grade to department to division to grand total
- Percentage-of-total calculations in USE BEFORE REPORTING declaratives
- A "top earners" flag for employees in the top pay grade of each department
- Proper handling of page breaks (no control heading at the bottom of a page without its first detail)
- Counts at every level (employees per grade, grades per department, etc.)
Exercise 31: Audit Trail Report Generator
Write a Report Writer program that produces a formatted audit trail from a bank's transaction log. The log contains millions of entries sorted by date, then by user ID. The report must:
- Show a date heading for each day
- Under each date, show a user heading for each operator
- Detail lines show timestamp, transaction type, account affected, amount, and result code
- User subtotal: count of transactions, total amount, count of errors
- Daily subtotal: count of users active, total transactions, total errors
- Grand total: count of days, total users, total transactions, total errors
- Exception highlighting: use USE BEFORE REPORTING to flag transactions with error codes
Design the complete REPORT SECTION with at least 8 report group types.
Exercise 32: Comparative Financial Report
Design and write a Report Writer program that produces a year-over-year comparison report. Each input record contains both current-year and prior-year figures for a general ledger account. The report should show:
- Account number and description
- Prior year balance
- Current year balance
- Dollar variance (current - prior)
- Percentage variance ((current - prior) / prior * 100)
- A trend indicator: "UP", "DOWN", or "FLAT" (within 1%)
The calculations for variance and percentage must be done in USE BEFORE REPORTING. The control breaks are by account category and subcategory. Handle division-by-zero for accounts with a zero prior-year balance.
Exercise 33: Report Writer Test Harness
Design and write a COBOL program that serves as a test harness for verifying Report Writer output. The program should:
- Generate a known set of test data (50 records with predictable values across 3 control levels)
- Write the test data to a sequential file
- Run the Report Writer program (via CALL or inline)
- Read the produced report output file line by line
- Verify that: the correct number of pages were produced, control headings appear in the right places, subtotals are mathematically correct, the grand total equals the sum of all input values
- Produce a test results summary: PASS/FAIL for each verification point
This is a meta-exercise in testing Report Writer programs, which is notoriously difficult because the output is formatted text rather than structured data.
Hint: One approach is to write validation logic that parses the report output looking for known patterns (e.g., "BRANCH TOTAL:" followed by a numeric amount that should match a calculated expected value). Store expected values in a table and compare them against extracted actuals.