Break Processing
Break processing means printing a total or totals for a group of records. The break is
traditionally caused by a change in the data. For example suppose that a file has been sorted
by department number and that every time the department number changes a total for that
department needs to be printed. This is break processing. Notice that I said that the file was
sorted on department number. This is critical! Files that are being used for break processing
must be sorted by the field or fields that will cause the break. In other words, if I am going
to break on department number, all the records in the file with the same department number must
be grouped together. When a record is read with a different department number, the programmer
can be sure that the previous department is finished and can print a total line for that
department. The reading of the record with the different department number triggered the break.
The breaks discussed in the previous paragraph were on department only. Frequently there are
multiple levels of breaks for example a company might have Divisions, which are comprised of
Branches, which are comprised of Departments. In this case totals must be printed when any or
all of the fields break. In this case, the lowest level, the Department is called a minor break,
the next level up, the Branch is called the intermediate break and the top level, the Division is
called the major break. The details of how this all works will be discussed.
Minor Breaks only:
In this discussion, we are going to assume that the records in the file have the following
layout and that the records have been sorted by department number.
1 - 4 Filler( later will contain Div # and Br #)
5 - 6 Dept #
7 -10 Item #
11-30 Item Name
31-33 On Hand
34-38 Price(999V99)
The report that we want to print will contain:
- the information from the record on the DETAIL LINE
- for each department, a MINOR TOTAL LINE with the totals for the department
- at the end of the report, a FINAL TOTAL LINE with the totals for all departments
Minor break processing involves doing the initializing read and moving the break number (in this
case department number) to a hold area that has been set up in working storage. Then the
processing routine starts the loop. In the loop, the program checks to see if there is a break,
in other words, if the department number has changed. This is done by comparing the department
number on the current record to the department number in the hold area. Obviously for the first
record they will be the same since the program just moved the number from the first record to
the hold area. Since they are the same the record will be processed. As part of the processing,
the minor accumulators will be added to - if you are accumulating a count of the number of
records in the department you would add 1 to a minor count accumulator. If you are accumulating
the contents of a field you would add the contents of the field to a minor total accumulator.
Once the record has been processed, it is written on the report and a new record is read. The
department number on the new record is compared to the department number in the hold area. If
they are the same, the record is processed. If they are not the same, this means that the
department has changed and it is time to write a minor total line for the department you have
just finished processing.
To do this control is passed to the minor routine where the minor total line is set up. If you
want to print the department number this involves moving the department number from the hold
area to a slot on the minor total line. Note that you must move the number from the hold area
not from the record that was just read since it contains the department number of the new
department that has not yet been processed. Also in the minor routine, you move the minor total
accumulators to the minor total line. Once the line has been setup. it is written. Then you
must reset the hold area by moving the new department number to it so that it will contain the
number of the department you are now starting to process and you must reset the minor total
accumulators to 0 so they will not contain numbers relating to the previous department. After
the minor total line has been written, the record that caused the break is processed.
This processing loop continues until end of file has been reached. At that time, the minor
total for the last department must be written so the minor total routine is processed one last
time. If there is a final total line, it too must be written, so the final total routine is now
processed.
Minor Break Logic - Checking for a break:
- Set-up a hold area in working storage to hold the department number of the department group
that is currently being processed - the hold area could be called HOLD-DEPT-WS
- When the first record is read with the initializing read, the department number on that
first record will be moved to the HOLD-DEPT-WS
- The next command should be the usual PERFORM B-200-LOOP until end of file has been reached
- At the beginning of the B-200-LOOP, the program should check and see if a break has happened
- this means compare the department number on the record to the department number in
HOLD-DEPT-WS
- if they are EQUAL, no break has occurred and the record should be processed (in this program
the record will be processed in a separate detail routine paragraph called B-300-DETAIL)
- if they are NOT EQUAL, a break has occurred and the minor total line for the department that
you have finished processing should be printed (this will happen in a minor routine paragraph -
in this program the minor routine paragraph is called B-310-MINOR-ROUT) before the record that
caused the break is processed (in the detail routine paragraph, B-300-DETAIL)
IF DEPT NOT = HOLD-DEPT-WS
PERFORM B-310-MINOR-ROUT.
PERFORM B-300-DETAIL.
- Note: The If is terminated after the PERFORM B-310-MINOR-ROUT command. This means that if
there was a break the minor routine will be performed as a result of the IF and if there was no
break, no special processing will be done. This means that the PERFORM B-300-DETAIL will be
done for all records. If a break happens the minor routine will be done before the detail
routine, if no break happened no special processing proceeds the execution of the detail
routine.
In the B-100-PROCESS, after all records on the file have been processed, the minor routine
is performed. This writes the minor total for the last group (in this case department) in the
file. If this is not done, there will be no minor total for the last group. Think about it.
The PERFORM B-200-LOOP is done until end of file has been reached. The thing that tells you end
of file has been reached is the read statement at the bottom of the B-200-LOOP. If end of file
has been reached then the B-200-LOOP will not be processed again which means that the IF
statement to check whether the minor total routine needs to be performed will not be executed
again. The only way to print out the last minor total is to PERFORM B-310-MINOR-ROUT one last
time after end of file has been reached. Note also that as soon as this last execution of the
minor routine is complete, the next instruction calls for B-320-FINAL-ROUT to be executed. This
will print the final total lines at the bottom of the report.
EXAMPLE:
B-100-PROCESS.
....
....
PERFORM B-200-LOOP
UNTIL MORE-RECS = "NO ".
PERFORM B-310-MINOR-ROUT.
PERFORM B-320-FINAL-ROUT.
Minor Break Logic - Processing in the Minor Routine:
The MINOR ROUTINE must accomplish the following:
- Set up the minor total line (this means moving accumulators and optionally the break
number, in our example that is the department number, to the minor total line - NOTE that when
you move the department number you should move the department number from the hold area,
the department number coming in on the input is for the new department, the department number in
the hold area is for the department you have just processed and are writing the total line for)
- Write the minor total line
- Reset for the next department
- move the department number on the record that was just read to the hold area
so you can now start to process the new department
- reset the minor total accumulators so the totals for the new department will
not include figures from the old department
- if you are keeping a line count, increment it
EXAMPLE:
B-310-MINOR-ROUT.
MOVE HOLD-DEPT-WS TO DEPT-ML.
MOVE MINOR-ON-HAND-ACC TO MINOR-ONHAND-ACC-ML.
MOVE MINOR-VALUE-ACC TO MINOR-VALUE-ACC-ML.
WRITE PRINTZ FROM MINOR-TOTAL-LINE
AFTER ADVANCING 2 LINES.
MOVE DEPT TO HOLD-DEPT-WS.
MOVE 0 TO MINOR-ONHAND-ACC.
MOVE 0 TO MINOR-VALUE-ACC.
ADD 2 TO LINE-CT.
NOTE: In this routine the department number was moved to the minor total line in the first
command. It was also reset after the line was written by moving the department number on the
input to the department hold area in working storage. Also, there are two accumulators so both
of them are moved to the line and both are reset to - after the line is written.
Minor Break Logic - Processing changes in the Detail Routine:
- The processing change in the Detail Routine is simply adding to the minor total accumulators
B-300-DETAIL.
.....
.....
ADD ON-HAND TO MINOR-ONHAND-ACC.
ADD INV-VALUE-WS TO MINOR-VALUE-ACC.
NOTE: Since there are two minor accumulators, there are two add statements, one for each.
PSEUDOCODE for minor break program:
An alternative to drawing a logic flowchart is to work out the logic using pseudocode -
pseudocode is essentially writing out what instructions you want to accomplish independent of
the language you are using.
Define in WORKING-STORAGE:
- hold area for the minor break field
- minor total accumulator(s) (also final total accumulators if you are writing a final total line)
- minor total line (also final total line if you are writing one)
PSEUDOCODE:
Mainline:
Perform initialize routine
Perform process routine
Perform wrapup/terminate routine
Stop run
Initialize Routine:
Open files
Housekeeping such as getting the date and moving to the header etc.
Process Routine:
Initializing read
Move minor break number to hold break number (in Working Storage)
Perform the processing loop until end of file
Perform the minor routine
Perform the final routine
Processing Loop:
If there is a minor break (break number on the input record does not equal break number in the
hold break number area in Working Storage)
Perform the minor routine
Perform the detail routine
Read the input record (if end of file, set the end of file indicator)
Detail Routine:
If program needs to write a header
Set up the detail line including moving information and doing any necessary calculations
Write the detail line
Add to the line count
If any additional calculations are needed to get the figures to add to the accumulators, execute
the calculations
Add to the minor accumulators
Add to the final accumulators
Minor Routine:
Set up the minor total line - move break number from hold area if needed and move the minor
accumulators to slots on the line
Write the minor total line
Add to the line count
Reset the hold area to contain the break number from the record that caused the break
Reset the minor accumulators to 0
Final Routine:
Set up the final total line - move the final accumulators to slots on the line
Write the final total line
Header Routine:
Set up the headers
Write the headers
Increment the page counter
Reset the line count
Wrapup/Terminate Routine
The pseudocode can now be used as a program outline to help you in writing the program. The
logic has been worked out independent of the language being used.
Minor, Intermediate and Major Breaks:
Minor, intermediate and major breaks are used when you have several levels of totals that you
want to print. For example, you want to total information by Division, Branch and then
Department. (Divisions are made up of branches and branches are made up of departments). To do
this, first the file needs to be sorted on division, and branch within division, and department
within branch so that all records will be grouped in a way appropriate to this multiple break
processing. The assumption here is that when the division changes or breaks the branch and
department have also changed. For example the West coast division is made up of branches in
Oregon and California and each of these branches has a series of departments. If the branch
changes from the Oregon branch to the California branch then the department has also changed
and if the division changes from the West coast division to the East coast division, the
branches and therefore the departments have also changed. If this scenario does not fit your
data, the logic described will not work.
In the example given, we are going to assume that the input records have the following layout
and that the file has been sorted by division, branch within division, and department within
branch.
1 - 2 Div #
3 - 4 Br #
5 - 6 Dept #
7 -10 Item #
11-30 Item Name
31-33 On Hand
34-38 Price(999V99)
The report that we want to print will contain:
- the information from the record on the DETAIL LINE
- for each department, a MINOR TOTAL LINE with the totals for the department
- for each branch, an INTERMEDIATE TOTAL LINE with the totals for the branch
- for each division, a MAJOR TOTAL LINE with the totals for the division
- at the end of the report, a FINAL TOTAL LINE with the totals for all departments
REMEMBER: MAJOR IS DIVISION, INTERMEDIATE IS BRANCH AND MINOR IS DEPARTMENT. The major,
intermediate and minor total break logic involves checking for each level of break starting
with the highest level. If the major/division breaks, then the logic assumes that all
levels broke since divisions are made up of branches which are made up of departments. So, if
the division breaks, the logic calls for the minor/department total line to be printed followed
by the intermediate/branch total line, followed by the major/division total line.(Notice that
we print from lower level to highest level because if you are looking at the report you would
want to see the department total first, then the branch total and the division total below that.)
This would be accomplished by performing first the minor total routine, then the intermediate
total routine and then the major total routine. If the division did not break, but the branch
did then the logic calls for the minor/department total line to be printed followed by the
intermediate/branch total. This will be accomplished by performing first the minor total
routine and then the intermediate total routine. If just the department breaks then only the
minor/department total line will be printed by performing the minor routine.
Minor, Intermediate, Major Break Logic - Checking for a break:
EXAMPLE:
B-100-PROCESS.
....
....
PERFORM B-200-LOOP
UNTIL MORE-RECS = "NO ".
PERFORM B-310-MINOR-ROUT.
PERFORM B-320-INTERMEDIATE-ROUT.
PERFORM B-330-MAJOR-ROUT.
PERFORM B-340-FINAL-ROUT.
Minor, Intermediate, Major Break Logic - Processing in the Minor, Intermediate, Major
Routines:
The MINOR ROUTINE must accomplish the following:
- Set up the minor total line
- Write the minor total line
- Reset for the next department
- move the department number on the record that was just read to the hold area
- reset the minor total accumulators
EXAMPLE:
B-310-MINOR-ROUT.
MOVE HOLD-DEPT TO DEPT-ML.
MOVE MINOR-ON-HAND-ACC TO MINOR-ONHAND-ACC-ML.
MOVE MINOR-VALUE-ACC TO MINOR-VALUE-ACC-ML.
WRITE PRINTZ FROM MINOR-TOTAL-LINE
AFTER ADVANCING 2 LINES.
MOVE DEPT TO HOLD-DEPT.
MOVE 0 TO MINOR-ONHAND-ACC.
MOVE 0 TO MINOR-VALUE-ACC.
ADD 2 TO LINE-CT.
The INTERMEDIATE ROUTINE must accomplish the following:
- Set up the intermediate total line
- Write the intermediate total line
- Reset for the next branch
- move the branch number on the record that was just read to the hold area
- reset the intermediate total accumulators
EXAMPLE:
B-320-INTERMEDIATE-ROUT.
MOVE HOLD-BRANCH TO BRANCH-IL.
MOVE INTER-ON-HAND-ACC TO INTER-ONHAND-ACC-IL.
MOVE INTER-VALUE-ACC TO INTER-VALUE-ACC-IL.
WRITE PRINTZ FROM INTERMEDIATE-TOTAL-LINE
AFTER ADVANCING 1 LINES.
MOVE BRANCH TO HOLD-BRANCH.
MOVE 0 TO INTER-ONHAND-ACC.
MOVE 0 TO INTER-VALUE-ACC.
ADD 1 TO LINE-CT.
The MAJOR ROUTINE must accomplish the following:
- Set up the major total line
- Write the major total line
- Reset for the next division
- move the division number on the record that was just read to the hold area
- reset the major total accumulators
EXAMPLE:
B-330-MAJOR-ROUT.
MOVE HOLD-DIV TO DIV-MJL.
MOVE MAJOR-ON-HAND-ACC TO MAJOR-ONHAND-ACC-MJL.
MOVE MAJOR-VALUE-ACC TO MAJOR-VALUE-ACC-MJL.
WRITE PRINTZ FROM MAJOR-TOTAL-LINE
AFTER ADVANCING 1 LINES.
MOVE DIV TO HOLD-DIV.
MOVE 0 TO MAJOR-ONHAND-ACC.
MOVE 0 TO MAJOR-VALUE-ACC.
ADD 1 TO LINE-CT.
Minor, Intermediate, Major Break Logic - Processing changes in the Detail Routine:
- The processing change in the Detail Routine is simply adding to the minor total
accumulators, the intermediate total accumulators and the major total accumulators.
B-300-DETAIL.
.....
.....
ADD ON-HAND TO MINOR-ONHAND-ACC.
ADD INV-VALUE-WS TO MINOR-VALUE-ACC.
ADD ON-HAND TO INTER-ONHAND-ACC.
ADD INV-VALUE-WS TO INTER-VALUE-ACC.
ADD ON-HAND TO MAJOR-ONHAND-ACC.
ADD INV-VALUE-WS TO MAJOR-VALUE-ACC.
ADD ON-HAND TO FINAL-ONHAND-ACC.
ADD INV-VALUE-WS TO FINAL-VALUE-ACC.
Since there are two accumulators at each level, there are two add statements for each level -
minor, intermediate, and major. Note this code also includes the add to the final total
accumulators.
PSEUDOCODE for minor, intermediate and major break program:
Define in WORKING-STORAGE:
- hold area for the minor break field, intermediate break field, major break field
- minor total accumulator(s), intermediate total accumulator(s), major total accumulator(s)
(also final total accumulators if you are writing a final total line)
- minor total line, intermediate total line, major total line (also final total line if
you are writing one)
PSEUDOCODE:
Mainline:
Perform initialize routine
Perform process routine
Perform wrapup/terminate routine
Stop run
Initialize Routine:
Open files
Housekeeping such as getting the date and moving to the header etc.
Process Routine:
Initializing read
Move minor break number to hold minor break number (in Working Storage)
Move intermediate break number to hold intermediate break number
Move major break number to hold major break number
Perform the processing loop until end of file
Perform the minor routine
Perform the intermediate routine
Perform the major routine
Perform the final routine
Processing Loop:
If there is a major break (major break number on the input record does not equal major break
number in the hold area)
Perform the minor routine
Perform the intermediate routine
Perform the major routine
else
If there is an intermediate break (intermediate break number on the input record does not
equal intermediate break number in the hold area)
Perform minor routine
Perform intermediate routine
else
If there is a minor break (minor break number on the input record does not equal minor break
number in the hold area)
Perform the minor routine
endif
endif
endif
Perform the detail routine
Read the input record (if end of file, set the end of file indicator)
Detail Routine:
If program needs to write a header
Set up the detail line including moving information and doing any necessary calculations
Write the detail line
Add to the line count
If any additional calculations are needed to get the figures to add to the accumulators, execute
the calculations
Add to the minor accumulators
Add to the intermediate accumulators
Add to the major accumulators
Add to the final accumulators
Minor Routine:
Set up the minor total line - move minor break number from hold area if needed and move the
minor accumulators to slots on the line
Write the minor total line
Add to the line count
Reset the minor hold area to contain the minor break number from the record that caused the
break
Reset the minor accumulators to 0
Intermediate Routine:
Set up the intermediate total line - move intermediate break number from hold area if needed and
move the intermediate accumulators to slots on the line
Write the intermediate total line
Add to the line count
Reset the intermediate hold area to contain the intermediate break number from the record that
caused the break
Reset the intermediate accumulators to 0
Major Routine:
Set up the major total line - move major break number from hold area if needed and move the
major accumulators to slots on the line
Write the major total line
Add to the line count
Reset the major hold area to contain the major break number from the record that caused the
break
Reset the major accumulators to 0
Final Routine:
Set up the final total line - move the final accumulators to slots on the line
Write the final total line
Header Routine:
Set up the headers
Write the headers
Increment the page counter
Reset the line count
Wrapup/terminate routine:
Group Indicating:
Group indicating means that you do not want the division number, branch number and department
number to appear on every detail line. Instead you only want them to appear when they have
changed. In other words, after a break in division, the division number has changed and you
want it to appear on the next detail line. The same with branch and department, after they have
broken they have changed so you want them to appear on the next detail line. There is one other
time you want the division number, branch number and department number to appear and that is on
the first line of a new page.
To do this we set up three indicators in working storage: In the sample program, I called them
DIV-BREAK-IND, BR-BREAK-IND, and DEPT-BREAK-IND. If the DIV-BREAK-IND was on, then it was time
to print division, branch and dept on the detail line. If the BR-BREAK-IND was on, then it was
time to print branch and dept on the detail line. If DEPT-BREAK-IND was on, then it was time to
print dept on the detail line.
There are two times that I want to print these control numbers on the detail line:
- The first line of a new page
- The first detail line after a break
To accomplish this:
- Set up the DIV-BREAK-IND, BR-BREAK-IND and DEPT-BREAK-IND in Working Storage with an initial
value of NO
- After you come back from performing the page header routine set the DIV-BREAK-IND equal to
YES so that the division, branch and dept will print on the next line
- If there is a division break - after performing the routines to print the totals, set the
DIV-BREAK-IND to YES
- If there is a branch break - after performing the routines to print the totals, set the
BR-BREAK-IND to YES
- If there is a dept break - after performing the routines to print the totals, set the
DEPT-BREAK-IND to YES
- In the Detail Routine, if the DIV-BREAK-IND is YES, move the division, branch and department
to the detail line and then set the DIV-BREAK-IND to NO - else if the BR-BREAK-IND is YES move
the branch and department to the detail line and set the BR-BREAK-IND to NO - else if the
DEPT-BREAK-IND is YES move the department to the detail line and set the DEPT-BREAK-IND to NO -
the reset to NO is necessary so that the next record will be printed without the control
numbers, if the indicator stayed set at YES then all lines following would have the control
numbers printed on them
Group Printing:
Group printing simply means printing total lines. Therefore you remove all things that cause
the detail line to print including the set up of the detail line, the moves to the detail line
and most importantly the WRITING of the detail line. You probably also want to adjust the
headers, maybe the information on the total lines etc. to make the report more meaningful - note
that in my sample I only did the minimum adjusting.