1
Chapter 13 - Mutlilevel Tables
• System Concepts– User View of tables
• one dimension view• two dimension view• three dimension view
2
Figure 13.1 Multilevel Tables
Responsibility
123456789
10
26,00027,00028,00030,00032,00034,00036,00039,00042,00046,000
Responsibility level = 4
(a) One-Level Table
3
Figure 13.1 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
4
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
Figure 13.1 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
5
• COBOL Implementation– Review of OCURS & REDEFINES clauses– Review of PERFORM VARYING statement– Representation of data storage and
memory allocation
6
Figure 13.2 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
7
Figure 13.3 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
8
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
Figure 13.3 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
9
• Two level tables– Syntax
• Additional OCCURS clause• Representation of data storage and memory
allocation
– Errors in compilation• Incorrect number of subscripts• Wrong Sequence• Invalid subscript• Examples
– SALARY (6, 5), SALARY (5, 6)– SALARY-TABLE, RESPONSIBILITY (1)– EXPERIENCE (6, 5) same as salary(6,5) because
salary is the only item under experience.
10
Figure 13.4 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
11
Figure 13.4 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
12
Write out the 12 pair of values that will be assumed by SUB-1 and SUB-2 as a result of the statement:
PERFORM 10-PROCESS-TABLE
VARYING SUB-1 FROM 1 BY 1
UNTIL SUB-1 > 4
AFTER SUB-2 FROM 1 BY 1
UNTIL SUB-2 > 3
13
Given:
01 CORPORATE-DATA.
05 COMPANY OCCURS 10 TIMES
10 DIVISION-NAME PIC X (15).
10 YEARLY-FINANCIAL-DATA OCCURS 4 TIMES.
15 REVENUE PIC 9(7).
15 NET-INCOME PIC 9(7).
14
a. Indicate the storage schematic
b. State whether the following are valid references. If not is error during compile or exe
i. CORPORATE-DATA
ii. COMPANY
iii. COMPANY (8)
iv. DIVISION-NAME (8)
v. DIVISION-NAME (12)
vi. YEARLY-FINANCIAL-DATA (4)
vii. REVENUE (10,4)
viii. NET-INCOME (10,4)
ix. REVENUE (4,10)
15
• Three Level Tables– Addition of third OCCURS clause– Subscripting order and requirements
• In order of occurs clauses
– Representation of data storage and memory allocation
– PERFORM VARYING statement in three dimension tables
16
(a) User’s View
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
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
Figure 13.10 Three-Level Tables
17
Figure 13.10 Three-Level Tables
01 SALARY-VALUES. 03 REGION-ONE. 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’.
03 REGION-TWO. 05 FILLER PIC X(5) VALUE ‘2800029000300003100032000’. 05 FILLER PIC X(5) VALUE ‘2900030000310003200033000’. 05 FILLER PIC X(5) VALUE ‘3000031000320003300034000’. 05 FILLER PIC X(5) VALUE ‘3200034000360003800040000’. 05 FILLER PIC X(5) VALUE ‘3400036000380004000042000’. 05 FILLER PIC X(5) VALUE ‘3600038000400004200044000’. 05 FILLER PIC X(5) VALUE ‘3800041000440004700050000’. 05 FILLER PIC X(5) VALUE ‘4100044000470005000053000’. 05 FILLER PIC X(5) VALUE ‘4400047000500005300056000’. 05 FILLER PIC X(5) VALUE ‘4800052000560006000064000’.
01 SALARY-TABLE REDEFINES SALARY-VALUES. 05 REGION OCCURS 2 TIMES. 10 RESPONSIBILITY OCCURS 10 TIMES. 15 EXPERIENCE OCCURS 5 TIMES. 20 SALARY PIC 9(5).
(b) Initialization via the REDEFINES and VALUES Clauses
18
SALARY-TABLE
SALARY-VALUES
(c) Storage Schematic
Figure 13.10 Three-Level Tables
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
RESPONSIBILITY (1)
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
RESPONSIBILITY (10)
...
REGION (1)
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
RESPONSIBILITY (1)
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
RESPONSIBILITY (10)
...
REGION (2)
19
• How to referenceSALARY (1, 2, 3)
region 1, responsibility 2, experience 3
SALARY (2, 12, 7)
error- no responsibility 12 or experience 7
SALARY-TABLE
entire table of data, no use subscripts
REGION (1)
refers to the 10 responsibility levels, each containing 5 experience levels of the 1st region
20
RESPONSIBILITY (1, 2)
refers to the 5 experience levels for responsibility level 2, region 1. Referenced with 2 subscripts
EXPERIENCE (1, 2, 3)
equivalent to SALARY (1, 2, 3) because SALARY is the only elementary item under the group EXPERIENCE.
21
Figure 13.11 PERFORM VARYING with Three Subscripts
PERFORM INITIALIZE-SALARIES VARYING REGION-SUB FROM 1 BY 1 UNTIL REGION-SUB > 2 AFTER 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 (REGION-SUB, RESPONSIBILITY-SUB, EXPERIENCE-SUB).
(a) Performing a Paragraph
(b) In-Line Perform
PERFORM VARYING REGION-SUB FROM 1 BY 1 UNTIL REGION-SUB > 2 AFTER 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 (REGION-SUB, RESPONSIBILITY-SUB, EXPERIENCE-SUB)END-PERFORM.
22
Figure 13.11 ( c) Variation of Subscripts
1 1 11 1 21 1 31 1 41 1 5
. . .
Responsibility Subscript
ExperienceSubscript
REGION-SUB and RESPONSIBILITY-SUB are both set to 1 while EXPERIENCE-SUB varies from 1 to 5
Region Subscript
1 2 11 2 21 2 31 2 41 2 5
REGION-SUB remains at 1 while RESPONSIBILITY-SUB is incremented to 2 and EXPERIENCE-SUB is again varied from 1 to 5
1 10 11 10 21 10 31 10 41 10 5
At the 50th iteration, REGION-SUB is still set to 1, but RESPONSIBILITY-SUB has reached 10.
2 1 12 1 22 1 32 1 42 1 5
REGION-SUB is incremented to 2, RESPONSIBILITY-SUB is reset to 1 while EXPERIENCE-SUB varies from 1 to 5
2 10 12 10 22 10 32 10 42 10 5
. . .
At the 100th iteration, REGION-SUB reaches 2, RESPONSIBILITY-SUB has reaches 10, EXPERIENCE-SUB reaches 5.
23
Indicate the 24 sets of different subscripts of the following:
PERFORM
VARYING SUB-1 FROM 1 BY 1
UNTIL SUB-1 > 3
AFTER SUB-2 FROM 1 BY 1
UNTIL SUB-2 > 3
AFTER SUB-3 FROM 1 BY 1
UNTIL SUB-3 > 4
24
Write the record structure that will hold data for 2 sections of COBOL, each sections having 40 students, each student will submit 6 projects and take 3 exams.
25
01 ENROLLMENT-DATA.
05 COLLEGE OCCURS 3 TIMES
10 MAJOR CODE OCCURS 50 TIMES
15 YEAR OCCURS 4 TIMES.
20 NUM-OF-STUDENT PIC 9(4).
A. Write the schematic
26
Are the following legal from the previous solution
1. ENROLLMENT-DATA
2. COLLEGE (1)
3. MAJOR (1)
4. YEAR (1)
5. NUMBER-OF-STUDENT (1)
6. NUMBER-OF-STUDENT (1, 2, 3)
7. NUMBER-OF-STUDENT (4, 5, 6)
27
Write the PERFORM VARYING statements to determine
1. The total number of students in the university
2. The total number of seniors in the first college
3. The total number of students in the first major of the first college.
4. The total number of freshmen (year 1) in the first college.
5. The total number of freshmen in the university.
28
Given the following table definition:01CORPORATE-SALES-TABLE
05 BRANCH-OFFICE OCCURS 6 TIMES.
10 BRANCH-NAME PIC X(10).
10 MONTHS OCCURS 12 TIMES.
15 SALES-AMOUNT PIC 9(6)
29
Indicate the appropriate storage schematic
30
Write a PERFORM VARYING statement to determine the annual sales for the third branch office.
31
Write a PERFORM VARYING statement to determine the corporate sales for May.
32
Write a PERFORM VARYING statement to determine the corporate sales for the entire year.
33
What are the differences between 1 & 2 & 3 level tables?
34
Code the DATA division entries necessary to define a table named A-TABLE with 5 rows and 20 columns. Each element of A-TABLE should have a PIC of S9(5)V99:
Add room for 3 tables:
35
From the original table, code the statement that adds the 1st element of the 1st row and the 3rd element of the 2nd row and puts the result in the last element of the 4th row:
36
Write the code to determine how many elements are equal in the first 2 rows of A-TABLE.
37
Write the code to find the element in each row that is equal to A-ITEM. If found perform PARA-A else perform ERROR-RTN.
38
• Table lookups– Two level lookup– Program specifications– Range-step tables– Program Listing