TABLSOUP.CBL variations:
This document shows several additional versions of the tablsoup.cbl program with different
options.
In the first version shown below which is saved as TABLNIND.CBL, I am not using an
indicator when a match is found. Instead, the PERFORM tests directly for the match.
PERFORM B-300-SEARCH
UNTIL ITEM-SUB > 9 OR
ITEM-NUMBER-IN = ITEM-NUMBER-TBL (ITEM-SUB).
Note that the UNTIL now tests for no match, ITEM-SUM > 9 and for the match. Because the
test is in the PERFORM, it is not necessary to do any testing in the loop. The purpose of
the loop is simply to increment the subscript.
B-300-SEARCH.
ADD 1 TO ITEM-SUB.
The entire program TABLNIND is shown below.
IDENTIFICATION DIVISION.
PROGRAM-ID. TABLSOUP.
AUTHOR. GROCER.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-FILE ASSIGN TO "C:\PCOBWIN\TABLES\STUTRAN.DAT".
SELECT PRINT-FILE ASSIGN TO "A:\OUTTNIND".
DATA DIVISION.
FILE SECTION.
FD INPUT-FILE
DATA RECORD IS INPUT-REC.
01 INPUT-REC.
05 ORDER-NO PIC 9999.
05 ITEM-NUMBER-IN PIC 99.
FD PRINT-FILE
DATA RECORD IS PRINTZ.
01 PRINTZ.
05 FILLER PIC X.
05 ORDER-NO-PR PIC 9999.
05 FILLER PIC X(10).
05 ITEM-NUMBER-IN-PR PIC 99.
05 FILLER PIC X(10).
05 ITEM-NAME-PR PIC X(15).
05 FILLER PIC X(38).
WORKING-STORAGE SECTION.
01 INDICATORS.
05 MORE-RECS PIC XXX VALUE "YES".
05 MATCH-IND PIC XXX VALUE "NO".
01 SUBSCRIPTS.
05 ITEM-SUB PIC 99 VALUE 0.
01 TABLE-COMBINED.
05 FILLER PIC X(17) VALUE "03SEAFOOD CHOWDER".
05 FILLER PIC X(17) VALUE "12CORN CHOWDER ".
05 FILLER PIC X(17) VALUE "15CLAM CHOWDER ".
05 FILLER PIC X(17) VALUE "17TOMATO SOUP ".
05 FILLER PIC X(17) VALUE "24CHICKEN SOUP ".
05 FILLER PIC X(17) VALUE "25VEGETABLE SOUP ".
05 FILLER PIC X(17) VALUE "27ONION SOUP ".
05 FILLER PIC X(17) VALUE "28GREEN PEA SOUP ".
05 FILLER PIC X(17) VALUE "45WONTON SOUP ".
01 RDF-TABLE-COMBINED REDEFINES TABLE-COMBINED.
05 ENTRIES OCCURS 9 TIMES.
10 ITEM-NUMBER-TBL PIC 99.
10 ITEM-NAME-TBL PIC X(15).
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 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(24) VALUE SPACES.
05 FILLER PIC X(11) VALUE "SOUP REPORT".
05 FILLER PIC X(23) 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 X(5) VALUE "ORDER".
05 FILLER PIC X(7) VALUE SPACES.
05 FILLER PIC X(6) VALUE "ITEM #".
05 FILLER PIC X(8) VALUE SPACES.
05 FILLER PIC X(9) VALUE "ITEM NAME".
05 FILLER PIC X(44) 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.
PERFORM U-000-DATE-ROUT.
B-100-PROCESS.
READ INPUT-FILE
AT END
MOVE "NO " TO MORE-RECS.
PERFORM B-200-LOOP
UNTIL MORE-RECS = "NO ".
B-200-LOOP.
IF LINE-CT > 55 OR PAGE-NO = 1
PERFORM B-310-HDR-ROUT.
MOVE SPACES TO PRINTZ.
MOVE ORDER-NO TO ORDER-NO-PR.
MOVE ITEM-NUMBER-IN TO ITEM-NUMBER-IN-PR.
MOVE 1 TO ITEM-SUB.
PERFORM B-300-SEARCH
UNTIL ITEM-SUB > 9 OR
ITEM-NUMBER-IN = ITEM-NUMBER-TBL (ITEM-SUB).
IF ITEM-SUB > 9
MOVE "*** INVALID ***" TO ITEM-NAME-PR
ELSE
MOVE ITEM-NAME-TBL (ITEM-SUB) TO ITEM-NAME-PR
END-IF
WRITE PRINTZ
AFTER ADVANCING 1 LINES.
ADD 1 TO LINE-CT.
READ INPUT-FILE
AT END
MOVE "NO " TO MORE-RECS.
B-300-SEARCH.
ADD 1 TO ITEM-SUB.
B-310-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-010-BLANK-LINE.
ADD 1 TO PAGE-NO.
MOVE 4 TO LINE-CT.
C-100-WRAPUP.
CLOSE INPUT-FILE
PRINT-FILE.
U-000-DATE-ROUT.
ACCEPT DATE-WS FROM DATE.
MOVE MO-WS TO MO-HDR.
MOVE DA-WS TO DA-HDR.
MOVE YR-WS TO YR-HDR.
U-010-BLANK-LINE.
MOVE SPACES TO PRINTZ.
WRITE PRINTZ
AFTER ADVANCING 1 LINES.
In the second version, TABLEMBD.CBL, I am using an embedded PERFORM instead of the
standalone PERFORM to handle the search. This means that I do no have a paragraph called
B-300-SEARCH. The code for the search is handed right in the PERFORM. This is an
excellent way of doing this program because the code is all together and easy to follow.
Notice that the PERFORM does not have a paragraph name on it. It is simply followed by the
UNTIL and then the code that would have been in the paragraph is inserted. I ended the if
with and END-IF and the PERFORM with an END-PERFORM to avoid any problems with embedded
periods and for clarity.
MOVE 1 TO ITEM-SUB.
MOVE "NO " TO MATCH-IND.
PERFORM
UNTIL ITEM-SUB > 9 OR MATCH-IND = "YES"
IF ITEM-NUMBER-IN = ITEM-NUMBER-TBL(ITEM-SUB)
MOVE "YES" TO MATCH-IND
ELSE
ADD 1 TO ITEM-SUB
END-IF
END-PERFORM
IF MATCH-IND= "YES"
MOVE ITEM-NAME-TBL (ITEM-SUB) TO ITEM-NAME-PR
ELSE
MOVE "*** INVALID ***" TO ITEM-NAME-PR.
The complete program is shown below:
IDENTIFICATION DIVISION.
PROGRAM-ID. TABLSOUP.
AUTHOR. GROCER.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-FILE ASSIGN TO "C:\PCOBWIN\TABLES\STUTRAN.DAT".
SELECT PRINT-FILE ASSIGN TO "A:\OUTEMBD".
DATA DIVISION.
FILE SECTION.
FD INPUT-FILE
DATA RECORD IS INPUT-REC.
01 INPUT-REC.
05 ORDER-NO PIC 9999.
05 ITEM-NUMBER-IN PIC 99.
FD PRINT-FILE
DATA RECORD IS PRINTZ.
01 PRINTZ.
05 FILLER PIC X.
05 ORDER-NO-PR PIC 9999.
05 FILLER PIC X(10).
05 ITEM-NUMBER-IN-PR PIC 99.
05 FILLER PIC X(10).
05 ITEM-NAME-PR PIC X(15).
05 FILLER PIC X(38).
WORKING-STORAGE SECTION.
01 INDICATORS.
05 MORE-RECS PIC XXX VALUE "YES".
05 MATCH-IND PIC XXX VALUE "NO".
01 SUBSCRIPTS.
05 ITEM-SUB PIC 99 VALUE 0.
01 TABLE-COMBINED.
05 FILLER PIC X(17) VALUE "03SEAFOOD CHOWDER".
05 FILLER PIC X(17) VALUE "12CORN CHOWDER ".
05 FILLER PIC X(17) VALUE "15CLAM CHOWDER ".
05 FILLER PIC X(17) VALUE "17TOMATO SOUP ".
05 FILLER PIC X(17) VALUE "24CHICKEN SOUP ".
05 FILLER PIC X(17) VALUE "25VEGETABLE SOUP ".
05 FILLER PIC X(17) VALUE "27ONION SOUP ".
05 FILLER PIC X(17) VALUE "28GREEN PEA SOUP ".
05 FILLER PIC X(17) VALUE "45WONTON SOUP ".
01 RDF-TABLE-COMBINED REDEFINES TABLE-COMBINED.
05 ENTRIES OCCURS 9 TIMES.
10 ITEM-NUMBER-TBL PIC 99.
10 ITEM-NAME-TBL PIC X(15).
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 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(24) VALUE SPACES.
05 FILLER PIC X(11) VALUE "SOUP REPORT".
05 FILLER PIC X(23) 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 X(5) VALUE "ORDER".
05 FILLER PIC X(7) VALUE SPACES.
05 FILLER PIC X(6) VALUE "ITEM #".
05 FILLER PIC X(8) VALUE SPACES.
05 FILLER PIC X(9) VALUE "ITEM NAME".
05 FILLER PIC X(44) 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.
PERFORM U-000-DATE-ROUT.
B-100-PROCESS.
READ INPUT-FILE
AT END
MOVE "NO " TO MORE-RECS.
PERFORM B-200-LOOP
UNTIL MORE-RECS = "NO ".
B-200-LOOP.
IF LINE-CT > 55 OR PAGE-NO = 1
PERFORM B-310-HDR-ROUT.
MOVE SPACES TO PRINTZ.
MOVE ORDER-NO TO ORDER-NO-PR.
MOVE ITEM-NUMBER-IN TO ITEM-NUMBER-IN-PR.
MOVE 1 TO ITEM-SUB.
MOVE "NO " TO MATCH-IND.
PERFORM
UNTIL ITEM-SUB > 9 OR MATCH-IND = "YES"
IF ITEM-NUMBER-IN = ITEM-NUMBER-TBL(ITEM-SUB)
MOVE "YES" TO MATCH-IND
ELSE
ADD 1 TO ITEM-SUB
END-IF
END-PERFORM
IF MATCH-IND= "YES"
MOVE ITEM-NAME-TBL (ITEM-SUB) TO ITEM-NAME-PR
ELSE
MOVE "*** INVALID ***" TO ITEM-NAME-PR.
WRITE PRINTZ
AFTER ADVANCING 1 LINES.
ADD 1 TO LINE-CT.
READ INPUT-FILE
AT END
MOVE "NO " TO MORE-RECS.
B-310-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-010-BLANK-LINE.
ADD 1 TO PAGE-NO.
MOVE 4 TO LINE-CT.
C-100-WRAPUP.
CLOSE INPUT-FILE
PRINT-FILE.
U-000-DATE-ROUT.
ACCEPT DATE-WS FROM DATE.
MOVE MO-WS TO MO-HDR.
MOVE DA-WS TO DA-HDR.
MOVE YR-WS TO YR-HDR.
U-010-BLANK-LINE.
MOVE SPACES TO PRINTZ.
WRITE PRINTZ
AFTER ADVANCING 1 LINES.
In the next two examples, TABLEEX1.CBL and TABLEEX2.CBL, I am dealing with what I call
early exits.
If the numbers are all in sequence in the table, you do not have to search the entire
table. You can leave as soon as you pass the place where the match would be.
For example, if the numbers in the table are 03, 12, 15, 17 etc. and you are looking for a
match to 14, you can exit the table when you find that the third element in the table which
is 15 is greater than the number you are looking for. This saves some processing time,
especially if you have a large table.
Remember - the numbers in the table must be in sequence.
MOVE 1 TO ITEM-SUB.
MOVE "NO " TO MATCH-IND.
PERFORM B-300-SEARCH
UNTIL ITEM-SUB > 9 OR MATCH-IND = "YES" OR
ITEM-NUMBER-TBL (ITEM-SUB) > ITEM-NUMBER-IN.
Notice that I have added a third condition to the test in the UNTIL. The third condition
says if the ITEM-NUMBER-TBL (ITEM-SUB) is greater than the item number on the input, the
perform is done. Looking back to the example above, 15 > 14 would meet this condition.
The entire program is shown below.
IDENTIFICATION DIVISION.
PROGRAM-ID. TABLSOUP.
AUTHOR. GROCER.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-FILE ASSIGN TO "C:\PCOBWIN\TABLES\STUTRAN.DAT".
SELECT PRINT-FILE ASSIGN TO "A:\OUTTEEX1".
DATA DIVISION.
FILE SECTION.
FD INPUT-FILE
DATA RECORD IS INPUT-REC.
01 INPUT-REC.
05 ORDER-NO PIC 9999.
05 ITEM-NUMBER-IN PIC 99.
FD PRINT-FILE
DATA RECORD IS PRINTZ.
01 PRINTZ.
05 FILLER PIC X.
05 ORDER-NO-PR PIC 9999.
05 FILLER PIC X(10).
05 ITEM-NUMBER-IN-PR PIC 99.
05 FILLER PIC X(10).
05 ITEM-NAME-PR PIC X(15).
05 FILLER PIC X(38).
WORKING-STORAGE SECTION.
01 INDICATORS.
05 MORE-RECS PIC XXX VALUE "YES".
05 MATCH-IND PIC XXX VALUE "NO".
01 SUBSCRIPTS.
05 ITEM-SUB PIC 99 VALUE 0.
01 TABLE-COMBINED.
05 FILLER PIC X(17) VALUE "03SEAFOOD CHOWDER".
05 FILLER PIC X(17) VALUE "12CORN CHOWDER ".
05 FILLER PIC X(17) VALUE "15CLAM CHOWDER ".
05 FILLER PIC X(17) VALUE "17TOMATO SOUP ".
05 FILLER PIC X(17) VALUE "24CHICKEN SOUP ".
05 FILLER PIC X(17) VALUE "25VEGETABLE SOUP ".
05 FILLER PIC X(17) VALUE "27ONION SOUP ".
05 FILLER PIC X(17) VALUE "28GREEN PEA SOUP ".
05 FILLER PIC X(17) VALUE "45WONTON SOUP ".
01 RDF-TABLE-COMBINED REDEFINES TABLE-COMBINED.
05 ENTRIES OCCURS 9 TIMES.
10 ITEM-NUMBER-TBL PIC 99.
10 ITEM-NAME-TBL PIC X(15).
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 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(24) VALUE SPACES.
05 FILLER PIC X(11) VALUE "SOUP REPORT".
05 FILLER PIC X(23) 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 X(5) VALUE "ORDER".
05 FILLER PIC X(7) VALUE SPACES.
05 FILLER PIC X(6) VALUE "ITEM #".
05 FILLER PIC X(8) VALUE SPACES.
05 FILLER PIC X(9) VALUE "ITEM NAME".
05 FILLER PIC X(44) 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.
PERFORM U-000-DATE-ROUT.
B-100-PROCESS.
READ INPUT-FILE
AT END
MOVE "NO " TO MORE-RECS.
PERFORM B-200-LOOP
UNTIL MORE-RECS = "NO ".
B-200-LOOP.
IF LINE-CT > 55 OR PAGE-NO = 1
PERFORM B-310-HDR-ROUT.
MOVE SPACES TO PRINTZ.
MOVE ORDER-NO TO ORDER-NO-PR.
MOVE ITEM-NUMBER-IN TO ITEM-NUMBER-IN-PR.
MOVE 1 TO ITEM-SUB.
MOVE "NO " TO MATCH-IND.
PERFORM B-300-SEARCH
UNTIL ITEM-SUB > 9 OR MATCH-IND = "YES" OR
ITEM-NUMBER-TBL (ITEM-SUB) > ITEM-NUMBER-IN.
IF MATCH-IND = "YES"
MOVE ITEM-NAME-TBL (ITEM-SUB) TO ITEM-NAME-PR
ELSE
MOVE "*** INVALID ***" TO ITEM-NAME-PR.
WRITE PRINTZ
AFTER ADVANCING 1 LINES.
ADD 1 TO LINE-CT.
READ INPUT-FILE
AT END
MOVE "NO " TO MORE-RECS.
B-300-SEARCH.
IF ITEM-NUMBER-IN = ITEM-NUMBER-TBL (ITEM-SUB)
MOVE "YES" TO MATCH-IND
ELSE
ADD 1 TO ITEM-SUB.
B-310-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-010-BLANK-LINE.
ADD 1 TO PAGE-NO.
MOVE 4 TO LINE-CT.
C-100-WRAPUP.
CLOSE INPUT-FILE
PRINT-FILE.
U-000-DATE-ROUT.
ACCEPT DATE-WS FROM DATE.
MOVE MO-WS TO MO-HDR.
MOVE DA-WS TO DA-HDR.
MOVE YR-WS TO YR-HDR.
U-010-BLANK-LINE.
MOVE SPACES TO PRINTZ.
WRITE PRINTZ
AFTER ADVANCING 1 LINES.
The next example also uses early exit logic. In this example, the MATCH-IND can have three
values. Empty or spaces is the initial value. If a match is found the indicator is set
to YES, if the number is passed so the early exit is warranted, the indicator is sent to NO.
MOVE 1 TO ITEM-SUB.
MOVE " " TO MATCH-IND.
PERFORM B-300-SEARCH
UNTIL ITEM-SUB > 9 OR MATCH-IND NOT = " ".
IF MATCH-IND = "YES"
MOVE ITEM-NAME-TBL (ITEM-SUB) TO ITEM-NAME-PR
ELSE
MOVE "*** INVALID ***" TO ITEM-NAME-PR.
B-300-SEARCH.
IF ITEM-NUMBER-IN = ITEM-NUMBER-TBL (ITEM-SUB)
MOVE "YES" TO MATCH-IND
ELSE
IF ITEM-NUMBER-TBL (ITEM-SUB) > ITEM-NUMBER-IN
MOVE "NO " TO MATCH-IND
ELSE
ADD 1 TO ITEM-SUB.
The entire program is shown below.
IDENTIFICATION DIVISION.
PROGRAM-ID. TABLSOUP.
AUTHOR. GROCER.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-FILE ASSIGN TO "C:\PCOBWIN\TABLES\STUTRAN.DAT".
SELECT PRINT-FILE ASSIGN TO "A:\OUTTEEX2".
DATA DIVISION.
FILE SECTION.
FD INPUT-FILE
DATA RECORD IS INPUT-REC.
01 INPUT-REC.
05 ORDER-NO PIC 9999.
05 ITEM-NUMBER-IN PIC 99.
FD PRINT-FILE
DATA RECORD IS PRINTZ.
01 PRINTZ.
05 FILLER PIC X.
05 ORDER-NO-PR PIC 9999.
05 FILLER PIC X(10).
05 ITEM-NUMBER-IN-PR PIC 99.
05 FILLER PIC X(10).
05 ITEM-NAME-PR PIC X(15).
05 FILLER PIC X(38).
WORKING-STORAGE SECTION.
01 INDICATORS.
05 MORE-RECS PIC XXX VALUE "YES".
05 MATCH-IND PIC XXX VALUE "NO".
01 SUBSCRIPTS.
05 ITEM-SUB PIC 99 VALUE 0.
01 TABLE-COMBINED.
05 FILLER PIC X(17) VALUE "03SEAFOOD CHOWDER".
05 FILLER PIC X(17) VALUE "12CORN CHOWDER ".
05 FILLER PIC X(17) VALUE "15CLAM CHOWDER ".
05 FILLER PIC X(17) VALUE "17TOMATO SOUP ".
05 FILLER PIC X(17) VALUE "24CHICKEN SOUP ".
05 FILLER PIC X(17) VALUE "25VEGETABLE SOUP ".
05 FILLER PIC X(17) VALUE "27ONION SOUP ".
05 FILLER PIC X(17) VALUE "28GREEN PEA SOUP ".
05 FILLER PIC X(17) VALUE "45WONTON SOUP ".
01 RDF-TABLE-COMBINED REDEFINES TABLE-COMBINED.
05 ENTRIES OCCURS 9 TIMES.
10 ITEM-NUMBER-TBL PIC 99.
10 ITEM-NAME-TBL PIC X(15).
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 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(24) VALUE SPACES.
05 FILLER PIC X(11) VALUE "SOUP REPORT".
05 FILLER PIC X(23) 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 X(5) VALUE "ORDER".
05 FILLER PIC X(7) VALUE SPACES.
05 FILLER PIC X(6) VALUE "ITEM #".
05 FILLER PIC X(8) VALUE SPACES.
05 FILLER PIC X(9) VALUE "ITEM NAME".
05 FILLER PIC X(44) 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.
PERFORM U-000-DATE-ROUT.
B-100-PROCESS.
READ INPUT-FILE
AT END
MOVE "NO " TO MORE-RECS.
PERFORM B-200-LOOP
UNTIL MORE-RECS = "NO ".
B-200-LOOP.
IF LINE-CT > 55 OR PAGE-NO = 1
PERFORM B-310-HDR-ROUT.
MOVE SPACES TO PRINTZ.
MOVE ORDER-NO TO ORDER-NO-PR.
MOVE ITEM-NUMBER-IN TO ITEM-NUMBER-IN-PR.
MOVE 1 TO ITEM-SUB.
MOVE " " TO MATCH-IND.
PERFORM B-300-SEARCH
UNTIL ITEM-SUB > 9 OR MATCH-IND NOT = " ".
IF MATCH-IND = "YES"
MOVE ITEM-NAME-TBL (ITEM-SUB) TO ITEM-NAME-PR
ELSE
MOVE "*** INVALID ***" TO ITEM-NAME-PR.
WRITE PRINTZ
AFTER ADVANCING 1 LINES.
ADD 1 TO LINE-CT.
READ INPUT-FILE
AT END
MOVE "NO " TO MORE-RECS.
B-300-SEARCH.
IF ITEM-NUMBER-IN = ITEM-NUMBER-TBL (ITEM-SUB)
MOVE "YES" TO MATCH-IND
ELSE
IF ITEM-NUMBER-TBL (ITEM-SUB) > ITEM-NUMBER-IN
MOVE "NO " TO MATCH-IND
ELSE
ADD 1 TO ITEM-SUB.
B-310-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-010-BLANK-LINE.
ADD 1 TO PAGE-NO.
MOVE 4 TO LINE-CT.
C-100-WRAPUP.
CLOSE INPUT-FILE
PRINT-FILE.
U-000-DATE-ROUT.
ACCEPT DATE-WS FROM DATE.
MOVE MO-WS TO MO-HDR.
MOVE DA-WS TO DA-HDR.
MOVE YR-WS TO YR-HDR.
U-010-BLANK-LINE.
MOVE SPACES TO PRINTZ.
WRITE PRINTZ
AFTER ADVANCING 1 LINES.