You are on page 1of 49

CHAPTER 10

Control Break
Processing
Structured COBOL Programming, Stern &
Stern, 9th Edition
An Introduction to
Control Break Processing
Structured COBOL Programming, Stern &
Stern, 9th Edition
An Introduction to
Control Break Processing
Types of Reports: A Systems Overview
Printed Reports fall into three major categories:
Detail or Transaction Reports
Exception Reports
Summary Reports
Another type of report, Displayed Output,
results from interactive processing.
Structured COBOL Programming, Stern &
Stern, 9th Edition
Detail or Transaction Reports
Detail or transaction reports are those that
include one or more lines of output for each
input record read. The following are examples:
Customer bills generated from a master
accounts receivable file would be an example of
a transaction or detail report.
Payroll checks generated from a master payroll file
would be a detail report.
A listing of each part number stocked by a company
would be a detail report.

Structured COBOL Programming, Stern &
Stern, 9th Edition
Exception Reports
A listing of those clients with overdue balances is
an example of an exception report.
An exception report is any printout of individual
records that meet (or fail to meet) certain
criteria. Other examples of exception reports
are:
A list of employees who are 65 years old or
older.
A list of part numbers in stock with a quantity on
hand below some minimum value.
Structured COBOL Programming, Stern &
Stern, 9th Edition
Summary Reports
As the name suggests, a summary or group
report summarizes rather than itemizes.
Often summaries or totals can provide more
comprehensive and meaningful information
for the user than a detail or exception report.
Structured COBOL Programming, Stern &
Stern, 9th Edition
MONTHLY STATUS REPORT
DEPT SALESPERSON NO. AMT OF SALES
01 12345 $ 988.55
01 12345 $ 3, 537.00
01 12347 $ 34.99
TOTAL FOR DEPT IS $4,560.54
02 12222 $ 9,877.00
02 12234 $ 87.77
TOTAL FOR DEPT IS $9,964.77
03 15645 $ 980.00
03 12321 $ 1,987.00
TOTAL FOR DEPT IS $2,967.00


Structured COBOL Programming, Stern &
Stern, 9th Edition
A Single-Level Control Break
Control Break Processing is when a field
(known as the key or control field) changes
from one record to the next.
When this change takes place then the
following takes place:
An appropriate control total line is printed.
The appropriate control field is initialized.
The appropriate control total is initialized.

Structured COBOL Programming, Stern &
Stern, 9th Edition
Sample Input
0112345098855
0112346353700
0112347003499
0212222987700
0212234008777
0315645098000
0312321198000
Structured COBOL Programming, Stern &
Stern, 9th Edition
Program Excerpt



100-MAIN-MODULE.
PERFORM 500-INITIALIZATION-RTN
PERFORM 400-HEADING-RTN
PERFORM 200-DETAIL-RTN UNTIL
ARE-THERE-MORE-RECORDS = NO .
PERFORM 600-END-OF-JOB-RTN.
STOP RUN.
Structured COBOL Programming, Stern &
Stern, 9th Edition
A Modular, Top-Down Approach
Program Excerpt
...
500-INITIALIZATION-RTN.
OPEN INPUT SALES-IN
OUTPUT PRINT-OUT.
READ SALES-IN
AT END MOVE NO TO ARE-THERE-MORE-RECORDS.
MOVE DEPT-IN TO WS-HOLD-DEPT.
Structured COBOL Programming, Stern &
Stern, 9th Edition
200-DETAIL-RTN
Program Excerpt

200-DETAIL-RTN.

