Presentation is loading. Please wait.

Presentation is loading. Please wait.

One & Two dimensional Tables Cont.. Table of Major Codes 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE.

Similar presentations


Presentation on theme: "One & Two dimensional Tables Cont.. Table of Major Codes 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE."— Presentation transcript:

1 One & Two dimensional Tables Cont.

2 Table of Major Codes 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE 43MANAGEMENT 49MARKETING 54STATISTICS

3 Sequential Table Lookup 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE 43MANAGEMENT 49MARKETING 53STATISTICS 39 1st try 2nd try 3rd try 4th try 5th try 6th try 7th try FINANCE Match

4 Binary Lookup 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE 43MANAGEMENT 49MARKETING 53STATISTICS 39 1st try FINANCE Match 2nd try 3rd try

5 01 MAJOR-VALUE. 05 FILLERPIC X(14)VALUE ‘02ART HISTORY’. 05 FILLERPIC X(14)VALUE ‘04BIOLOGY’. 05 FILLERPIC X(14)VALUE ‘19CHEMISTRY’. 05 FILLERPIC X(14)VALUE ‘21CIVIL ENG’. 05 FILLERPIC X(14)VALUE ‘24COMP INF SYS’. 05 FILLERPIC X(14)VALUE ‘32ECONOMICS’. 05 FILLERPIC X(14)VALUE ‘39FINANCE’. 05 FILLERPIC X(14)VALUE ‘43MANAGEMENT’. 05 FILLERPIC X(14)VALUE ‘40MARKETING’. 05 FILLERPIC X(14) VALUE ‘54STATISTICS’. 01 MAJOR-TABLE REDEFINES MAJOR-VALUE. 05 MAJORS OCCURS 10 TIMES. 10 MAJOR-CODEPIC 9(2). 10 EXPANDED-MAJORPIC X(12). Initialization via Hard Coding

6 Table Initialization (Storage Schematic ) 02ARTHISTORY 4BIOLOGY 054STATISTI MAJOR-VALUE MAJOR-TABLE... CD (1) EXP-MAJOR (1) CD (2) EXP-MAJOR (2)EXP-MAJOR (10) CD (10)

7 19CHEMISTRY Input-Loaded Tables 04BIOLOGY 02ART HISTORY 02 ART HISTORY04BIOLOGY19CHEMISTRY MAJOR-CODE (1) EXPANDED-MAJOR (1) MAJOR-CODE (2) EXPANDED-MAJOR (2) MAJOR-CODE (3) EXPANDED-MAJOR (3)

8 Loading from an input file zFD TAX-FILE. z01 TAX-RECORD. z 05 ZIPCODE-IN PIC 9(5). z 05 TAX-RATE-IN PIC V999 COMP-3. z WORKING-STORAGE SECTION. z zREAD TAX-FILE INTO TABLE-ENTRIES (SUB) z AT END z DISPLAY 'NOT ENOUGH TABLE RECORDS' z PERFORM 300-TERMINATION-RTN z STOP RUN zEND-READ. 01 SALES-TAX-TABLE. 05 TABLE-ENTRIES OCCURS 1000 TIMES. 10 T-ZIPCODE PIC 9(5). 10 T-TAX-RATE PIC V999 COMP-3.

9 Sequential Lookup with PERFORM VARYING WORKING-STORAGE SECTION. 01 TABLE-PROCESSING-ELEMENTS. 05 WS-MAJOR-SUBPIC S9(4)COMP. 05 WS-FOUND-MAJOR-SWITCHPIC X(3)VALUE ‘NO’. 05 WS-END-OF-TABLE-SWITCHPIC X(3)VALUE ‘NO’. 01 MAJOR-VALUE. 05 FILLERPIC X(14)VALUE ‘02ART HISTORY’. 05 FILLERPIC X(14)VALUE ‘04BIOLOGY’. 05 FILLERPIC X(14)VALUE ‘19CHEMISTRY’. 05 FILLERPIC X(14)VALUE ‘21CIVIL ENG’. 05 FILLERPIC X(14)VALUE ‘24COMP INF SYS’. 05 FILLERPIC X(14)VALUE ‘32ECONOMICS’. 05 FILLERPIC X(14)VALUE ‘39FINANCE’. 05 FILLERPIC X(14)VALUE ‘43MANAGEMENT’. 05 FILLERPIC X(14)VALUE ‘40MARKETING’. 05 FILLERPIC X(14) VALUE ‘54STATISTICS’. 01 MAJOR-TABLE REDEFINES MAJOR-VALUE. 05 MAJORS OCCURS 10 TIMES. 10 MAJOR-CODEPIC 9(2). 10 EXPANDED-MAJORPIC X(12).

