One & Two dimensional Tables Cont.. Table of Major Codes 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL...

33

Transcript of One & Two dimensional Tables Cont.. Table of Major Codes 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL...

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

One & Two dimensional Tables Cont.

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

Table of Major Codes02 ART HISTORY04 BIOLOGY19 CHEMESTRY21 CIVIL ENGINEERING24 COMP INF SYS32 ECONOMICS39 FINANCE43 MANAGEMENT49 MARKETING54 STATISTICS

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

Sequential Table Lookup

02 ART HISTORY

04 BIOLOGY

19 CHEMESTRY

21 CIVIL ENGINEERING

24 COMP INF SYS

32 ECONOMICS

39 FINANCE

43 MANAGEMENT

49 MARKETING

53 STATISTICS

39

1st try

2nd try

3rd try

4th try

5th try

6th try

7th tryFINANCE

Match

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

Binary Lookup

02 ART HISTORY

04 BIOLOGY

19 CHEMESTRY

21 CIVIL ENGINEERING

24 COMP INF SYS

32 ECONOMICS

39 FINANCE

43 MANAGEMENT

49 MARKETING

53 STATISTICS

39

1st try

FINANCEMatch

2nd try

3rd try

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

01 MAJOR-VALUE. 05 FILLER PIC X(14) VALUE ‘02ART HISTORY’. 05 FILLER PIC X(14) VALUE ‘04BIOLOGY’. 05 FILLER PIC X(14) VALUE ‘19CHEMISTRY’. 05 FILLER PIC X(14) VALUE ‘21CIVIL ENG’. 05 FILLER PIC X(14) VALUE ‘24COMP INF SYS’. 05 FILLER PIC X(14) VALUE ‘32ECONOMICS’. 05 FILLER PIC X(14) VALUE ‘39FINANCE’. 05 FILLER PIC X(14) VALUE ‘43MANAGEMENT’. 05 FILLER PIC X(14) VALUE ‘40MARKETING’. 05 FILLER PIC X(14) VALUE ‘54STATISTICS’.

01 MAJOR-TABLE REDEFINES MAJOR-VALUE. 05 MAJORS OCCURS 10 TIMES.

10 MAJOR-CODE PIC 9(2).10 EXPANDED-MAJOR PIC X(12).

Initialization via Hard Coding

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

Table Initialization (Storage Schematic)

0 2 A R T H I S T O R Y 4 B I O L O G Y 0 5 4 S T A T I S T I

MAJOR-VALUE

MAJOR-TABLE

...

CD (1)EXP-MAJOR (1) CD (2) EXP-MAJOR (2) EXP-MAJOR (10)CD (10)

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

19CHEMISTRY

Input-Loaded Tables

04BIOLOGY

02ART HISTORY

02 ART HISTORY 04 BIOLOGY 19 CHEMISTRY

MAJOR-CODE (1)

EXPANDED-MAJOR (1)

MAJOR-CODE (2)

EXPANDED-MAJOR (2)

MAJOR-CODE (3)

EXPANDED-MAJOR (3)

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

Loading from an input file

FD TAX-FILE. 01 TAX-RECORD. 05 ZIPCODE-IN PIC 9(5). 05 TAX-RATE-IN PIC V999 COMP-3.

WORKING-STORAGE SECTION.

READ TAX-FILE INTO TABLE-ENTRIES (SUB) AT END DISPLAY 'NOT ENOUGH TABLE RECORDS' PERFORM 300-TERMINATION-RTN STOP RUN END-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.

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

Sequential Lookup with PERFORM VARYING

WORKING-STORAGE SECTION.01 TABLE-PROCESSING-ELEMENTS. 05 WS-MAJOR-SUB PIC S9(4) COMP. 05 WS-FOUND-MAJOR-SWITCH PIC X(3) VALUE ‘NO’. 05 WS-END-OF-TABLE-SWITCH PIC X(3) VALUE ‘NO’.

01 MAJOR-VALUE. 05 FILLER PIC X(14) VALUE ‘02ART HISTORY’. 05 FILLER PIC X(14) VALUE ‘04BIOLOGY’. 05 FILLER PIC X(14) VALUE ‘19CHEMISTRY’. 05 FILLER PIC X(14) VALUE ‘21CIVIL ENG’. 05 FILLER PIC X(14) VALUE ‘24COMP INF SYS’. 05 FILLER PIC X(14) VALUE ‘32ECONOMICS’. 05 FILLER PIC X(14) VALUE ‘39FINANCE’. 05 FILLER PIC X(14) VALUE ‘43MANAGEMENT’. 05 FILLER PIC X(14) VALUE ‘40MARKETING’. 05 FILLER PIC X(14) VALUE ‘54STATISTICS’.

01 MAJOR-TABLE REDEFINES MAJOR-VALUE. 05 MAJORS OCCURS 10 TIMES.

10 MAJOR-CODE PIC 9(2).10 EXPANDED-MAJOR PIC X(12).

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

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-SWITCHMOVE ‘UNKNOWN’ TO HDG-MAJOR