IF DEPT-IN NOT = WS-HOLD-DEPT
PERFORM 300-CONTROL-BREAK
IF WS-LINE-CT > 25
PERFORM 400-HEADING-RTN
Structured COBOL Programming, Stern &
Stern, 9th Edition
200-DETAIL-RTN (Continued)
200-DETAIL-RTN.
MOVE DEPT-IN TO DL-DEPT-OUT
MOVE SLSNO-IN TO DL-SLSNO-OUT
MOVE AMT-OF-SALES-IN TO DL-AMT-OF-SALES-OUT
WRITE PRINT-REC FROM DETAIL-LINE
AFTER ADVANCING 2 LINES
ADD 1 TO WS-LINE-CT
ADD AMT-OF-SALES-IN TO WS-DEPT-TOTAL.
READ SALES-IN
AT END MOVE NO TO ARE-THERE-MORE-RECORDS.
Structured COBOL Programming, Stern &
Stern, 9th Edition
300-CONTROL-BREAK
In the 300-CONTROL-BREAK module we print
a summary line after a record is read that has
a different department number than the one
stored at WS-HOLD-DEPT.
300-CONTROL-BREAK is performed when an
input record's DEPT-IN, the control field,
differs from the one stored at WS-HOLD-
DEPT.
Structured COBOL Programming, Stern &
Stern, 9th Edition
300-CONTROL-BREAK
When there is a change in DEPT-IN, we must:
1. Print a line with the department total accumulated
for the previous DEPT-IN control group, which is
stored in WS-DEPT-TOTAL.
2. Reinitialize WS-DEPT-TOTAL, the control total, so
that the next department's total begins at zero before
any amounts for the new control group have been
accumulated.
Structured COBOL Programming, Stern &
Stern, 9th Edition
300-CONTROL-BREAK
3. Move the current DEPT-IN to WS-HOLD-DEPT
so that we can compare succeeding input
records to this new DEPT-IN control field.
4. Return to 200-DETAIL-RTN and process the
current record by printing a detail line and adding
the amount to the control total.
Structured COBOL Programming, Stern &
Stern, 9th Edition
300-CONTROL-BREAK
Program Excerpt
300-CONTROL-BREAK.
MOVE WS-DEPT-TOTAL TO DEPT-TOTAL-OUT
WRITE PRINT-REC FROM GROUP-REC
AFTER ADVANCING 2 LINES
ADD 1 TO WS-LINE-CT
MOVE ZEROS TO WS-DEPT-TOTAL
MOVE DEPT-IN TO WS-HOLD-DEPT.
Structured COBOL Programming, Stern &
Stern, 9th Edition
Forcing a Control Break When There
Are No More Records
Control break printing of totals occurs when:
A record with a new control field is read.
The total for the last group of records, then, will
have been accumulated when ARE-THERE-
MORE-RECORDS is equal to 'NO '.
A control total will not have been printed since there
is no subsequent record to trigger a change.
Structured COBOL Programming, Stern &
Stern, 9th Edition
Forcing a Control Break When There
Are No More Records
DEPT
01
01
01
02 --- 01 totals are printed when 02 is read
02
03 --- 02 totals are printed when 03 is read
03
(no more records)
At this point, the printing of 03 totals must be
``forced'' after ARE-THERE-MORE-RECORDS
is set equal to 'NO '
Structured COBOL Programming, Stern &
Stern, 9th Edition
Forcing a Control Break When There
Are No More Records
600-END-OF-JOB-RTN.
MOVE WS-DEPT-TOTAL TO DEPT-TOTAL
WRITE PRINT-REC FROM GROUP-REC
AFTER ADVANCING 2 LINES
CLOSE SALES-IN
PRINT-OUT.
Structured COBOL Programming, Stern &
Stern, 9th Edition
REFINEMENTS TO IMPROVE
THE QUALITY OF A CONTROL
BREAK REPORT
Structured COBOL Programming, Stern &
Stern, 9th Edition
Printing a Final Total
Sometimes, control break processing also
requires the printing of a summary line
containing a final total.
This summary line (with final total) would be
printed after the last control total is written.
Structured COBOL Programming, Stern &
Stern, 9th Edition
Printing a Final Total
Method 1
The final total, which we will call WS-FINAL-
TOTAL, may be accumulated by adding
AMT-OF-SALES-IN for each record.
This may be accomplished by changing the ADD
instruction in the 200- DETAIL-RTN to:
ADD AMT-OF-SALES-IN TO WS-DEPT-
TOTAL WS-
FINAL-TOTAL


