0010   IDENTIFICATION DIVISION.
       PROGRAM-ID. Search1.
       ENVIRONMENT DIVISION.
0020   INPUT-OUTPUT SECTION.
0030   FILE-CONTROL.
0040       SELECT ORDERS-SUBMITTED   ASSIGN TO "ORDFILE1.DAT"
                                     LINE SEQUENTIAL.
0050  *    SELECT COMPANY-ORDERS     ASSIGN TO ORDRPRT.
0060       SELECT ORDER-SUMMARY      ASSIGN TO "ORDSUMM.DAT".
0070   FILE SECTION.
0080   FD  ORDERS-SUBMITTED
0090       LABEL RECORDS STANDARD.
0100   01  ORDER-RECORD.
0110       05  ORD-COMPANY          PIC X(10).
0120       05  ORD-ITEM-CODE        PIC X(10).
0130       05  ORD-ITEM-NAME        PIC X(30).
0140       05  ORD-ITEM-COUNT       PIC 9(5).
0150       05  ORD-ITEM-RATE        PIC 9(6)V99.
0160       05  ORD-ITEM-DATE        PIC X(8).
0170       05  ORD-RECIPIENT        PIC 9(5).
0180       05  FILLER               PIC XXXX.

0190  *FD  COMPANY-ORDERS.
0200   FD  ORDER-SUMMARY
0210        LABEL RECORDS STANDARD.
0220   01  ORDER-SUMMARY-LINE       PIC X(132).
0230
0240   WORKING-STORAGE SECTION.
0250   01  INPUT-EOF-CONTROL           PIC XXX VALUE 'NO '.
0260     88  END-OF-INPUT                      VALUE 'YES'.
0270
0280   01  COMPUTER-DATE.
0290       05  THIS-YEAR               PIC 9999.
0300       05  THIS-MONTH              PIC 99.
0310       05  THIS-DAY                PIC XX.
0320       05  FILLER                  PIC X(13).
0330
0340   01  MONTH-LIST.
0350       05  FILLER PIC X(30) VALUE 'January   February  March'.
0360       05  FILLER PIC X(30) VALUE 'April     May       June'.
0370       05  FILLER PIC X(30) VALUE 'July      August    September'.
0380       05  FILLER PIC X(30) VALUE 'October   November  December'.
0390   01  MONTH-TABLE REDEFINES MONTH-LIST.
0400       05  MONTH-NAME OCCURS 12 TIMES PIC X(10).
0410
0420   01  ORG-SUB                     PIC 99      COMP.
0421   01  TOTAL-COUNT                 PIC 9(5)    COMP VALUE ZERO.
0422   01  TOTAL-AMOUNT                PIC 9(8)V99 COMP VALUE ZERO.
0430   01  DIVISION-NAME-LIST.
0440       05  FILLER PIC X(30) VALUE 'FIRST SHIFT ASSEMBLY LINE'.
0450       05  FILLER PIC X(30) VALUE 'SECOND SHIFT ASSEMBLY LINE'.
0460       05  FILLER PIC X(30) VALUE 'EAST REGION SALES OFFICE'.
0470       05  FILLER PIC X(30) VALUE 'WEST REGION SALES OFFICE'.
0480       05  FILLER PIC X(30) VALUE 'TECHNICAL SUPPORT DIVISION'.
0490       05  FILLER PIC X(30) VALUE 'ADMINISTRATIVE DIVISION'.
0500       05  FILLER PIC X(30) VALUE 'MANAGEMENT STAFF'.
0510   01  DIVISION-NAME-TABLE REDEFINES DIVISION-NAME-LIST.
0520       05  DIVISION-NAME OCCURS 7 TIMES PIC X(30).
0530   01  DIVISION-TOTALS-TABLE.
0540       05  DIVISION-TOTAL-ENTRY OCCURS 7 TIMES.
0550          10  DIVISION-COUNT      PIC 9(5)    COMP.
0560          10  DIVISION-AMOUNT     PIC 9(8)V99 COMP.
0570
0580  *01  COMPANY-ORDER-DEFINITIONS.
0590
0600   01  SUMMARY-TITLE.
0610       05  FILLER                  PIC X(20) VALUE SPACES.
0620       05  FILLER                  PIC X(38) VALUE
0630           'COMPANY ORDER SUMMARY BY DIVISION FOR '.
0640       05  SUM-TITLE-DATE          PIC X(16) VALUE SPACES.
0650   01  SUMMARY-HEADING.
0660       05  FILLER                  PIC X(50) VALUE
0670           '                    ORGANIZATION NAME'.
0680       05  FILLER                  PIC X(10) VALUE ' COUNT'.
0690       05  FILLER                  PIC X(13) VALUE '       AMOUNT'.
0700   01  SUMMARY-DETAIL.
0710       05  FILLER                  PIC X(20) VALUE SPACE.
0720       05  SUM-DTL-NAME            PIC X(30).
0730       05  FILLER                  PIC X(5)  VALUE SPACES.
0740       05  SUM-DTL-COUNT           PIC ZZ,ZZ9.
0750       05  FILLER                  PIC X(5)  VALUE SPACES.
0760       05  SUM-DTL-AMOUNT          PIC ZZ,ZZZ,ZZ9.99.
0770
0780   PROCEDURE DIVISION.
0790
0800   0100-MAIN-CONTROL.
0810       MOVE FUNCTION CURRENT-DATE TO COMPUTER-DATE.
0810       SUBTRACT 1 FROM THIS-MONTH.
0820       IF THIS-MONTH = ZERO
0830           MOVE 12 TO THIS-MONTH
0840           SUBTRACT 1 FROM THIS-YEAR.
0850       STRING MONTH-NAME (THIS-MONTH) DELIMITED BY SPACE
0860         '  ' DELIMITED BY SIZE
0870         THIS-YEAR DELIMITED BY SIZE
0880         INTO SUM-TITLE-DATE.
0890
0900       INITIALIZE DIVISION-TOTALS-TABLE.
0910
0920       OPEN INPUT ORDERS-SUBMITTED.
0930  *    OPEN OUTPUT COMPANY-ORDERS.
0940       PERFORM 0500-READ-ORDER.
0950       PERFORM 0200-MAIN-LOOP
0960           UNTIL END-OF-INPUT.
0970       CLOSE ORDERS-SUBMITTED.
0980  *    CLOSE COMPANY-ORDERS.
0990
1000       OPEN OUTPUT ORDER-SUMMARY.
1010       WRITE ORDER-SUMMARY-LINE FROM SUMMARY-TITLE
1020           AFTER ADVANCING 1 LINE.
1030       WRITE ORDER-SUMMARY-LINE FROM  SUMMARY-HEADING
1040           AFTER ADVANCING 2 LINES.
1050       MOVE SPACES TO ORDER-SUMMARY-LINE.
1060       WRITE ORDER-SUMMARY-LINE
1070           AFTER ADVANCING 2 LINE.
1080       PERFORM 0300-PRINT-SUMMARY
1090           VARYING ORG-SUB FROM 1 BY 1
1100           UNTIL ORG-SUB > 7.
1101       MOVE 'GRAND TOTAL' TO  SUM-DTL-NAME.
1102       MOVE TOTAL-COUNT TO  SUM-DTL-COUNT.
1103       MOVE  TOTAL-AMOUNT TO  SUM-DTL-AMOUNT.
1104       WRITE ORDER-SUMMARY-LINE FROM SUMMARY-DETAIL
1105           AFTER ADVANCING 3 LINES.
1110       CLOSE ORDER-SUMMARY.
1120       STOP RUN.
1130
1140   0200-MAIN-LOOP.
1150  *    PERFORM 0250-FORMAT-ORDER-LINE.
1160       ADD 1 TO DIVISION-COUNT (ORD-RECIPIENT).
1170       COMPUTE DIVISION-AMOUNT (ORD-RECIPIENT)
1171           = DIVISION-AMOUNT (ORD-RECIPIENT)
1180           + (ORD-ITEM-COUNT * ORD-ITEM-RATE).
1190       PERFORM 0500-READ-ORDER.
1200  *0250-FORMAT-ORDER-LINE.
1210   0300-PRINT-SUMMARY.
1211       ADD DIVISION-COUNT (ORG-SUB) TO TOTAL-COUNT.
1212       ADD DIVISION-AMOUNT (ORG-SUB) TO TOTAL-AMOUNT.
1220       MOVE DIVISION-NAME (ORG-SUB) TO SUM-DTL-NAME.
1230       MOVE DIVISION-COUNT (ORG-SUB) TO SUM-DTL-COUNT.
1240       MOVE DIVISION-AMOUNT (ORG-SUB) TO SUM-DTL-AMOUNT.
1250       WRITE ORDER-SUMMARY-LINE FROM SUMMARY-DETAIL
1260           AFTER ADVANCING 2 LINES.
1270   0500-READ-ORDER.
1280       READ ORDERS-SUBMITTED
1290           AT END
1300               MOVE 'YES' TO INPUT-EOF-CONTROL.