ELSEIF ST-MAJ0R-CODE = MAJOR-CODE (WS-MAJOR-SUB) MOVE ‘YES’ TO WS-FOUND-MAJOR-SWITCH MOVE EXP-MAJOR (WS-MAJOR-SUB) TO HDG-MAJOREND-IF

END-IF.

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

SEARCH Statement (Sequential Lookup)

01 MAJOR-VALUE. 05 FILLER PIC X(14) VALUE ‘02ART HISTORY’. 05 FILLER PIC X(14) VALUE ‘04BIOLOGY’. 05 FILLER PIC X(14) VALUE ‘19CHEMISTRY’. 05 FILLER PIC X(14) VALUE ‘21CIVIL ENG’. 05 FILLER PIC X(14) VALUE ‘24COMP INF SYS’. 05 FILLER PIC X(14) VALUE ‘32ECONOMICS’. 05 FILLER PIC X(14) VALUE ‘39FINANCE’. 05 FILLER PIC X(14) VALUE ‘43MANAGEMENT’. 05 FILLER PIC X(14) VALUE ‘40MARKETING’. 05 FILLER PIC X(14) VALUE ‘54STATISTICS’.

01 MAJOR-TABLE REDEFINES MAJOR-VALUE. 05 MAJORS OCCURS 10 TIMES INDEXED BY MAJOR-INDEX.

10 MAJOR-CODE PIC 9(2).10 EXPANDED-MAJOR PIC X(12).

. . .

INDEXED BY clause required in table definition

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

SEARCH Statement (Sequential Lookup)

PROCEDURE DIVISION.. .

.SET MAJOR-INDEX TO 1.SEARCH MAJORS

AT END MOVE ‘UNKNOWN’ TO HDG-MAJORWHEN ST-MAJOR-CODE = MAJOR-CODE (MAJOR-INDEX) MOVE EXP-MAJOR (MAJOR-INDEX) TO HDG-MAJOR

END-SEARCH.

SET statement establishes starting point

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

Indexes versus Subscripts

INDEXES SUBSCRIPTS

Defined with a specific table; can be used Defined in Working-Storage; the same subscript 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 subscriptssubscripts more efficient, although indexes are still faster

To change: Use PERFORM .. VARYING or To Change: Use PERFORM … VARYING SET or MOVE, ADD, SUBTRACT 1

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

SEARCH ALL Statement (Binary Lookup)

KEY required for binary search (ASCENDING or DESCENDING)

01 MAJOR-VALUE. 05 FILLER PIC X(10) VALUE ‘02ART HISTORY’. 05 FILLER PIC X(10) VALUE ‘04BIOLOGY’. 05 FILLER PIC X(10) VALUE ‘19CHEMISTRY’. 05 FILLER PIC X(10) VALUE ‘21CIVIL ENG’. 05 FILLER PIC X(10) VALUE ‘24COMP INF SYS’. 05 FILLER PIC X(10) VALUE ‘32ECONOMICS’. 05 FILLER PIC X(10) VALUE ‘39FINANCE’. 05 FILLER PIC X(10) VALUE ‘43MANAGEMENT’. 05 FILLER PIC X(10) VALUE ‘40MARKETING’. 05 FILLER PIC 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-CODE PIC 9(2).10 EXPANDED-MAJOR PIC X(12).

. . .

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

SEARCH ALL Statement (Binary Lookup)

PROCEDURE DIVISION.. .

.SEARCH ALL MAJORS

AT END MOVE ‘UNKNOWN’ TO HDG-MAJORWHEN MAJOR-CODE (MAJOR-INDEX) = ST-MAJOR-CODE

MOVE EXP-MAJOR (MAJOR-INDEX) TO HDG-MAJOREND-SEARCH.

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

Implements a sequential lookup

Requires a SET statement prior to SEARCH to establish the initial position in the table

Does not require codes in the table to be in any special sequence

Contains an optional VARYING clause

May specify more than one WHEN clause

Implements a binary lookup Does not require an initial