Structured COBOL Programming, Stern &
Stern, 9th Edition
Printing a Final Total
Method 2
The WS-FINAL-TOTAL may be accumulated,
instead, by adding each WS-DEPT-TOTAL to it
in 300-CONTROL-BREAK.
This means that WS-FINAL-TOTAL would be
accumulated, not for each detail record, but
only when a control break has occurred.
Structured COBOL Programming, Stern &
Stern, 9th Edition
Printing a Final Total
Method 2
This would be accomplished by coding the
following before we reinitialize WS-DEPT-
TOTAL:
300-CONTROL-BREAK.
...
ADD WS-DEPT-TOTAL TO WS-FINAL-
TOTAL
MOVE ZEROS TO WS-DEPT-TOTAL
...
Structured COBOL Programming, Stern &
Stern, 9th Edition
Starting a New Page After Each Control
Break
It is likely that separate pages of a control break
report will be distributed to different users.
In this case, it is useful to have each department's data
begin on a new page.
Thus, a control break module would also include
a statement to PERFORM the heading routine
so that the paper is advanced to a new page
when a control break occurs.

Structured COBOL Programming, Stern &
Stern, 9th Edition
Starting a New Page After Each
Control Break
We would add a PERFORM statement to the
300-CONTROL-BREAK module for printing
headings on a new page each time that
module is executed.
In this instance, it would be redundant to print
the Department Number on each detail line.
Rather, it would be better to print it once at
the beginning of each page as a page
heading.


Structured COBOL Programming, Stern &
Stern, 9th Edition
Sequence-Checking or Sorting
For accurate control break processing, records
must be in sequence by the control field.
It might be useful to check to make certain,
after each control break, that no sequence
error occurred. If one did, an error message
should be printed.
Structured COBOL Programming, Stern &
Stern, 9th Edition
Executing the Control Break Module
from the Main Module After an End-
of-File Condition Has Been Met
If we wish to force a control break at the
end of the job, it is best to perform the
sequence of steps in the control break
routine.
Structured COBOL Programming, Stern &
Stern, 9th Edition
QUESTIONS?
Structured COBOL Programming, Stern &
Stern, 9th Edition
SELF-TEST
1. In control break processing, we typically
MOVE the control field to ____ after reading
the first record (when FIRST-RECORD =
'YES').


Solution: a hold or WORKING-STORAGE area
Structured COBOL Programming, Stern &
Stern, 9th Edition
SELF-TEST
2. What processing is performed if an input
control field is equal to the control field stored
in the hold area?



Solution: We add to a control total and print, if
detail printing is required.
Structured COBOL Programming, Stern &
Stern, 9th Edition
SELF-TEST
3. What processing is performed if an input
control field is not equal to the control field
stored in the hold area?



Solution: We perform a control break
procedure.
Structured COBOL Programming, Stern &
Stern, 9th Edition
SELF-TEST
4. If each control group is to begin on a
separate page, we would perform a heading
routine at the ____ module.



Solution: control break
Structured COBOL Programming, Stern &
Stern, 9th Edition
SELF-TEST
5. If a final total is required, it is most efficient to
accumulate the final total in the ____
module.



Solution: control break
Structured COBOL Programming, Stern &
Stern, 9th Edition
SELF-TEST
6. At the control break module, we must print
____ , initialize ____ at zero, and move
____ .


Solution: the control total; the control total; the
input control field to the hold area
Structured COBOL Programming, Stern &
Stern, 9th Edition
SELF-TEST
7. When each individual input record results in
the printing of an output line, we call this
____ .



Solution: detail or transaction printing
Structured COBOL Programming, Stern &
Stern, 9th Edition
Multiple-Level Control Breaks
When two or more fields are required as
control fields:
Use a double-level control break
Need two holding areas for comparison
purposes.
Structured COBOL Programming, Stern &
Stern, 9th Edition
Multiple-Level Control Breaks
Sample Input Data
DEPT-IN SLSNO-IN AMT-OF-TRANS-IN
01 001* 34555
01 001* 54434
01 002* 65544
01 003* 76353
02 001* 09377
02 001* 92838
02 002* 09374
02 002* 09383
* in sequence by department number

