Chapter 13 Mutlilevel Tables System Concepts User View
Chapter 13 - Mutlilevel Tables • System Concepts – User View of tables • one dimension view • two dimension view • three dimension view 1
Figure 13. 1 1 2 3 4 5 Responsibility 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 Multilevel Tables Responsibility level = 4 (a) One-Level Table 2
Figure 13. 1 Multilevel Tables Responsibility level = 1 Experience level = 4 Responsibility level = 4 Experience level = 1 Experience 1 2 3 4 5 Responsibility 6 7 8 9 10 1 26, 000 27, 000 28, 000 30, 000 32, 000 34, 000 36, 000 39, 000 42, 000 46, 000 2 27, 000 28, 000 29, 000 32, 000 34, 000 36, 000 39, 000 42, 000 45, 000 50, 000 3 28, 000 29, 000 30, 000 34, 000 36, 000 38, 000 42, 000 45, 000 48, 000 54, 000 4 29, 000 30, 000 31, 000 36, 000 38, 000 40, 000 45, 000 48, 000 51, 000 58, 000 5 30, 000 31, 000 32, 000 38, 000 40, 000 42, 000 48, 000 51, 000 54, 000 62, 000 (b) Two-Level Table 3
Figure 13. 1 Multilevel Tables Region = 2 Responsibility level = 4 Experience level = 1 Region 2 Region 1 Experience 1 2 3 Responsibility 4 Experience 15 6 1 26, 000 7 2 27, 000 8 3 28, 000 9 4 30, 000 10 5 32, 000 Responsibility 6 7 8 9 10 34, 000 36, 000 39, 000 42, 000 46, 000 1 28, 000 29, 000 30, 000 32, 000 2 34, 000 27, 000 36, 000 28, 000 39, 000 29, 000 42, 000 32, 000 46, 000 34, 000 36, 000 39, 000 42, 000 45, 000 50, 000 2 29, 000 30, 000 31, 000 34, 000 3 36, 000 28, 000 39, 000 29, 000 42, 000 30, 000 45, 000 34, 000 50, 000 36, 000 38, 000 42, 000 45, 000 48, 000 54, 000 3 30, 000 31, 000 32, 000 36, 000 4 38, 000 29, 000 42, 000 30, 000 45, 000 31, 000 48, 000 36, 000 54, 000 38, 000 40, 000 45, 000 48, 000 51, 000 58, 000 4 31, 000 32, 000 33, 000 38, 000 5 40, 000 30, 000 45, 000 31, 000 48, 000 32, 000 51, 000 38, 000 58, 000 40, 000 42, 000 48, 000 51, 000 54, 000 62, 000 (c) Three-Level Table Region = 2 Responsibility level = 4 Experience level = 1 5 32, 000 33, 000 34, 000 40, 000 42, 000 44, 000 50000 53, 000 56, 000 64, 000 Region = 1 Responsibility level = 4 Experience level = 1 Region = 1 Responsibility level = 1 Experience level 4 = 4
• COBOL Implementation – Review of OCURS & REDEFINES clauses – Review of PERFORM VARYING statement – Representation of data storage and memory allocation 5
Figure 13. 2 One-Level Table 1 2 3 4 5 6 7 8 9 10 Responsibility 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 FILLER 05 FILLER 05 FILLER PIC PIC PIC X(5) X(5) X(5) VALUE VALUE VALUE ‘ 26000’. ‘ 27000’. ‘ 28000’. ‘ 30000’. ‘ 32000’. ‘ 34000’. ‘ 36000’. ‘ 39000’. ‘ 42000’. ‘ 46000’. 01 SALARY-TABLE REDEFINES SALARY-VALUES. 05 SALARY OCCURS 10 TIMES PIC 9(5). (b) Initialization via the REDEFINES and VALUES Clauses SALARY (1) 2 6 0 0 SALARY (2) 0 2 7 0 0 SALARY-TABLE SALARY (4) SALARY (5) SALARY (3) 0 2 8 0 0 0 3 2 0 0 SALARY (6) 0 3 4 0 0 0 . . . SALARY (10) 4 6 6 (c) Storage Schematic 0 0 0
Figure 13. 3 Two-Level Table Responsibility level = 1 Experience level = 4 Responsibility level = 4 Experience level = 1 1 2 3 4 5 1 26, 000 27, 000 28, 000 29, 000 30, 000 2 27, 000 28, 000 29, 000 30, 000 31, 000 32, 000 4 30, 000 32, 000 34, 000 36, 000 38, 000 5 32, 000 34, 000 36, 000 38, 000 40, 000 6 34, 000 36, 000 38, 000 40, 000 42, 000 7 36, 000 39, 000 42, 000 45, 000 48, 000 8 39, 000 42, 000 45, 000 48, 000 51, 000 9 42, 000 45, 000 48, 000 51, 000 54, 000 10 46, 000 50, 000 54, 000 58, 000 62, 000 Experience Responsibility (a) User’s View 7
Figure 13. 3 Two-Level Table 01 SALARY-VALUES. 05 FILLER 05 FILLER 05 FILLER PIC PIC PIC X(5) X(5) X(5) VALUE VALUE VALUE ‘ 2600027000280002900030000’. ‘ 2700028000290003000031000’. ‘ 2800029000300003100032000’. ‘ 3000032000340003600038000’. ‘ 3200034000360003800040000’. ‘ 3400036000380004000042000’. ‘ 3600039000420004500048000’. ‘ 3900042000450004800051000’. ‘ 4200045000480005100054000’. ‘ 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 SALARY-TABLE RESPONSIBILITY (1) EXP (2) RESPONSIBILITY (10). EXP (3) EXP (4) EXP (5) SALARY (1) . . SALARY (2) . . . 2 6 0 0 0 2 7 0 0 0 2 8 0 0 0 3 2 0 0 0 4 6 0 0 0 5 0 SALARY-VALUES 8 (c) Storage Schematic 0 0 0
• 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. 9
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). (a) Performing a Paragraph 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 (b) In-Line Perform 10
Figure 13. 4 continued Responsibility Subscript Experience Subscript 1 1 1 2 3 4 5 2 2 2 1 2 3 4 5 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 . . . 10 10 10 1 2 3 4 5 RESPONSIBILITY-SUB reaches 10 and EXPERIENCE-SUB varies from 1 to 5 (c) Variation of Subscripts 11
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 12
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). 13
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) 14
• 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 15
Figure 13. 10 Three-Level Tables Region = 2 Responsibility level = 4 Experience level = 1 Region 2 Region 1 Experience 1 2 3 Responsibility 4 1 5 Experience 6 1 26, 000 7 2 27, 000 8 3 28, 000 9 4 30, 000 10 5 32, 000 Responsibility 6 34, 000 7 36, 000 8 39, 000 9 42, 000 10 46, 000 1 28, 000 29, 000 30, 000 32, 000 2 34, 000 27, 000 36, 000 28, 000 39, 000 29, 000 42, 000 32, 000 46, 000 34, 000 2 29, 000 30, 000 31, 000 34, 000 3 36, 000 28, 000 39, 000 29, 000 42, 000 30, 000 45, 000 34, 000 50, 000 36, 000 3 30, 000 31, 000 32, 000 36, 000 4 38, 000 29, 000 42, 000 30, 000 45, 000 31, 000 48, 000 36, 000 54, 000 38, 000 4 31, 000 32, 000 33, 000 38, 000 5 40, 000 30, 000 45, 000 31, 000 48, 000 32, 000 51, 000 38, 000 58, 000 40, 000 36, 000 39, 000 42, 000 45, 000 50, 000 38, 000 42, 000 45, 000 48, 000 54, 000 40, 000 45, 000 48, 000 51, 000 58, 000 42, 000 48, 000 51, 000 54, 000 62, 000 (a) User’s View Region = 2 Responsibility level = 4 Experience level = 1 5 32, 000 33, 000 34, 000 40, 000 42, 000 44, 000 50000 53, 000 56, 000 64, 000 Region = 1 Responsibility level = 4 Experience level = 1 Region = 1 Responsibility level = 1 Experience level = 4 16
Figure 13. 10 Three-Level Tables 01 SALARY-VALUES. 03 REGION-ONE. 05 FILLER 05 FILLER 05 FILLER PIC PIC PIC X(5) X(5) X(5) VALUE VALUE VALUE ‘ 2600027000280002900030000’. ‘ 2700028000290003000031000’. ‘ 2800029000300003100032000’. ‘ 3000032000340003600038000’. ‘ 3200034000360003800040000’. ‘ 3400036000380004000042000’. ‘ 3600039000420004500048000’. ‘ 3900042000450004800051000’. ‘ 4200045000480005100054000’. ‘ 4600050000540005800062000’. 03 REGION-TWO. 05 FILLER 05 FILLER 05 FILLER PIC PIC PIC X(5) X(5) X(5) VALUE VALUE VALUE ‘ 2800029000300003100032000’. ‘ 2900030000310003200033000’. ‘ 3000031000320003300034000’. ‘ 3200034000360003800040000’. ‘ 3400036000380004000042000’. ‘ 3600038000400004200044000’. ‘ 3800041000440004700050000’. ‘ 4100044000470005000053000’. ‘ 4400047000500005300056000’. ‘ 480005200056000064000’. 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 17
Figure 13. 10 Three-Level Tables SALARY-TABLE REGION (1) RESPONSIBILITY (1) EXP (2) 2 6 0 0 0 2 7 0 0 0 2 EXP (3) EXP (4) REGION (2) RESPONSIBILITY (10) EXP (5) 80 0 0 3 2 0 0 0 . . . EXP (1) EXP (2) 2 6 0 0 0 2 7 0 0 0 2 EXP (3) EXP (4) RESPONSIBILITY (1) EXP (5) EXP (1) EXP (2) 80 0 0 3 2 0 0 0 2 6 0 0 0 2 7 0 0 0 2 EXP (3) EXP (4) RESPONSIBILITY (10) EXP (5) 80 0 0 3 2 0 0 0 . . . EXP (1) EXP (2) 2 6 0 0 0 2 7 0 0 0 2 EXP (3) EXP (4) EXP (5) 80 0 0 3 2 0 0 0 SALARY-VALUES (c) Storage Schematic 18
• How to reference SALARY (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 1 st region 19
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. 20
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 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. (b) In-Line Perform 21
Figure 13. 11 ( c) Variation of Subscripts Region Responsibility Subscript Experience Subscript 1 1 1 2 3 4 5 REGION-SUB and RESPONSIBILITY-SUB are both set to 1 while EXPERIENCE-SUB varies from 1 to 5 1 1 1 2 2 2 1 2 3 4 5 REGION-SUB remains at 1 while RESPONSIBILITY -SUB is incremented to 2 and EXPERIENCE-SUB is again varied from 1 to 5 1 1 10 10 10 1 2 3 4 5 2 2 2 1 1 1 2 3 4 5 REGION-SUB is incremented to 2, RESPONSIBILITY-SUB is reset to 1 while EXPERIENCE-SUB varies from 1 to 5 2 2 2 10 10 10 1 2 3 4 5 At the 100 th iteration, REGION-SUB reaches 2, RESPONSIBILITY-SUB has reaches 10, EXPERIENCE-SUB reaches 5. 22 . . . At the 50 th iteration, REGION-SUB is still set to 1, but RESPONSIBILITY-SUB has reached 10. .
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 23
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. 24
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 25
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) 26
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. 27
Given the following table definition: 01 CORPORATE-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) 28
Indicate the appropriate storage schematic 29
Write a PERFORM VARYING statement to determine the annual sales for the third branch office. 30
Write a PERFORM VARYING statement to determine the corporate sales for May. 31
Write a PERFORM VARYING statement to determine the corporate sales for the entire year. 32
What are the differences between 1 & 2 & 3 level tables? 33
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 S 9(5)V 99: Add room for 3 tables: 34
From the original table, code the statement that adds the 1 st element of the 1 st row and the 3 rd element of the 2 nd row and puts the result in the last element of the 4 th row: 35
Write the code to determine how many elements are equal in the first 2 rows of ATABLE. 36
Write the code to find the element in each row that is equal to A-ITEM. If found perform PARA-A else perform ERRORRTN. 37
• Table lookups – Two level lookup – Program specifications – Range-step tables – Program Listing 38
- Slides: 38