SET statement (calculates its own starting position

Requires the codes to be in ascending or descending sequence on the associated KEY clause in the table definition

Does not contain a VARYING clause

Restricted to a single WHEN clause

SEARCH versus SEARCH ALL

SEARCH SEARCH ALL

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

Multilevel Tables

Responsibility

123456789

10

26,00027,00028,00030,00032,00034,00036,00039,00042,00046,000

Responsibility level = 4

(a) One-Level Table

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

Multilevel Tables

Responsibility level = 1Experience level = 4

Responsibility

123456789

10

26,00027,00028,00030,00032,00034,00036,00039,00042,00046,000

27,00028,00029,00032,00034,00036,00039,00042,00045,00050,000

28,00029,00030,00034,00036,00038,00042,00045,00048,00054,000

29,00030,00031,00036,00038,00040,00045,00048,00051,00058,000

30,00031,00032,00038,00040,00042,00048,00051,00054,00062,000

1 2 3 4 5Experience

Responsibility level = 4Experience level = 1

(b) Two-Level Table

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

One-Level Table

Responsibility

12345678910

26,00027,00028,00030,00032,00034,00036,00039,00042,00046,000

Responsibility level = 4

(a) User’s View01 SALARY-VALUES. 05 FILLER PIC X(5) VALUE ‘26000’. 05 FILLER PIC X(5) VALUE ‘27000’. 05 FILLER PIC X(5) VALUE ‘28000’. 05 FILLER PIC X(5) VALUE ‘30000’. 05 FILLER PIC X(5) VALUE ‘32000’. 05 FILLER PIC X(5) VALUE ‘34000’. 05 FILLER PIC X(5) VALUE ‘36000’. 05 FILLER PIC X(5) VALUE ‘39000’. 05 FILLER PIC X(5) VALUE ‘42000’. 05 FILLER PIC X(5) VALUE ‘46000’.

01 SALARY-TABLE REDEFINES SALARY-VALUES. 05 SALARY OCCURS 10 TIMES PIC 9(5).

(b) Initialization via the REDEFINES and VALUES ClausesSALARY-TABLE

SALARY (1)

2 6 0 0 0

SALARY (2)

2 7 0 0 0

SALARY (3)

2 8 0 0 0

SALARY (4)

3 0 0 0 0

SALARY (5)

3 2 0 0 0

SALARY (6)

3 4 0 0 0

SALARY (10)

4 6 0 0 0. . .

(c) Storage Schematic

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

Responsibility

123456789

10

28,00029,00030,00032,00032,00034,00036,00039,00042,00046,000

29,00030,00031,00034,00034,00036,00039,00042,00045,00050,000

30,00031,00032,00036,00036,00038,00042,00045,00048,00054,000

31,00032,00033,00038,00038,00040,00045,00048,00051,00058,000

32,00033,00034,00040,00042,00044,0005000053,00056,00064,000

1 2 3 4 5Experience

Multilevel Tables

(c) Three-Level Table

Responsibility

123456789

10

26,00027,00028,00030,00032,00034,00036,00039,00042,00046,000

27,00028,00029,00032,00034,00036,00039,00042,00045,00050,000

28,00029,00030,00034,00036,00038,00042,00045,00048,00054,000

29,00030,00031,00036,00038,00040,00045,00048,00051,00058,000

30,00031,00032,00038,00040,00042,00048,00051,00054,00062,000

1 2 3 4 5ExperienceRegion 1

Region 2

Region = 1Responsibility level = 1Experience level = 4

Region = 2Responsibility level = 4Experience level = 1

Region = 2Responsibility level = 4Experience level = 1

Region = 1Responsibility level = 4Experience level = 1

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

SALARY-TABLE

EXP (1)

2 6 0 0 0

EXP (2)

2 7 0 0 0

EXP (3)

2 8 0 0 0

EXP (4)

3 0 0 0 0

EXP (5)

3 2 0 0 0

SALARY (1)

4 6 0 0 0

SALARY (2)

5 0 0 0 0

. . .

RESPONSIBILITY (1) RESPONSIBILITY (10) . . .

SALARY-VALUES

(c) Storage Schematic

Two-Level Table

01 SALARY-VALUES. 05 FILLER PIC X(5) VALUE ‘2600027000280002900030000’. 05 FILLER PIC X(5) VALUE ‘2700028000290003000031000’. 05 FILLER PIC X(5) VALUE ‘2800029000300003100032000’. 05 FILLER PIC X(5) VALUE ‘3000032000340003600038000’. 05 FILLER PIC X(5) VALUE ‘3200034000360003800040000’. 05 FILLER PIC X(5) VALUE ‘3400036000380004000042000’. 05 FILLER PIC X(5) VALUE ‘3600039000420004500048000’. 05 FILLER PIC X(5) VALUE ‘3900042000450004800051000’. 05 FILLER PIC X(5) VALUE ‘4200045000480005100054000’. 05 FILLER PIC X(5) VALUE ‘4600050000540005800062000’.

01 SALARY-TABLE REDEFINES SALARY-VALUES. 05 RESPONSIBILITY OCCURS 10 TIMES. 10 EXPERIENCE OCCURS 5 TIMES. 15 SALARY PIC 9(5).

(b) Initialization via the REDEFINES and VALUES Clauses

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

Two-Level TableResponsibility level = 1Experience 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

1 2 3 4 5Experience

Responsibility level = 4Experience level = 1

(a) User’s View

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

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

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

2-level Table continued

(c) Variation of Subscripts

1 11 21 31 41 5

2 12 22 32 42 5

10 110 210 310 410 5

. . .

Responsibility Subscript

ExperienceSubscript

RESPONSIBILITY-SUB is set to 1 whileEXPERIENCE-SUB varies from 1 to 5

RESPONSIBILITY-SUB is set to 2 whileEXPERIENCE-SUB varies from 1 to 5

RESPONSIBILITY-SUB reaches 10 andEXPERIENCE-SUB varies from 1 to 5