1 / 11

Two and three dimension tables

Two and three dimension tables. Please use speaker notes for additional information!. twodim.cbl. IDENTIFICATION DIVISION. PROGRAM-ID. TWODIM. AUTHOR. GROCER. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL.

osgood
Download Presentation

Two and three dimension tables

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Two and three dimension tables Please use speaker notes for additional information!

  2. twodim.cbl IDENTIFICATION DIVISION. PROGRAM-ID. TWODIM. AUTHOR. GROCER. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INPUT-FILE ASSIGN TO "C:\PCOBWIN\CIS12FST\TWODIM.DAT". SELECT PRINT-FILE ASSIGN TO PRINTER. DATA DIVISION. FILE SECTION. FD INPUT-FILE DATA RECORD IS INPUT-REC. 01 INPUT-REC. 05 CUST-ID PIC X(4). 05 FROM-CITY PIC 9. 05 TO-CITY PIC 9. FD PRINT-FILE DATA RECORD IS PRINTZ. 01 PRINTZ. 05 FILLER PIC X(4). 05 CUST-ID-PR PIC X(4). 05 FILLER PIC X(15). 05 FROM-CITY-PR PIC X(10). 05 FILLER PIC X(5). 05 TO-CITY-PR PIC X(10). 05 FILLER PIC X(5). 05 FARE-PR PIC $ZZZ.99. 05 FILLER PIC X(20). These two input fields are going to be used as the subscripts to get information out of the two dimension table. The fare from the two-dimensional table will print in this field. Input data: 111123 121222 123433 212125 234514 242511 272835 The city names from the 2 one-dimensional tables will print in these fields. WORKING-STORAGE SECTION. 01 PROGRAM-INDICATORS. 05 MORE-RECS PIC XXX VALUE "YES". 01 WORK-AREAS. 05 INV-VALUE-WS PIC 9(5)V99 VALUE 0.

  3. twodim.cbl 01 FARE-TABLE. 05 FROM-BOSTON. 10 TO-ISTANBUL PIC 999V99 VALUE 851.00. 10 TO-BUDAPEST PIC 999V99 VALUE 549.50. 10 TO-FRANKFORT PIC 999V99 VALUE 659.95. 10 TO-LONDON PIC 999V99 VALUE 499.00. 10 TO-PRAGUE PIC 999V99 VALUE 498.99. 05 FROM-PROVIDENCE. 10 TO-ISTANBUL PIC 999V99 VALUE 929.00. 10 TO-BUDAPEST PIC 999V99 VALUE 612.75. 10 TO-FRANKFORT PIC 999V99 VALUE 628.99. 10 TO-LONDON PIC 999V99 VALUE 525.00. 10 TO-PRAGUE PIC 999V99 VALUE 550.00. 05 FROM-NEW-YORK. 10 TO-ISTANBUL PIC 999V99 VALUE 799.99. 10 TO-BUDABEST PIC 999V99 VALUE 526.89. 10 TO-FRANKFORT PIC 999V99 VALUE 498.99. 10 TO-LONDON PIC 999V99 VALUE 425.00. 10 TO-PRAGUE PIC 999V99 VALUE 512.00. 01 RDF-FARE-TABLE REDEFINES FARE-TABLE. 05 FROM-CITIES OCCURS 3 TIMES. 10 FARE PIC 999V99 OCCURS 5 TIMES.

  4. 01 FROM-CITY-TABLE. 05 FILLER PIC X(10) VALUE "BOSTON ". 05 FILLER PIC X(10) VALUE "PROVIDENCE". 05 FILLER PIC X(10) VALUE "NEW YORK ". 01 RDF-FROM-CITY-TABLE REDEFINES FROM-CITY-TABLE. 05 FROM-CITY-NAME PIC X(10) OCCURS 3 TIMES. 01 TO-CITY-TABLE. 05 FILLER PIC X(10) VALUE "ISTANBUL ". 05 FILLER PIC X(10) VALUE "BUDAPEST ". 05 FILLER PIC X(10) VALUE "FRANKFORT ". 05 FILLER PIC X(10) VALUE "LONDON ". 05 FILLER PIC X(10) VALUE "PRAGUE ". 01 RDF-TO-CITY-TABLE REDEFINES TO-CITY-TABLE. 05 TO-CITY-NAME PIC X(10) OCCURS 5 TIMES. 01 FARE-TABLE. 05 FROM-BOSTON. 10 TO-ISTANBUL PIC 999V99 VALUE 851.00. 10 TO-BUDAPEST PIC 999V99 VALUE 549.50. 10 TO-FRANKFORT PIC 999V99 VALUE 659.95. 10 TO-LONDON PIC 999V99 VALUE 499.00. 10 TO-PRAGUE PIC 999V99 VALUE 498.99. 05 FROM-PROVIDENCE. 10 TO-ISTANBUL PIC 999V99 VALUE 929.00. 10 TO-BUDAPEST PIC 999V99 VALUE 612.75. 10 TO-FRANKFORT PIC 999V99 VALUE 628.99. 10 TO-LONDON PIC 999V99 VALUE 525.00. 10 TO-PRAGUE PIC 999V99 VALUE 550.00. 05 FROM-NEW-YORK. 10 TO-ISTANBUL PIC 999V99 VALUE 799.99. 10 TO-BUDABEST PIC 999V99 VALUE 526.89. 10 TO-FRANKFORT PIC 999V99 VALUE 498.99. 10 TO-LONDON PIC 999V99 VALUE 425.00. 10 TO-PRAGUE PIC 999V99 VALUE 512.00. 01 RDF-FARE-TABLE REDEFINES FARE-TABLE. 05 FROM-CITIES OCCURS 3 TIMES. 10 FARE PIC 999V99 OCCURS 5 TIMES. twodim.cbl FROM-CITY on the input has values of 1, 2, or 3. It will be used as a subscript to move the FROM-CITY-NAME from this table. MOVE FROM-CITY-NAME (FROM-CITY).. TO-CITY on the input has values of 1, 2, 3, 4 or 5. It will be used as a subscript to move the TO-CITY-NAME from this table. MOVE TO-CITY-NAME (TO-CITY)... You can see that there are three 05s that describe the 3 places you can fly from. In this example consider these the rows. Under the redefines, I am redefining these as 05 FROM-CITIES. Under each of the 05s, I have put five 10 levels to describe each of the cities I can fly to. In this example, consider them columns. On the redefines, these are called FARE with an occurs of 5 times. Looking at it, I have three 05s redefined as 05 occurs 3 times and under each 05 in the original table I have five 10s redefined as 10 FARE with a picture and occurs 5 times.

  5. twodim.cbl 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(22) VALUE SPACES. 05 FILLER PIC X(16) VALUE "AIR FARE 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 X(10) VALUE "PASSENGER ". 05 FILLER PIC X(12) VALUE SPACES. 05 FILLER PIC X(10) VALUE "ORIGINATE ". 05 FILLER PIC X(5) VALUE SPACES. 05 FILLER PIC X(11) VALUE "DESTINATION". 05 FILLER PIC X(6) VALUE SPACES. 05 FILLER PIC X(4) VALUE "FARE". 05 FILLER PIC X(16) VALUE SPACES.

  6. twodim.cbl PROCEDURE DIVISION. MAINLINE. PERFORM A-100-STARTUP. PERFORM B-100-PROCESS. PERFORM C-100-WRAPUP. STOP RUN. A-100-STARTUP. 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. PERFORM B-300-DETAIL. READ INPUT-FILE AT END MOVE "NO " TO MORE-RECS. B-300-DETAIL. IF LINE-CT > 55 OR PAGE-NO = 1 PERFORM B-400-HDR-ROUT. MOVE SPACES TO PRINTZ. MOVE CUST-ID TO CUST-ID-PR. MOVE FROM-CITY-NAME (FROM-CITY) TO FROM-CITY-PR. MOVE TO-CITY-NAME (TO-CITY) TO TO-CITY-PR. MOVE FARE (FROM-CITY, TO-CITY) TO FARE-PR. WRITE PRINTZ AFTER ADVANCING 1 LINES. ADD 1 TO LINE-CT. This line moves the FROM-CITY-NAME from the one dimensional table, subscripted by FROM-CITY from the input to the field on the print line. This line moves the TO-CITY-NAME from the one dimensional table subscripted by TO-CITY from the input to the field on the print line. This line moves the FARE, first subscripted by FROM-CITY to get into the correct 05 level and then subscripted by TO-CITY to get into the correct 10 level. It moves the subscripted FARE to the field on the print line.

  7. twodim.cbl 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. MOVE SPACES TO PRINTZ. WRITE PRINTZ AFTER ADVANCING 1 LINES. ADD 1 TO PAGE-NO. MOVE 4 TO LINE-CT. 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. C-100-WRAPUP. CLOSE INPUT-FILE PRINT-FILE.

  8. twodim.cbl This is the result of the: MOVE TO-CITY-NAME (TO-CITY) TO TO-CITY-PR. This is the result of the: MOVE FROM-CITY-NAME (FROM-CITY) TO FROM-CITY-PR. 05/01/99 AIR FARE REPORT PAGE 1 PASSENGER ORIGINATE DESTINATION FARE 1111 PROVIDENCE FRANKFORT $628.99 1212 PROVIDENCE BUDAPEST $612.75 1234 NEW YORK FRANKFORT $498.99 2121 PROVIDENCE PRAGUE $550.00 2345 BOSTON LONDON $499.00 2425 BOSTON ISTANBUL $851.00 2728 NEW YORK PRAGUE $512.00 This is the result of the MOVE FARE (FROM-CITY, TO-CITY) TO FARE-PR.

  9. Alternate way of setting up the two dimension table: 01 FARE-TABLE-WAY2. 05 TO-ISTANBUL. 10 FROM-BOSTON PIC 999V99 VALUE 851.00. 10 FROM-PROV PIC 999V99 VALUE 929.00. 10 FROM-NEW-YORK PIC 999V99 VALUE 799.99. 05 TO-BUDAPEST. 10 FROM-BOSTON PIC 999V99 VALUE 549.50. 10 FROM-PROV PIC 999V99 VALUE 612.75. 10 FROM-NEW-YORK PIC 999V99 VALUE 526.89. 05 TO-FRANKFORT. 10 FROM-BOSTON PIC 999V99 VALUE 659.96. 10 FROM-PROV PIC 999V99 VALUE 628.99. 10 FROM-NEW-YORK PIC 999V99 VALUE 498.99. 05 TO-LONDON. 10 FROM-BOSTON PIC 99V99 VALUE 499.00 10 FROM-PROV PIC 99V99 VALUE 525.00. 10 FROM-NEW-YORK PIC 999V99 VALUE 425.00. 05 TO-PRAGUE. 10 FROM-BOSTON PIC 99V99 VALUE 498.99. 10 FROM-PROV PIC 99V99 VALUE 550.00. 10 FROM-NEW-YORK PIC 999V99 VALUE 512.00. 01 RDF-FARE-TABLE REDEFINES FARE-TABLE. 05 TO-CITIES OCCURS 5 TIMES. 10 FARE PIC 999V99 OCCURS 3 TIMES.

  10. Alternate approach 01 FARE-TABLE-WAY2. 05 TO-ISTANBUL. 10 FROM-BOSTON PIC 999V99 VALUE 851.00. 10 FROM-PROV PIC 999V99 VALUE 929.00. 10 FROM-NEW-YORK PIC 999V99 VALUE 799.99. 05 TO-BUDAPEST. 10 FROM-BOSTON PIC 999V99 VALUE 549.50. 10 FROM-PROV PIC 999V99 VALUE 612.75. 10 FROM-NEW-YORK PIC 999V99 VALUE 526.89. 05 TO-FRANKFORT. 10 FROM-BOSTON PIC 999V99 VALUE 659.96. 10 FROM-PROV PIC 999V99 VALUE 628.99. 10 FROM-NEW-YORK PIC 999V99 VALUE 498.99. 05 TO-LONDON. 10 FROM-BOSTON PIC 99V99 VALUE 499.00 10 FROM-PROV PIC 99V99 VALUE 525.00. 10 FROM-NEW-YORK PIC 999V99 VALUE 425.00. 05 TO-PRAGUE. 10 FROM-BOSTON PIC 99V99 VALUE 498.99. 10 FROM-PROV PIC 99V99 VALUE 550.00. 10 FROM-NEW-YORK PIC 999V99 VALUE 512.00. 01 RDF-FARE-TABLE REDEFINES FARE-TABLE. 05 TO-CITIES OCCURS 5 TIMES. 10 FARE PIC 999V99 OCCURS 3 TIMES. INPUT: 05 FROM-CITY PIC 9. 05 TO-CITY PIC 9. In the PROCEDURE DIVISION: MOVE FARE(TO-CITY, FROM-CITY) TO FARE-PR.

  11. 3 dimension table 01 THREE-DIM-TABLE. 05 DAY-RATES. 10 DAY-S-S. 15 TO-FR PIC 9V99 VALUE 1.20. 15 TO-NB PIC 9V99 VALUE 1.25. 15 TO-NP PIC 9V99 VALUE 1.35. 15 TO-PR PIC 9V99 VALUE 1.40. 10 DAY-P-P. 15 TO-FR PIC 9V99 VALUE 1.35. 15 TO-NB PIC 9V99 VALUE 1.40. 15 TO-NP PIC 9V99 VALUE 1.50. 15 TO-PR PIC 9V99 VALUE 1.55. 05 EVENING-RATES. 10 EVENING-S-S. 15 TO-FR PIC 9V99 VALUE 1.00. 15 TO-NB PIC 9V99 VALUE 1.05. 15 TO-NP PIC 9V99 VALUE 1.15. 15 TO-PR PIC 9V99 VALUE 1.20. 10 EVENING-P-P. 15 TO-FR PIC 9V99 VALUE 1.15. 15 TO-NB PIC 9V99 VALUE 1.20. 15 TO-NP PIC 9V99 VALUE 1.30. 15 TO-PR PIC 9V99 VALUE 1.35. 05 NIGHT-RATES. 10 NIGHT-S-S. 15 TO-FR PIC 9V99 VALUE 0.85. 15 TO-NB PIC 9V99 VALUE 0.90. 15 TO-NP PIC 9V99 VALUE 1.00. 15 TO-PR PIC 9V99 VALUE 1.05. 10 NIGHT-P-P. 15 TO-FR PIC 9V99 VALUE 1.00. 15 TO-NB PIC 9V99 VALUE 1.05. 15 TO-NP PIC 9V99 VALUE 1.15. 15 TO-PR PIC 9V99 VALUE 1.20. 01 RDF-THREE-DIM-TABLE REDEFINES THREE-DIM-TABLE. 05 TIME-PERIODS OCCURS 3 TIMES. 10 TYPE-CALLS OCCURS 2 TIMES. 15 RATE PIC 9V99 OCCURS 4 TIMES. 01 INPUT-RECORDS 05 ... 05 TIME-CODE PIC 9. 05 TYPE-CODE PIC 9. 05 PLACE-CODE PIC 9. Here we move the RATE subscripted by the TIME-CODE which takes us to the correct 05 level, and the TYPE-CODE that takes us to the correct 10 level under the 05, and the PLACE-CODE which takes us to the correct 15 level. MOVE RATE (TIME-CODE, TYPE-CODE, PLACE-CODE) TO RATE-PR.

More Related