10 Sequential Lookup with PERFORM VARYING PROCEDURE DIVISION. 0000-PREPARE-STUDENT-REPORT. MOVE ‘NO’ TO WS-FOUND-SWITCH WS-END-OF-TABLE-SWITCH. PERFORM 1000-FIND-MAJOR VARYING WS-MAJOR-SUB FROM 1 BY 1 UNTIL WS-END-OF-TABLE-SWITCH = ‘YES’ OR WS-FOUND-MAJOR-SWITCH = ‘YES’.... 1000-FIND-MAJOR. IF WS-MAJOR-SUB > 10 MOVE ‘YES’ TO WS-END-OF-TABLE-SWITCH MOVE ‘UNKNOWN’ TO HDG-MAJOR ELSE IF ST-MAJ0R-CODE = MAJOR-CODE (WS-MAJOR-SUB) MOVE ‘YES’ TO WS-FOUND-MAJOR-SWITCH MOVE EXP-MAJOR (WS-MAJOR-SUB) TO HDG-MAJOR END-IF END-IF.

11 SEARCH Statement (Sequential Lookup) 01 MAJOR-VALUE. 05 FILLERPIC X(14)VALUE ‘02ART HISTORY’. 05 FILLERPIC X(14)VALUE ‘04BIOLOGY’. 05 FILLERPIC X(14)VALUE ‘19CHEMISTRY’. 05 FILLERPIC X(14)VALUE ‘21CIVIL ENG’. 05 FILLERPIC X(14)VALUE ‘24COMP INF SYS’. 05 FILLERPIC X(14)VALUE ‘32ECONOMICS’. 05 FILLERPIC X(14)VALUE ‘39FINANCE’. 05 FILLERPIC X(14)VALUE ‘43MANAGEMENT’. 05 FILLERPIC X(14)VALUE ‘40MARKETING’. 05 FILLERPIC X(14) VALUE ‘54STATISTICS’. 01 MAJOR-TABLE REDEFINES MAJOR-VALUE. 05 MAJORS OCCURS 10 TIMES INDEXED BY MAJOR-INDEX. 10 MAJOR-CODEPIC 9(2). 10 EXPANDED-MAJORPIC X(12).... INDEXED BY clause required in table definition

12 SEARCH Statement (Sequential Lookup) PROCEDURE DIVISION.... SET MAJOR-INDEX TO 1. SEARCH MAJORS AT END MOVE ‘UNKNOWN’ TO HDG-MAJOR WHEN ST-MAJOR-CODE = MAJOR-CODE (MAJOR-INDEX) MOVE EXP-MAJOR (MAJOR-INDEX) TO HDG-MAJOR END-SEARCH. SET statement establishes starting point

13 Indexes versus Subscripts INDEXESSUBSCRIPTS Defined with a specific table; can be used Defined in Working-Storage; the samesubscript only with the table with which they are defined can be used with multiple tables although this is not recommended Initialized and incremented via the SET May not be used with SET statements (MOVE and can also be manipulated by PERFORM ADD are used instead); can also be manipulated in PERFORM statements Provide more efficient object code than USAGE IS COMPUTATIONAL makes subscripts subscripts more efficient, although indexes are still faster To change: Use PERFORM.. VARYINGor To Change: Use PERFORM … VARYING SET or MOVE, ADD, SUBTRACT 1

14 SEARCH ALL Statement (Binary Lookup) KEY required for binary search (ASCENDING or DESCENDING) 01 MAJOR-VALUE. 05 FILLERPIC X(10)VALUE ‘02ART HISTORY’. 05 FILLERPIC X(10)VALUE ‘04BIOLOGY’. 05 FILLERPIC X(10)VALUE ‘19CHEMISTRY’. 05 FILLERPIC X(10)VALUE ‘21CIVIL ENG’. 05 FILLERPIC X(10)VALUE ‘24COMP INF SYS’. 05 FILLERPIC X(10)VALUE ‘32ECONOMICS’. 05 FILLERPIC X(10)VALUE ‘39FINANCE’. 05 FILLERPIC X(10)VALUE ‘43MANAGEMENT’. 05 FILLERPIC X(10)VALUE ‘40MARKETING’. 05 FILLERPIC X(10) VALUE ‘54STATISTICS’. 01 MAJOR-TABLE REDEFINES MAJOR-VALUE. 05 MAJORS OCCURS 10 TIMES ASCENDING KEY IS MAJOR-CODE INDEXED BY MAJOR-INDEX. 10 MAJOR-CODEPIC 9(2). 10 EXPANDED-MAJORPIC X(12)....