Structured COBOL Programming, Stern &
Stern, 9th Edition
Multiple-Level Control Breaks
Sample Output
MONTHLY SALES REPORT PAGE 1 01/29/2001
DEPT-01
SALESPERSON NUMBER TOTAL AMT OF SALES
001 $889.89
002 $655.44
003 $763.53
TOTAL FOR DEPT - $2,308.86
Structured COBOL Programming, Stern &
Stern, 9th Edition
Multiple-Level Control Breaks
Sample Output
MONTHLY SALES REPORT PAGE 2 01/29/2001
DEPT-02
SALESPERSON NUMBER TOTAL AMT OF SALES
001 $1,022.15
002 $187.57
TOTAL FOR DEPT - $1,209.72
Structured COBOL Programming, Stern &
Stern, 9th Edition
Multiple-Level Control Breaks
Program Excerpt
100-MAIN-MODULE.
PERFORM 600-INITIALIZATION-RTN.
PERFORM 500-HEADING-RTN.
PERFORM 200-DETAIL-RTN
UNTIL NO-MORE-RECORDS.
PERFORM 400-DEPT-BREAK.
PERFORM 700-END-OF-JOB-RTN
STOP RUN.
Structured COBOL Programming, Stern &
Stern, 9th Edition
Multiple-Level Control Breaks
Program Excerpt
600-INITIALIZATION-RTN.
OPEN INPUT TRANS-FILE-IN
OUTPUT REPORT-FILE-OUT
ACCEPT WS-DATE FROM DATE . . .
READ TRANS-FILE-IN
AT END MOVE NO TO ARE-THERE-
MORE-RECORDS.
MOVE SLSNO-IN TO WS-HOLD-SLSNO
MOVE DEPT-IN TO WS-HOLD-DEPT
Structured COBOL Programming, Stern &
Stern, 9th Edition
Multiple-Level Control Breaks
Program Excerpt
No Detail printing required, no write needed:
200-DETAIL-RTN.
IF DEPT-IN NOT EQUAL WS-HOLD-DEPT
PERFORM 400-DEPT-BREAK
IF SLSNO-IN NOT EQUAL WS-HOLD-SLSNO
PERFORM 300-SLS-BREAK
ADD AMT-OF-TRANS-IN TO WS-SLS-TOTAL.
READ TRANS-FILE-IN
AT END MOVE NO TO ARE-THERE-MORE-
RECORDS.
Structured COBOL Programming, Stern &
Stern, 9th Edition
Multiple-Level Control Breaks
Program Excerpt
400-DEPT-BREAK.
PERFORM 300-SLS-BREAK
MOVE WS-DEPT-TOTAL TO DL-DEPT-
TOTAL
WRITE REPORT-REC-OUT FROM DL-
DEPT-LINE AFTER ADVANCING 2
LINES

Structured COBOL Programming, Stern &
Stern, 9th Edition
Multiple-Level Control Breaks
Program Excerpt
400-DEPT-BREAK. (continued)
IF MORE-RECORDS
MOVE ZEROS TO WS-DEPT-TOTAL
MOVE DEPT-IN TO WS-HOLD-DEPT
PERFORM 500-HEADING-RTN
Structured COBOL Programming, Stern &
Stern, 9th Edition
Multiple-Level Control Breaks
Program Excerpt
300-SLS-BREAK.
MOVE WS-SLS-TOTAL TO DL-SLS-TOTAL
MOVE WS-HOLD-SLSNO TO DL-SLSNO
WRITE REPORT-REC-OUT FROM DL-SLS-LINE
AFTER ADVANCING 2 LINES
ADD WS-SLS-TOTAL TO WS-DEPT-TOTAL
IF MORE-RECORDS
MOVE ZERO TO WS-SLS-TOTAL
MOVE SLSNO-IN TO WS-HOLD-SLSNO
Structured COBOL Programming, Stern &
Stern, 9th Edition
Forcing a Control Break When There
Are No More Records
700-END-OF-JOB-RTN.
MOVE WS-SLS-TOTAL TO DL-SLS-TOTAL
MOVE WS-DEPT-TOTAL TO DL-DEPT-TOTAL
WRITE REPORT-REC-OUT FROM DL-SLS-LINE
AFTER ADVANCING 2 LINES
WRITE REPORT-REC-OUT FROM DL-
DEPT-LINE
CLOSE TRANS-FILE-IN
REPORT-FILE-OUT.
Structured COBOL Programming, Stern &
Stern, 9th Edition
QUESTIONS?

You might also like