IDENTIFICATION DIVISION.
       PROGRAM-ID. MAJBREAK.
       AUTHOR. GROCER.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       SELECT INPUT-FILE
           ASSIGN TO "A:\BREAK00.DAT".
       SELECT PRINT-FILE
           ASSIGN TO "A:\breakout.dat".
       DATA DIVISION.
       FILE SECTION.
       FD  INPUT-FILE
	   DATA RECORD IS INPUT-REC.
       01  INPUT-REC.
           05  COMPANY         PIC XX.
           05  REGION          PIC XX.
           05  DEPT            PIC XX.
           05  EMP-NO          PIC 9(4).
           05  EMP-NAME        PIC X(20).
           05  PAY             PIC 9(4)V99.
           05  BONUS           PIC 9(3)V99.
       FD  PRINT-FILE
	   DATA RECORD IS PRINTZ.
       01  PRINTZ.
	   05  FILLER	       PIC X.
           05  COMPANY-PR      PIC XX.
	   05  FILLER	       PIC XXX.
           05  REGION-PR       PIC XX.
	   05  FILLER	       PIC XXX.
           05  DEPT-PR         PIC XX.
	   05  FILLER	       PIC XXX.
           05  EMP-NO-PR       PIC 9(4).
	   05  FILLER	       PIC X(5).
           05  EMP-NAME-PR     PIC X(20).
	   05  FILLER	       PIC X(5).
           05  PAY-PR          PIC $$,$$$.99.
           05  FILLER          PIC X(6).
           05  BONUS-PR        PIC $$$$.99.
           05  FILLER          PIC X(8).
       WORKING-STORAGE SECTION.
       01  PROGRAM-INDICATORS.
           05  MORE-RECS                PIC XXX      VALUE "YES".
       01  HOLD-AREAS.
           05  HOLD-COMPANY             PIC XX       VALUE SPACES.
           05  HOLD-REGION              PIC XX       VALUE SPACES.
           05  HOLD-DEPT                PIC XX       VALUE SPACES.
       01  ACCUMULATORS.
           05  FINAL-PAY-ACC         PIC 9(8)V99  VALUE 0.
           05  FINAL-BONUS-ACC       pIC 9(7)V99  VALUE 0.
       01  PAGE-CONTROL.
	   05  PAGE-NO	       PIC 99	 VALUE 1.
	   05  LINE-CT	       PIC 99	 VALUE 0.
       01  DATE-WS.
	   05  YR-WS	       PIC 99	 VALUE 0.
	   05  MO-WS	       PIC 99	 VALUE 0.
	   05  DA-WS	       PIC 99	 VALUE 0.
       01  MINOR-TOTAL-LINE.
           05  FILLER              PIC X(20) VALUE SPACES.
           05  FILLER              PIC X(17) VALUE "TOTALS FOR DEPT: ".
           05  DEPT-ML             PIC 99    VALUE 0.
           05  FILLER              PIC X(9) VALUE SPACES.
           05  MINOR-PAY-ACC-ML    PIC $$$$,$$$.99.
           05  FILLER              PIC X(4)  VALUE SPACES.
           05  MINOR-BONUS-ACC-ML  PIC $$,$$$.99.
           05  FILLER              PIC X(8)  VALUE SPACES.
       01  INTER-TOTAL-LINE.
           05  FILLER              PIC X(20) VALUE SPACES.
           05  FILLER              PIC X(19)
                                       VALUE "TOTALS FOR REGION: ".
           05  REGION-IL           PIC 99    VALUE 0.
           05  FILLER              PIC X(7)  VALUE SPACES.
           05  INTER-PAY-ACC-IL    PIC $$$$,$$$.99.
           05  FILLER              PIC X(3)  VALUE SPACES.
           05  INTER-BONUS-ACC-IL  PIC $$$,$$$.99.
           05  FILLER              PIC X(8)  VALUE SPACES.
       01  MAJOR-TOTAL-LINE.
           05  FILLER               PIC X(20) VALUE SPACES.
           05  FILLER               PIC X(21)
                                        VALUE "TOTALS FOR COMPANY: ".
           05  COMPANY-MJL              PIC 99    VALUE 0.
           05  FILLER               PIC X(3)  VALUE SPACES.
           05  MAJOR-PAY-ACC-MJL    PIC $$,$$$,$$$.99.
           05  FILLER               PIC X(2)  VALUE SPACES.
           05  MAJOR-BONUS-ACC-MJL  PIC $$$$,$$$.99.
           05  FILLER               PIC X(8)  VALUE SPACES.
       01  FINAL-TOTAL-LINE.
           05  FILLER              PIC X(20) VALUE SPACES.
           05  FILLER              PIC X(13) VALUE "FINAL TOTAL: ".
           05  FILLER              PIC X(12) VALUE SPACES.
           05  FINAL-PAY-ACC-FL    PIC $$$,$$$,$$$.99.
           05  FILLER              PIC X(1)  VALUE SPACES.
           05  FINAL-BONUS-ACC-FL  PIC $$$$$,$$$.99.
           05  FILLER              PIC X(8)  VALUE SPACES.
       01  PAGE-HDR.
           05  FILLER              PIC XX    VALUE SPACES.
	   05  DATE-HDR.
               10  MO-HDR          PIC 99.
               10  FILLER          PIC X     VALUE "/".
               10  DA-HDR          PIC 99.
               10  FILLER          PIC X     VALUE "/".
               10  YR-HDR          PIC 99.
           05  FILLER              PIC X(20) VALUE SPACES.
           05  FILLER              PIC X(21)
                         VALUE "WEEKLY PAYROLL REPORT".
           05  FILLER              PIC X(20) VALUE SPACES.
           05  FILLER              PIC X(5)  VALUE "PAGE ".
           05  PAGE-NO-HDR         PIC Z9.
           05  FILLER              PIC X(2)  VALUE SPACES.
       01  COLUMN-HDR.
           05  FILLER              PIC X     VALUE SPACES.
           05  FILLER              PIC XX    VALUE "CO".
           05  FILLER              PIC XXX   VALUE SPACES.
           05  FILLER              PIC XX    VALUE "RG".
           05  FILLER              PIC XXX   VALUE SPACES.
           05  FILLER              PIC X(4)  VALUE "DEPT".
           05  FILLER              PIC X     VALUE SPACES.
           05  FILLER              PIC X(6)  VALUE "ID #".
           05  FILLER              PIC X(3)  VALUE SPACES.
           05  FILLER              PIC X(9)  VALUE "EMP NAME".
           05  FILLER              PIC X(17) VALUE SPACES.
           05  FILLER              PIC X(8)  VALUE "WEEK PAY".
           05  FILLER              PIC X(8)  VALUE SPACES.
           05  FILLER              PIC X(5)  VALUE "BONUS".
           05  FILLER              PIC X(3)  VALUE SPACES.
           05  FILLER              PIC X(5)  VALUE SPACES.
       PROCEDURE DIVISION.
       MAINLINE.
           PERFORM A-100-INITIALIZE.
           PERFORM B-100-PROCESS.
           PERFORM C-100-WRAPUP.
           STOP RUN.
       A-100-INITIALIZE.
	   OPEN INPUT INPUT-FILE
                OUTPUT PRINT-FILE.
	   ACCEPT DATE-WS FROM DATE.
	   MOVE MO-WS TO MO-HDR.
	   MOVE DA-WS TO DA-HDR.
	   MOVE YR-WS TO YR-HDR.
       B-100-PROCESS.
	   READ INPUT-FILE
	       AT END
		   MOVE "NO " TO MORE-RECS.
           PERFORM B-200-LOOP
	       UNTIL MORE-RECS = "NO ".
           PERFORM B-340-FINAL-ROUT.
       B-200-LOOP.
           PERFORM B-300-DETAIL.
	   READ INPUT-FILE
	       AT END
		   MOVE "NO " TO MORE-RECS.
       B-300-DETAIL.
           IF LINE-CT > 50 OR PAGE-NO = 1
               PERFORM B-400-HDR-ROUT.
	   MOVE SPACES TO PRINTZ.
           MOVE COMPANY TO COMPANY-PR.
           MOVE REGION TO REGION-PR.
	   MOVE DEPT TO DEPT-PR.
           MOVE EMP-NO TO EMP-NO-PR.
           MOVE EMP-NAME TO EMP-NAME-PR.
           MOVE PAY TO PAY-PR.
           MOVE BONUS TO BONUS-PR.
	   WRITE PRINTZ
	       AFTER ADVANCING 1 LINES.
	   ADD 1 TO LINE-CT.
           ADD PAY TO FINAL-PAY-ACC.
           ADD BONUS TO FINAL-BONUS-ACC.
       B-340-FINAL-ROUT.
           MOVE FINAL-PAY-ACC TO FINAL-PAY-ACC-FL.
           MOVE FINAL-BONUS-ACC TO FINAL-BONUS-ACC-FL.
	   WRITE PRINTZ FROM FINAL-TOTAL-LINE
	       AFTER ADVANCING 1 LINES.
       B-400-HDR-ROUT.
	   MOVE PAGE-NO TO PAGE-NO-HDR.
	   WRITE PRINTZ FROM PAGE-HDR
	       AFTER ADVANCING PAGE.
	   WRITE PRINTZ FROM COLUMN-HDR
	       AFTER ADVANCING 2 LINES.
           PERFORM U-000-BLANK-LINE.
	   ADD 1 TO PAGE-NO.
           MOVE 4 TO LINE-CT.
       U-000-BLANK-LINE.
	   MOVE SPACES TO PRINTZ.
	   WRITE PRINTZ
               AFTER ADVANCING 1 LINES.
           ADD 1 TO LINE-CT.
       C-100-WRAPUP.
	   CLOSE INPUT-FILE
                 PRINT-FILE.