Chapter 15 Quiz: Report Writer Module
Test your understanding of the COBOL Report Writer module. Each question is followed by a hidden answer -- try to answer before revealing it.
Question 1
Which DATA DIVISION section contains the RD (Report Description) entry?
- a) FILE SECTION
- b) WORKING-STORAGE SECTION
- c) REPORT SECTION
- d) LINKAGE SECTION
Show Answer
**c) REPORT SECTION**. The REPORT SECTION is a subdivision of the DATA DIVISION that contains all RD entries and their subordinate report group definitions. The REPORT SECTION appears after the WORKING-STORAGE SECTION and before the LINKAGE SECTION. Each RD entry describes one report, and each report must be associated with an FD entry in the FILE SECTION via the REPORT IS clause.Question 2
Which three PROCEDURE DIVISION verbs are used to drive Report Writer?
- a) OPEN, WRITE, CLOSE
- b) INITIATE, GENERATE, TERMINATE
- c) START, READ, STOP
- d) BEGIN, PRODUCE, END
Show Answer
**b) INITIATE, GENERATE, TERMINATE**. INITIATE activates the report and prepares it for processing. GENERATE produces detail lines and triggers control break processing. TERMINATE deactivates the report, fires all pending control footings, and presents the report footing. The programmer still uses OPEN and CLOSE for the underlying report file, but the report-specific processing uses these three verbs.Question 3
How many report group types does the COBOL Report Writer standard define?
- a) 3
- b) 5
- c) 7
- d) 9
Show Answer
**c) 7**. The seven report group types are: 1. REPORT HEADING (RH) -- printed once at the start 2. PAGE HEADING (PH) -- printed at the top of each page 3. CONTROL HEADING (CH) -- printed when a control field changes (before the group) 4. DETAIL (DE) -- the main body line 5. CONTROL FOOTING (CF) -- printed when a control field changes (after the group) 6. PAGE FOOTING (PF) -- printed at the bottom of each page 7. REPORT FOOTING (RF) -- printed once at the endQuestion 4
What clause in the RD entry specifies which data fields are monitored for control breaks?
- a) BREAK FIELDS ARE
- b) CONTROLS ARE
- c) GROUP KEYS ARE
- d) SORT FIELDS ARE
Show Answer
**b) CONTROLS ARE**. The CONTROLS clause lists the data fields that the Report Writer monitors for value changes. When a control field's value changes between successive GENERATE executions, the appropriate CONTROL FOOTING and CONTROL HEADING groups are triggered. The keyword FINAL can be included to designate a grand-total level that fires once at the end of the report (on TERMINATE). Fields are listed from major to minor.Question 5
What does the SUM clause in a CONTROL FOOTING accomplish?
- a) Counts the number of records in the group
- b) Automatically accumulates the values of named fields across GENERATE executions
- c) Computes the arithmetic sum of all fields in the record
- d) Adds a literal value to a running total
Show Answer
**b) Automatically accumulates the values of named fields across GENERATE executions**. Each time GENERATE is executed, the SUM clause adds the current value of the named data items to an internal accumulator. When the CONTROL FOOTING is presented (because the control field changed or TERMINATE was executed), the accumulated total is placed in the SUM field and the accumulator is automatically reset to zero for the next group. At higher control levels, SUM can reference SUM fields from lower-level footings, producing a "sum of sums" rollup.Question 6
What is the difference between GENERATE detail-name and GENERATE report-name?
- a) There is no difference; they are interchangeable
- b) GENERATE report-name produces all report groups; GENERATE detail-name produces only the detail
- c) GENERATE detail-name presents the detail line and processes control breaks; GENERATE report-name processes control breaks and accumulates SUM fields but does NOT present a detail line
- d) GENERATE report-name can only be used once per program execution
Show Answer
**c) GENERATE detail-name presents the detail line and processes control breaks; GENERATE report-name processes control breaks and accumulates SUM fields but does NOT present a detail line**. The report-level GENERATE is used for "summary reporting" where only control headings and footings appear in the output, with no individual detail lines. Both forms trigger control break processing and SUM accumulation identically; the only difference is whether the detail line is presented.Question 7
In the PAGE LIMIT clause PAGE LIMIT IS 66 HEADING 1 FIRST DETAIL 7 LAST DETAIL 58 FOOTING 63, on which line can the first detail line appear?
- a) Line 1
- b) Line 6
- c) Line 7
- d) Line 8
Show Answer
**c) Line 7**. The FIRST DETAIL clause specifies the earliest line number on which a DETAIL report group can appear. Lines 1 through 6 are reserved for the PAGE HEADING (and any CONTROL HEADING that appears before the first detail). LAST DETAIL 58 means no detail line can start after line 58. The FOOTING area (lines 59-63) is reserved for CONTROL FOOTING and PAGE FOOTING groups.Question 8
What special register is automatically incremented each time a new page begins in a Report Writer report?
- a) LINE-COUNTER
- b) PAGE-COUNTER
- c) REPORT-COUNTER
- d) LINAGE-COUNTER
Show Answer
**b) PAGE-COUNTER**. PAGE-COUNTER is a special register automatically maintained by Report Writer. It is set to 1 when INITIATE executes and is incremented by 1 each time a new page begins. It can be referenced as a SOURCE field in page headings or footings to display the current page number. The programmer can also explicitly set PAGE-COUNTER (e.g., to restart page numbering for a new section).Question 9
What is the purpose of the USE BEFORE REPORTING declarative?
- a) To define the format of report groups
- b) To execute custom COBOL logic immediately before a specified report group is presented
- c) To sort the input data before report generation
- d) To open and close the report file
Show Answer
**b) To execute custom COBOL logic immediately before a specified report group is presented**. USE BEFORE REPORTING is coded in the DECLARATIVES section of the PROCEDURE DIVISION. It allows the programmer to modify field values, perform calculations, conditionally suppress a group (using SUPPRESS PRINTING), or execute any other COBOL logic before the Report Writer presents the named group. This is the escape hatch for any formatting or logic that cannot be expressed purely through Report Writer declarations.Question 10
When multiple control fields change simultaneously (e.g., both branch and department change because a new branch starts), what is the order in which CONTROL FOOTING and CONTROL HEADING groups are presented?
- a) All headings first, then all footings
- b) All footings from minor to major, then all headings from major to minor
- c) Footings and headings alternate for each level
- d) Only the highest-level footing and heading are presented
Show Answer
**b) All footings from minor to major, then all headings from major to minor**. When multiple control breaks occur simultaneously, the Report Writer first closes all open groups by presenting footings from the innermost (most minor) level outward to the changed level. Then it opens the new groups by presenting headings from the outermost (most major) changed level inward to the most minor level. This ensures proper nesting: every group that was open gets a footing before the new groups get headings.Question 11
Which of the following is a valid location for the SOURCE clause?
- a) Only in DETAIL report groups
- b) Only in CONTROL FOOTING report groups
- c) In any report group type (headings, details, footings)
- d) Only in PAGE HEADING groups
Show Answer
**c) In any report group type (headings, details, footings)**. The SOURCE clause can appear in any report group. In a PAGE HEADING, it might reference PAGE-COUNTER or a date field. In a DETAIL line, it references input record fields. In a CONTROL FOOTING, it could reference a working-storage accumulator. The SOURCE clause simply copies the current value of the named data item into the report field when the group is presented.Question 12
How does the FD entry for a Report Writer output file differ from a normal FD entry?
- a) It uses SD instead of FD
- b) It includes a REPORT IS clause naming the report(s) associated with the file
- c) It must not include a record description
- d) Both b and c
Show Answer
**d) Both b and c**. The FD for a Report Writer file includes `REPORT IS report-name` (or `REPORTS ARE report-name-1 report-name-2...` for multiple reports). The record description is typically minimal -- just a single 01-level with a PIC X(n) large enough to hold the longest report line. Some compilers allow omitting the record description entirely because Report Writer manages the output buffer. The actual report layout is defined in the REPORT SECTION, not in the FD.Question 13
True or False: INITIATE automatically opens the report file.
Show Answer
**False**. INITIATE does NOT open the report file. The programmer must explicitly OPEN the report file (OPEN OUTPUT or OPEN EXTEND) before executing INITIATE. Similarly, TERMINATE does not close the file -- the programmer must CLOSE the file after TERMINATE. The correct sequence is: OPEN, INITIATE, GENERATE (loop), TERMINATE, CLOSE.Question 14
True or False: A single COBOL program can contain multiple RD entries for different reports.
Show Answer
**True**. A single program can define and produce multiple reports. Each report has its own RD entry in the REPORT SECTION, its own set of report group definitions, and is associated with its own FD entry (or multiple reports can share one FD, though this is uncommon). Each report is independently INITIATEd, GENERATEd, and TERMINATEd.Question 15
True or False: The SUM clause automatically resets its accumulator to zero after the CONTROL FOOTING is presented.
Show Answer
**True**. After a CONTROL FOOTING group containing a SUM clause is presented, the SUM accumulator is automatically reset to zero. This means each control group starts accumulating fresh totals from zero. This automatic reset is one of the key benefits of Report Writer -- it eliminates the manual "zero the accumulator" logic that is a common source of bugs in hand-coded control break reports.Question 16
True or False: Report Writer can produce control break reports from unsorted input data.
Show Answer
**False**. Report Writer assumes the input data is already sorted on the control fields in the same order as they are listed in the CONTROLS clause (major to minor). If the input data is not sorted, the Report Writer will detect a "control break" every time the field values do not match the previous record, producing incorrect subtotals and excessive control headings/footings. The programmer must ensure the input is properly sorted before driving the report with GENERATE.Question 17
True or False: LINE-COUNTER can be explicitly set by the programmer to force a specific line position.
Show Answer
**True**. While LINE-COUNTER is normally maintained automatically by Report Writer, the programmer can explicitly modify it (e.g., in a USE BEFORE REPORTING declarative). However, doing so is generally discouraged because it can disrupt Report Writer's internal page management logic, potentially causing formatting errors or infinite loops. It is safer to let Report Writer manage LINE-COUNTER and use the LINE clause on report groups to control positioning.Question 18
True or False: The SUPPRESS PRINTING statement can be used in a USE BEFORE REPORTING section to prevent a report group from being presented.
Show Answer
**True**. SUPPRESS PRINTING, when executed within a USE BEFORE REPORTING declarative, prevents the associated report group from being presented (printed) for the current occurrence. This is useful for conditional detail suppression (e.g., hiding zero-balance accounts) or conditional footing suppression. The SUM accumulation still occurs even when the group is suppressed -- only the visual presentation is affected.Question 19
What is the output of the following PROCEDURE DIVISION code? Assume the input file has 5 records all with BRANCH = 'NYC'.
OPEN INPUT TRANS-FILE
OPEN OUTPUT REPORT-FILE
INITIATE BRANCH-REPORT
READ TRANS-FILE
AT END SET END-OF-FILE TO TRUE
END-READ
PERFORM UNTIL END-OF-FILE
GENERATE BRANCH-DETAIL-LINE
READ TRANS-FILE
AT END SET END-OF-FILE TO TRUE
END-READ
END-PERFORM
TERMINATE BRANCH-REPORT
CLOSE TRANS-FILE REPORT-FILE
STOP RUN.
The report has: REPORT HEADING, PAGE HEADING, CONTROL HEADING for BRANCH, DETAIL, CONTROL FOOTING for BRANCH, CONTROL FOOTING for FINAL, REPORT FOOTING.
Show Answer
The output sequence is: 1. **REPORT HEADING** -- presented before the first GENERATE (triggered by the first GENERATE or INITIATE, depending on implementation) 2. **PAGE HEADING** -- presented at the top of the first page 3. **CONTROL HEADING for BRANCH (NYC)** -- the first GENERATE detects a new branch value 4. **DETAIL line** (record 1) -- first GENERATE 5. **DETAIL line** (record 2) -- second GENERATE (no control break, same branch) 6. **DETAIL line** (record 3) -- third GENERATE 7. **DETAIL line** (record 4) -- fourth GENERATE 8. **DETAIL line** (record 5) -- fifth GENERATE 9. **CONTROL FOOTING for BRANCH (NYC)** -- triggered by TERMINATE 10. **CONTROL FOOTING for FINAL** -- triggered by TERMINATE 11. **REPORT FOOTING** -- triggered by TERMINATE Since all records have the same branch, there is only one control break cycle (at the end). TERMINATE fires all pending footings in order from minor to major, then presents the report footing.Question 20
A report group is defined as follows. What does it produce?
01 TYPE IS CONTROL FOOTING RP-BRANCH.
05 LINE PLUS 2.
10 COLUMN 1 VALUE "BRANCH TOTAL:".
10 COLUMN 20 PIC $$$,$$$, MATH1 $,$$9.99
SOURCE IS TX-AMOUNT.
05 COLUMN 35 PIC $$$,$$$,$$9.99
SUM TX-AMOUNT.
Show Answer
**No, this will not work.** The SUM clause is only valid in CONTROL FOOTING groups, not in DETAIL groups. SUM accumulates values for presentation in footings, not for running totals in detail lines. To produce a running balance, the programmer should: 1. Define a working-storage field: `01 WS-RUNNING-BAL PIC S9(9)V99 VALUE 0.` 2. In a USE BEFORE REPORTING declarative for the detail line, add the current amount: `ADD TX-AMOUNT TO WS-RUNNING-BAL` 3. Use SOURCE IS WS-RUNNING-BAL in the detail line for the running balance column The running balance field should be reset to zero in the USE BEFORE REPORTING for the appropriate control heading if it should restart for each control group.Question 24
What is the significance of the NEXT GROUP clause in a report group definition?
01 TYPE IS CONTROL FOOTING RP-BRANCH
NEXT GROUP IS NEXT PAGE.
05 LINE PLUS 2.
10 COLUMN 1 VALUE "BRANCH TOTAL:".
10 COLUMN 40 PIC $$$,$$$, MATH5 $,$$$,$$9.99
SUM TX-AMOUNT.
01 TYPE IS CONTROL FOOTING RP-REGION.
05 LINE PLUS 2.
10 RG-TOTAL COLUMN 40
PIC $$$$,$$$,$$9.99
SUM BR-TOTAL.
01 TYPE IS CONTROL FOOTING FINAL.
05 LINE PLUS 2.
10 COLUMN 40
PIC $$$$$,$$$,$$9.99
SUM RG-TOTAL.
How do the totals flow?
Show Answer
The "sum of sums" works as follows: 1. **Branch level (SUM TX-AMOUNT):** Each GENERATE adds the current TX-AMOUNT to BR-TOTAL's accumulator. When a branch break occurs, BR-TOTAL shows the sum of all TX-AMOUNT values within that branch. The accumulator resets to zero for the next branch. 2. **Region level (SUM BR-TOTAL):** Each time the branch CONTROL FOOTING fires and presents BR-TOTAL, that value is added to RG-TOTAL's accumulator. When a region break occurs, RG-TOTAL shows the sum of all branch subtotals within that region. This is equivalent to the sum of all TX-AMOUNT values within the region, but it is computed by adding up the branch totals, not by re-summing individual transactions. 3. **FINAL level (SUM RG-TOTAL):** Each time the region CONTROL FOOTING fires and presents RG-TOTAL, that value is added to the FINAL accumulator. At TERMINATE, the FINAL footing shows the sum of all region subtotals, which equals the grand total of all transactions. This cascading accumulation means the programmer only needs to define SUM at each level referencing the level below -- Report Writer handles the rollup automatically. The grand total is guaranteed to equal the sum of all individual detail amounts because each level sums the next lower level's totals.Question 27
True or False: Report Writer can produce output to a display screen (ACCEPT/DISPLAY) rather than a print file.
Show Answer
**False**. Report Writer is designed exclusively for producing output to files (typically print files). All Report Writer output goes through the associated FD entry using WRITE operations managed internally by the Report Writer runtime. It cannot direct output to DISPLAY statements or interactive screens. For screen-based reporting, you would need to use manual COBOL code, Screen Section, or an external reporting tool.Question 28
What happens if TERMINATE is executed without any GENERATE having been executed first?
Show Answer
If TERMINATE is executed after INITIATE but before any GENERATE, the behavior depends on the implementation. In most standard-conforming implementations: - The REPORT HEADING may or may not have been presented (it is typically triggered by the first GENERATE) - No CONTROL HEADING, DETAIL, or CONTROL FOOTING groups are presented - The REPORT FOOTING is presented (if defined) - SUM fields will all be zero since no data was accumulated This scenario typically occurs when the input file is empty. The program should check for an empty file condition and either skip the INITIATE/TERMINATE cycle entirely or accept that a minimal report (heading and footing only) will be produced. Some implementations may issue a warning or produce an empty report file.Question 29
A report has two DETAIL group types defined:
01 REGULAR-DETAIL TYPE IS DETAIL LINE PLUS 1.
...
01 SUMMARY-DETAIL TYPE IS DETAIL LINE PLUS 1.
...
Can the program selectively GENERATE one or the other? How?
Show Answer
**Yes**, the program can selectively GENERATE either detail group by name: IF TX-TYPE = 'R'
GENERATE REGULAR-DETAIL
ELSE
GENERATE SUMMARY-DETAIL
END-IF
Each GENERATE statement names the specific detail group to present. Both detail types share the same control break processing (they are under the same RD), so either GENERATE will trigger control headings and footings as needed. SUM fields accumulate regardless of which detail type is generated.
This feature is useful for reports that have multiple line formats -- for example, a transaction report where deposits and withdrawals have different field layouts.
Question 30
What does the GROUP INDICATE clause do in a detail line definition?
01 TRANS-DETAIL TYPE IS DETAIL LINE PLUS 1.
05 COLUMN 1 PIC X(10)
SOURCE IS TX-ACCOUNT
GROUP INDICATE.
05 COLUMN 15 PIC X(8)
SOURCE IS TX-DATE.
05 COLUMN 30 PIC $$$,$$9.99
SOURCE IS TX-AMOUNT.
Show Answer
The **GROUP INDICATE** clause causes the field to be printed only on the first detail line after a control break or at the top of a new page. On subsequent detail lines within the same control group (and same page), the field is suppressed (replaced with spaces). In this example, TX-ACCOUNT will be printed on the first transaction for each account and then suppressed for subsequent transactions of the same account. This produces the classic "group indicated" report format:1234567890 01/15/26 $1,500.00
01/16/26 $250.00
01/17/26 $3,200.00
9876543210 01/15/26 $800.00
01/18/26 $1,100.00
This improves readability by reducing visual clutter from repeated account numbers.