IDENTIFICATION DIVISION.
       PROGRAM-ID. MAJBREAK.
       AUTHOR. GROCER.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       SELECT INPUT-FILE
           ASSIGN TO "C:\PCOBWIN\CIS12FST\MAJOR.DAT".
       SELECT PRINT-FILE
           ASSIGN TO PRINTER.
       DATA DIVISION.
       FILE SECTION.
       FD  INPUT-FILE
           DATA RECORD IS INPUT-REC.
       01  INPUT-REC.
           05  DIV             PIC XX.
           05  BRANCH          PIC XX.
           05  DEPT            PIC XX.
           05  ITEM-NO         PIC 9(4).
           05  ITEM-NAME       PIC X(20).
           05  ON-HAND         PIC 9(3).
           05  PRICE           PIC 9(3)V99.
       FD  PRINT-FILE
           DATA RECORD IS PRINTZ.
       01  PRINTZ.
           05  FILLER          PIC X.
           05  DIV-PR          PIC XX.
           05  FILLER          PIC XXX.
           05  BRANCH-PR       PIC XX.
           05  FILLER          PIC XXX.
           05  DEPT-PR         PIC XX.
           05  FILLER          PIC XXX.
           05  ITEM-NO-PR      PIC 9(4).
           05  FILLER          PIC X(5).
           05  ITEM-NAME-PR    PIC X(20).
           05  FILLER          PIC X(5).
           05  ON-HAND-PR      PIC ZZ9.
           05  FILLER          PIC X(4).
           05  PRICE-PR        PIC $$$9.99.
           05  FILLER          PIC X(5).
           05  INV-VALUE-PR    PIC $$$,$$9.99.
           05  FILLER          PIC X.
       WORKING-STORAGE SECTION.
       01  PROGRAM-INDICATORS.
           05  MORE-RECS                PIC XXX      VALUE "YES".
       01  HOLD-AREAS.
           05  HOLD-DIV                 PIC XX       VALUE SPACES.
           05  HOLD-BRANCH              PIC XX       VALUE SPACES.
           05  HOLD-DEPT                PIC XX       VALUE SPACES.
       01  WORK-AREAS.
           05  INV-VALUE-WS             PIC 9(5)V99  VALUE 0.
       01  ACCUMULATORS.
           05  MINOR-ONHAND-ACC         PIC 9(4)     VALUE 0.
           05  INTER-ONHAND-ACC         PIC 9(5)     VALUE 0.
           05  MAJOR-ONHAND-ACC         PIC 9(6)     VALUE 0.
           05  FINAL-ONHAND-ACC         PIC 9(7)     VALUE 0.
           05  MINOR-VALUE-ACC          PIC 9(6)V99  VALUE 0.
           05  INTER-VALUE-ACC          PIC 9(7)V99  VALUE 0.
           05  MAJOR-VALUE-ACC          PIC 9(8)V99  VALUE 0.
           05  FINAL-VALUE-ACC          PIC 9(9)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-ONHAND-ACC-ML PIC Z,ZZ9.
           05  FILLER              PIC X(15) VALUE SPACES.
           05  MINOR-VALUE-ACC-ML  PIC $$$$,$$9.99.
           05  FILLER              PIC X     VALUE SPACES.
       01  INTER-TOTAL-LINE.
           05  FILLER              PIC X(20) VALUE SPACES.
           05  FILLER              PIC X(19)
                                       VALUE "TOTALS FOR BRANCH: ".
           05  BRANCH-IL           PIC 99    VALUE 0.
           05  FILLER              PIC X(6)  VALUE SPACES.
           05  INTER-ONHAND-ACC-IL PIC ZZ,ZZ9.
           05  FILLER              PIC X(13) VALUE SPACES.
           05  INTER-VALUE-ACC-IL  PIC $$,$$$,$$9.99.
           05  FILLER              PIC X     VALUE SPACES.
       01  MAJOR-TOTAL-LINE.
           05  FILLER               PIC X(20) VALUE SPACES.
           05  FILLER               PIC X(21)
                                        VALUE "TOTALS FOR DIVISION: ".
           05  DIV-MJL              PIC 99    VALUE 0.
           05  FILLER               PIC X(3) VALUE SPACES.
           05  MAJOR-ONHAND-ACC-MJL PIC ZZZ,ZZ9.
           05  FILLER               PIC X(12) VALUE SPACES.
           05  MAJOR-VALUE-ACC-MJL  PIC $$$,$$$,$$9.99.
           05  FILLER               PIC X     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(11) VALUE SPACES.
           05  FINAL-ONHAND-ACC-FL PIC Z,ZZZ,ZZ9.
           05  FILLER              PIC X(11) VALUE SPACES.
           05  FINAL-VALUE-ACC-FL  PIC $$$$,$$$,$$9.99.
           05  FILLER              PIC X     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(22) VALUE SPACES.
           05  FILLER              PIC X(16) VALUE "INVENTORY 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(5)  VALUE SPACES.
       01  COLUMN-HDR.
           05  FILLER              PIC X     VALUE SPACES.
           05  FILLER              PIC XXX   VALUE "DIV".
           05  FILLER              PIC XX    VALUE SPACES.
           05  FILLER              PIC XX    VALUE "BR".
           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 "ITEM #".
           05  FILLER              PIC X(3)  VALUE SPACES.
           05  FILLER              PIC X(9)  VALUE "ITEM NAME".
           05  FILLER              PIC X(13) VALUE SPACES.
           05  FILLER              PIC X(7)  VALUE "ON HAND".
           05  FILLER              PIC X(4)  VALUE SPACES.
           05  FILLER              PIC X(7)  VALUE "PRICE".
           05  FILLER              PIC X(3)  VALUE SPACES.
           05  FILLER              PIC X(11) VALUE "INVEN VALUE".
           05  FILLER              PIC X     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.
           MOVE DIV TO HOLD-DIV.
           MOVE BRANCH TO HOLD-BRANCH.
           MOVE DEPT TO HOLD-DEPT.
           PERFORM B-200-LOOP
               UNTIL MORE-RECS = "NO ".
           PERFORM B-310-MINOR-ROUT.
           PERFORM B-320-INTER-ROUT.
           PERFORM B-330-MAJOR-ROUT.
           PERFORM B-340-FINAL-ROUT.
       B-200-LOOP.
           IF DIV NOT = HOLD-DIV
               PERFORM B-310-MINOR-ROUT
               PERFORM B-320-INTER-ROUT
               PERFORM B-330-MAJOR-ROUT
               PERFORM U-000-BLANK-LINE
           ELSE
               IF BRANCH NOT = HOLD-BRANCH
                   PERFORM B-310-MINOR-ROUT
                   PERFORM B-320-INTER-ROUT
                   PERFORM U-000-BLANK-LINE
               ELSE
                   IF DEPT NOT = HOLD-DEPT
                       PERFORM B-310-MINOR-ROUT
                       PERFORM U-000-BLANK-LINE.
           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 DIV TO DIV-PR.
           MOVE BRANCH TO BRANCH-PR.
           MOVE DEPT TO DEPT-PR.
           MOVE ITEM-NO TO ITEM-NO-PR.
           MOVE ITEM-NAME TO ITEM-NAME-PR.
           MOVE ON-HAND TO ON-HAND-PR.
           MOVE PRICE TO PRICE-PR.
           MULTIPLY ON-HAND BY PRICE
               GIVING INV-VALUE-WS.
           MOVE INV-VALUE-WS TO INV-VALUE-PR.
           WRITE PRINTZ
               AFTER ADVANCING 1 LINES.
           ADD 1 TO LINE-CT.
           ADD ON-HAND TO MINOR-ONHAND-ACC.
           ADD ON-HAND TO INTER-ONHAND-ACC.
           ADD ON-HAND TO MAJOR-ONHAND-ACC
           ADD ON-HAND TO FINAL-ONHAND-ACC.
           ADD INV-VALUE-WS TO MINOR-VALUE-ACC.
           ADD INV-VALUE-WS TO INTER-VALUE-ACC.
           ADD INV-VALUE-WS TO MAJOR-VALUE-ACC.
           ADD INV-VALUE-WS TO FINAL-VALUE-ACC.
       B-310-MINOR-ROUT.
           MOVE HOLD-DEPT TO DEPT-ML.
           MOVE MINOR-ONHAND-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.
       B-320-INTER-ROUT.
           MOVE HOLD-BRANCH TO BRANCH-IL.
           MOVE INTER-ONHAND-ACC TO INTER-ONHAND-ACC-IL.
           MOVE INTER-VALUE-ACC TO INTER-VALUE-ACC-IL.
           WRITE PRINTZ FROM INTER-TOTAL-LINE
               AFTER ADVANCING 1 LINES.
           MOVE SPACES TO PRINTZ.
           MOVE BRANCH TO HOLD-BRANCH.
           MOVE 0 TO INTER-ONHAND-ACC.
           MOVE 0 TO INTER-VALUE-ACC.
           ADD 1 TO LINE-CT.
       B-330-MAJOR-ROUT.
           MOVE HOLD-DIV TO DIV-MJL.
           MOVE MAJOR-ONHAND-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.
       B-340-FINAL-ROUT.
           MOVE FINAL-ONHAND-ACC TO FINAL-ONHAND-ACC-FL.
           MOVE FINAL-VALUE-ACC TO FINAL-VALUE-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.
      *
      *Input data:
      *
      *0110121234HOE                 01201899
      *0110121235RAKE                02501595
      *0110151111TROWEL              02000599
      *0110151112HAND HOE            01400799
      *0120171000LILY                05000199
      *0120171001TULIP               07500299
      *0121223000PANSY               11200599
      *0121223001PETUNIA             10000499
      *0230245555DOGWOOD             01010099
      *0230245556CHERRY              01012000
      *0240276789WHITE PINE          00513500
      *0240276790BLACK PINE          01020000
      *0250553456MAPLE               00807500
      *0250553457OAK                 00909900
      *
      *Output data:
      *
      *   04/11/99                      INVENTORY REPORT                    PAGE  1
      *
      * DIV  BR   DEPT ITEM #   ITEM NAME             ON HAND    PRICE     INVEN VALUE
      *
      * 01   10   12   1234     HOE                       12     $18.99        $227.88
      * 01   10   12   1235     RAKE                      25     $15.95        $398.75
      *
      *                    TOTALS FOR DEPT: 12            37                   $626.63
      *
      * 01   10   15   1111     TROWEL                    20      $5.99        $119.80
      * 01   10   15   1112     HAND HOE                  14      $7.99        $111.86
      *
      *                    TOTALS FOR DEPT: 15            34                   $231.66
      *                    TOTALS FOR BRANCH: 10          71                   $858.29
      *
      * 01   20   17   1000     LILY                      50      $1.99         $99.50
      * 01   20   17   1001     TULIP                     75      $2.99        $224.25
      *
      *                    TOTALS FOR DEPT: 17           125                   $323.75
      *                    TOTALS FOR BRANCH: 20         125                   $323.75
      *
      * 01   21   22   3000     PANSY                    112      $5.99        $670.88
      * 01   21   22   3001     PETUNIA                  100      $4.99        $499.00
      *
      *                    TOTALS FOR DEPT: 22           212                 $1,169.88
      *                    TOTALS FOR BRANCH: 21         212                 $1,169.88
      *                    TOTALS FOR DIVISION: 01       408                 $2,351.92
      *
      * 02   30   24   5555     DOGWOOD                   10    $100.99      $1,009.90
      * 02   30   24   5556     CHERRY                    10    $120.00      $1,200.00
      *
      *                    TOTALS FOR DEPT: 24            20                 $2,209.90
      *                    TOTALS FOR BRANCH: 30          20                 $2,209.90
      *
      * 02   40   27   6789     WHITE PINE                 5    $135.00        $675.00
      * 02   40   27   6790     BLACK PINE                10    $200.00      $2,000.00
      *
      *                    TOTALS FOR DEPT: 27            15                 $2,675.00
      *                    TOTALS FOR BRANCH: 40          15                 $2,675.00
      *
      * 02   50   55   3456     MAPLE                      8     $75.00        $600.00
      * 02   50   55   3457     OAK                        9     $99.00        $891.00
      *
      *                    TOTALS FOR DEPT: 55            17                 $1,491.00
      *                    TOTALS FOR BRANCH: 50          17                 $1,491.00
      *                    TOTALS FOR DIVISION: 02        52                 $6,375.90
      *                    FINAL TOTAL:                  460                 $8,727.82
      *