Control Breaks


Here in a pseudocode format are some examples of how you might structure programs using control breaks.

Single Level Control Break

           INITIALIZATION-PARAGRAPH.
               open the files.
               do the initial read.
               save the value of the break field.

           LOOP-PARAGRAPH.
               if value of break field has changed
                  perform the control break.
               (statements that process the current record)
               save the value of the break field.
               read the next record.

           END-OF-JOB-PARAGRAPH.
               perform the control break.
               close the files.

           CONTROL-BREAK-PARAGRAPH.
               write a subtotal line.
               reinitialize any counters or totals.

Alternative Single Level Control Break

           INITIALIZATION-PARAGRAPH.
               open the files.
               do the initial read.
               save the value of the break field.

           LOOP-PARAGRAPH.
               (statements that process the current record)
               read the next record.
               if the value of the break field has changed
                  or end-of-file
                     perform the control break.
               if not end-of-file
                  save the value of the break field.

           END-OF-JOB-PARAGRAPH.
               close the files.

           CONTROL-BREAK-PARAGRAPH.
               write a subtotal line.
               reinitialize any counters or totals.

Control Break with Page Break

           INITIALIZATION-PARAGRAPH.
               open the files.
               move 1 to the page number.
               print the headers.
               do the initial read.
               save the value of the break field.

           LOOP-PARAGRAPH.
               if value of break field has changed
                   perform the control break.
               if the detail line count > page break value
                   print the headers.
               (statements that process the current record)
               add 1 to the detail line count.
               save the value of the break field.
               read the next record.

           END-OF-JOB-PARAGRAPH.
               perform the control break.
               close the files.

           PRINT-THE-HEADERS.
               write the header lines.
               increment the page number.
               reset the detail line count back to zero

           CONTROL-BREAK-PARAGRAPH.
               write a subtotal line.
               increment line counter.
               reinitialize any counters or totals.

Cobol Home