15 SEARCH ALL Statement (Binary Lookup) PROCEDURE DIVISION.... SEARCH ALL MAJORS AT END MOVE ‘UNKNOWN’ TO HDG-MAJOR WHEN MAJOR-CODE (MAJOR-INDEX) = ST-MAJOR-CODE MOVE EXP-MAJOR (MAJOR-INDEX) TO HDG-MAJOR END-SEARCH.

16 zImplements a sequential lookup zRequires a SET statement prior to SEARCH to establish the initial position in the table zDoes not require codes in the table to be in any special sequence zContains an optional VARYING clause zMay specify more than one WHEN clause z Implements a binary lookup z Does not require an initial SET statement (calculates its own starting position z Requires the codes to be in ascending or descending sequence on the associated KEY clause in the table definition z Does not contain a VARYING clause z Restricted to a single WHEN clause SEARCH versus SEARCH ALL SEARCH SEARCH ALL

17 Multilevel Tables Responsibility 1 2 3 4 5 6 7 8 9 10 26,000 27,000 28,000 30,000 32,000 34,000 36,000 39,000 42,000 46,000 Responsibility level = 4 (a) One-Level Table

18 Multilevel Tables Responsibility level = 1 Experience level = 4 Responsibility 1 2 3 4 5 6 7 8 9 10 26,000 27,000 28,000 30,000 32,000 34,000 36,000 39,000 42,000 46,000 27,000 28,000 29,000 32,000 34,000 36,000 39,000 42,000 45,000 50,000 28,000 29,000 30,000 34,000 36,000 38,000 42,000 45,000 48,000 54,000 29,000 30,000 31,000 36,000 38,000 40,000 45,000 48,000 51,000 58,000 30,000 31,000 32,000 38,000 40,000 42,000 48,000 51,000 54,000 62,000 12345 Experience Responsibility level = 4 Experience level = 1 (b) Two-Level Table

19 One-Level Table Responsibility 1 2 3 4 5 6 7 8 9 10 26,000 27,000 28,000 30,000 32,000 34,000 36,000 39,000 42,000 46,000 Responsibility level = 4 (a) User’s View 01 SALARY-VALUES. 05 FILLERPIC X(5)VALUE ‘26000’. 05 FILLERPIC X(5)VALUE ‘27000’. 05 FILLERPIC X(5)VALUE ‘28000’. 05 FILLERPIC X(5)VALUE ‘30000’. 05 FILLERPIC X(5)VALUE ‘32000’. 05 FILLERPIC X(5)VALUE ‘34000’. 05 FILLERPIC X(5)VALUE ‘36000’. 05 FILLERPIC X(5)VALUE ‘39000’. 05 FILLERPIC X(5)VALUE ‘42000’. 05 FILLERPIC X(5)VALUE ‘46000’. 01 SALARY-TABLE REDEFINES SALARY-VALUES. 05 SALARY OCCURS 10 TIMESPIC 9(5). (b) Initialization via the REDEFINES and VALUES Clauses SALARY-TABLE SALARY (1) 26000 SALARY (2) 27000 SALARY (3) 28000 SALARY (4) 30000 SALARY (5) 32000 SALARY (6) 34000 SALARY (10) 46000... (c) Storage Schematic

20 Responsibility 1 2 3 4 5 6 7 8 9 10 28,000 29,000 30,000 32,000 34,000 36,000 39,000 42,000 46,000 29,000 30,000 31,000 34,000 36,000 39,000 42,000 45,000 50,000 30,000 31,000 32,000 36,000 38,000 42,000 45,000 48,000 54,000 31,000 32,000 33,000 38,000 40,000 45,000 48,000 51,000 58,000 32,000 33,000 34,000 40,000 42,000 44,000 50000 53,000 56,000 64,000 12345 Experience Multilevel Tables (c) Three-Level Table Responsibility 1 2 3 4 5 6 7 8 9 10 26,000 27,000 28,000 30,000 32,000 34,000 36,000 39,000 42,000 46,000 27,000 28,000 29,000 32,000 34,000 36,000 39,000 42,000 45,000 50,000 28,000 29,000 30,000 34,000 36,000 38,000 42,000 45,000 48,000 54,000 29,000 30,000 31,000 36,000 38,000 40,000 45,000 48,000 51,000 58,000 30,000 31,000 32,000 38,000 40,000 42,000 48,000 51,000 54,000 62,000 12345 Experience Region 1 Region 2 Region = 1 Responsibility level = 1 Experience level = 4 Region = 2 Responsibility level = 4 Experience level = 1 Region = 1 Responsibility level = 4 Experience level = 1

21 SALARY-TABLE EXP (1) 26000 EXP (2) 27000 EXP (3) 28000 EXP (4) 30000 EXP (5) 32000 SALARY (1) 46000 SALARY (2) 50000... RESPONSIBILITY (1)RESPONSIBILITY (10)... SALARY-VALUES (c) Storage Schematic Two-Level Table 01 SALARY-VALUES. 05 FILLERPIC X(5)VALUE ‘2600027000280002900030000’. 05 FILLERPIC X(5)VALUE ‘2700028000290003000031000’. 05 FILLERPIC X(5)VALUE ‘2800029000300003100032000’. 05 FILLERPIC X(5)VALUE ‘3000032000340003600038000’. 05 FILLERPIC X(5)VALUE ‘3200034000360003800040000’. 05 FILLERPIC X(5)VALUE ‘3400036000380004000042000’. 05 FILLERPIC X(5)VALUE ‘3600039000420004500048000’. 05 FILLERPIC X(5)VALUE ‘3900042000450004800051000’. 05 FILLERPIC X(5)VALUE ‘4200045000480005100054000’. 05 FILLERPIC X(5)VALUE ‘4600050000540005800062000’. 01 SALARY-TABLE REDEFINES SALARY-VALUES. 05 RESPONSIBILITY OCCURS 10 TIMES. 10 EXPERIENCE OCCURS 5 TIMES. 15 SALARYPIC 9(5). (b) Initialization via the REDEFINES and VALUES Clauses

22 Two-Level Table Responsibility level = 1 Experience level = 4 Responsibility 1 2 3 4 5 6 7 8 9 10 26,000 27,000 28,000 30,000 32,000 34,000 36,000 39,000 42,000 46,000 27,000 28,000 29,000 32,000 34,000 36,000 39,000 42,000 45,000 50,000 28,000 29,000 30,000 34,000 36,000 38,000 42,000 45,000 48,000 54,000 29,000 30,000 31,000 36,000 38,000 40,000 45,000 48,000 51,000 58,000 30,000 31,000 32,000 38,000 40,000 42,000 48,000 51,000 54,000 62,000 12345Experience Responsibility level = 4 Experience level = 1 (a) User’s View

23 PERFORM VARYING with Two Subscripts PERFORM INITIALIZE-SALARIES VARYING RESPONSIBILITY-SUB FROM 1 BY 1 UNTIL RESPONSIBILITY-SUB > 10 AFTER EXPERIENCE-SUB FROM 1 BY 1 UNTIL EXPERIENCE-SUB > 5.... INITIALIZE-SALARIES. MOVE ZERO TO SALARY (RESPONSIBILITY-SUB, EXPERIENCE-SUB). PERFORM VARYING RESPONSIBILITY-SUB FROM 1 BY 1 UNTIL RESPONSIBILITY-SUB > 10 AFTER EXPERIENCE-SUB FROM 1 BY 1 UNTIL EXPERIENCE-SUB > 5 MOVE ZERO TO SALARY (RESPONSIBILITY-SUB, EXPERIENCE-SUB) END-PERFORM (a) Performing a Paragraph (b) In-Line Perform

24 2-level Table continued (c) Variation of Subscripts 1 1 1 2 1 3 1 4 1 5 2 1 2 2 2 3 2 4 2 5 10 1 10 2 10 3 10 4 10 5... Responsibility Subscript Experience Subscript RESPONSIBILITY-SUB is set to 1 while EXPERIENCE-SUB varies from 1 to 5 RESPONSIBILITY-SUB is set to 2 while EXPERIENCE-SUB varies from 1 to 5 RESPONSIBILITY-SUB reaches 10 and EXPERIENCE-SUB varies from 1 to 5


Download ppt "One & Two dimensional Tables Cont.. Table of Major Codes 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE."

Similar presentations


Ads by Google