CHAPTER 10
CONTROL BREAK
PROCESSING
CHAPTER OBJECTIVES
Upon
completion of this chapter, the student should be able to:
1. Distinguish between Detail Reports,
Exception Reports, and Summary Reports.
2. Define the term control field as it
relates to control break processing.
3. Describe the logic involved in
designing single-level and multiple-level control break programs.
LECTURE OUTLINE
I. An
Introduction to Control Break Processing
A. Types of Reports: A Systems Overview
1. Printed reports fall into three major
categories:
a. Detail or Transaction Reports contain
one or more lines of output for each input record read.
b. Exception Reports list individual
records that meet (or fail to meet) certain criteria.
c. Summary Reports produce summaries or
totals that provide a more comprehensive view for the user.
2. As a rule, either exception reports or
summary reports should be generated instead of detail reports if they can serve
the user’s purpose.
3. When output is required as responses to
inquiries and where printed copies are not needed, displayed output is often
used.
B. An Example of a Control Break Procedure
1. A control field is a key field used to
indicate when totals are to print.
2. All input records must be in sequence
by the control field.
3. Records are read and accumulated until
the value of the control field changes.
4. A change in the control field
"forces" the printing of the previous control field totals.
5. Totals are reset to zero and processing
continues.
II. Program Requirements for Control Break
Processing
A. A Single-Level Control Break
1. A single-level control break program
contains one control field which triggers the printing of totals.
2. Steps involved in a single-level
control break program:
a. For the first record read, move the control field to a hold area
in WORKING-STORAGE.
b. For each additional record, as long as
the control field is equal to the hold area, execute the detail routine for the
input record. This means: Add the appropriate amount to a control
total, and print the detail record if desired.
c. If the control field for a specific
record read is not equal to the hold area:
i. Print the control total.
ii. Initialize the control total field to
zero.
iii. Reinitialize the hold field with the
new control field value if ARE-THERE-MORE-RECORDS is not equal to ’NO ’.
iv. Process the detail record as in step b.
v. Print headings on a new page if each
control total is to appear on a separate page.
d. After all records have been processed,
perform a control break to print the last control group.
3. Refer to the text for a complete
example of a single-level control break.
B. Refinements to Improve the Quality of a
Control Break Report
1. Print a summary line that contains a
final total:
a. One method for calculating the final
total is to accumulate the contents of the input records as each record is
processed.
b. A second, more efficient method is to
accumulate the final total in the control break module by adding the control
total to the final total prior to reinitializing the control total.
2. Start a new page after each control
break for clarity and ease of distribution.
3. Sequence check or sort the input
records to be certain that the data is in the correct order.
4. Perform the control break module from
the main module after the end of the input file has been reached rather than
coding a separate module.
5. Refer to the text for a sample program
that incorporates these features.
C. Summary of a Single-Level Control Break
Procedure:
Review single-level
control break procedures described in this section of the text.
III.
Multiple-Level Control Breaks
1. There is a control field for each level
control break. Each control field will
require its own hold area in WORKING-STORAGE to enable the program to determine
when control breaks occur.
2. Input records must be in sequence by
control fields from major-level control fields to minor-level control fields.
3. Detail printing may or may not be
required. Instead, totals only may be
printed in the control break module.
4. The test for a major-level control
break must be done before that for a minor-level control break.
5. The major-level control routine must
begin by "forcing" a minor-level control break.
6. A program may contain as many control
fields as are necessary.
7. Refer to the text for a complete
double-level control break procedure.
SOLUTIONS TO REVIEW QUESTIONS
I. True-False Questions
1. F Sequence
checking can be eliminated if the data is sorted prior to
processing.
2. F It
is called a detail report or a transaction report.
3. T
4. T
5. F An
alphanumeric control field will work.
6. T
7. F One
can print the heading wherever it is appropriate for the particular
program. Sometimes the heading may need to contain
input data.
8. F Moves
to hold areas only occur as part of initialization routines or as a part of a control break.
9. T
10. F The
hold field should be reinitialized to the value contained in the
control field of the
current input record.
11. F Some
detail modules do not produce output.
That is, group printing alone may
be
sufficient.
12. T
13. T
14. T
15. F Any
number of levels of control breaks is permitted.
II. General Questions
1a. 100-MAIN-MODULE.
OPEN INPUT STUDENT-FILE
PERFORM UNTIL NO-MORE-RECORDS
READ STUDENT-FILE
AT END
MOVE 'NO ' TO
ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM
200-PROCESS-ONE-STUDENT
END-READ
END-PERFORM
PERFORM 400-TERMINATION
STOP RUN.
1b. 200-PROCESS-ONE-STUDENT.
EVALUATE TRUE
WHEN FIRST-RECORD = 'YES'
MOVE SCHOOL-SR TO SCHOOL-HOLD
MOVE 'NO ' TO FIRST-RECORD
WHEN SCHOOL-SR NOT = SCHOOL-HOLD
PERFORM 300-SCHOOL-BREAK
END-EVALUATE
ADD STUDENT-GPA-SR TO SCHOOL-TOTAL-GPA
ADD 1 TO SCHOOL-STUDENT-COUNTER.
1c. 300-SCHOOL-BREAK.
DIVIDE SCHOOL-TOTAL-GPA BY
SCHOOL-STUDENT-COUNTER
GIVING SCHOOL-AVERAGE-GPA ROUNDED
DISPLAY 'AVERAGE GPA FOR THE SCHOOL OF
'
SCHOOL-HOLD
' IS '
SCHOOL-AVERAGE-GPA
MOVE SCHOOL-SR TO SCHOOL-HOLD
MOVE 0 TO SCHOOL-TOTAL-GPA
SCHOOL-STUDENT-COUNTER.
1d. Modify module 300-SCHOOL-BREAK
to include code that adds school totals to the corresponding university totals:
300-SCHOOL-BREAK.
DIVIDE SCHOOL-TOTAL-GPA BY
SCHOOL-STUDENT-COUNTER
GIVING SCHOOL-AVERAGE-GPA ROUNDED
DISPLAY 'AVERAGE GPA FOR THE SCHOOL OF
'
SCHOOL-HOLD
' IS '
SCHOOL-AVERAGE-GPA
ADD SCHOOL-TOTAL-GPA TO
UNIVERSITY-TOTAL-GPA
MOVE SCHOOL-SR TO SCHOOL-HOLD
MOVE 0 TO SCHOOL-TOTAL-GPA
SCHOOL-STUDENT-COUNTER.
Add the following
termination module:
400-TERMINATION.
PERFORM 300-SCHOOL-BREAK
DIVIDE UNIVERSITY-TOTAL-GPA
BY UNIVERSITY-STUDENT-COUNTER
GIVING UNIVERSITY-AVERAGE-GPA
ROUNDED
DISPLAY ' '
DISPLAY 'AVERAGE GPA FOR THE
UNIVERSITY IS '
UNIVERSITY-AVERAGE-GPA
CLOSE STUDENT-FILE.
2. Answer b) is not true. The other answers are true.
3. Adding the control totals is more
efficient since there are fewer of them.
4. A conditional statement in an EVALUATE
or an IF.
5. Zero.
III. Internet/Critical Thinking Questions
The sample search shown here lists
several commonly-used report features as keywords. Search on them individually to locate web
sites which address the particular report items.
Search Engine: yahoo.com>Computers & Internet
Keywords: COBOL+printing
Contents: These searches primarily
locate two categories of sites:
-
University internet courses that include lessons on the report feature
-
Companies that market software which automates the printing of
reports
SOLUTIONS
TO DEBUGGING EXERCISES
1. No, the program is not logically correct.
a. In the 200-DETAIL-RTN, the total field
WS-TOTAL needs to be reinitialized to zero.
Also, the WS-HOLD-ACCT field must be reset with the value in ACCT-NO.
b. Another logic error is caused by the
combination of READs in modules 100-MAIN-MODULE and 300-ADD-IT-UP. The problem is that the first record in each
control group after the first is skipped over without being processed.
When the first record
of a new control group is read at the end of 300-ADD-IT-UP, the statements
after the PERFORM in module 200-DETAIL-RTN are executed, and then control is
returned to the PERFORM in module 100-MAIN-MODULE, where another record is
read.
2. No.
The last control total is printed in module 200-DETAIL-RTN prior to
returning to the main module.
3. MOVE 0 TO WS-TOTAL
MOVE ACCT-NO TO WS-HOLD-ACCT
4. Each time a control break occurred an
extra record would be read. The first
record of each control group would not be processed.
5. Yes.
A control break would occur when the first record was processed. This would result in the printing of totals
prior to having accumulated them.