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: 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:

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:

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:

	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:

PSEUDOCODE:

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: 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:

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:

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:

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:

	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:

PSEUDOCODE:

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: To accomplish this:

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.