1 chapter 13 - mutlilevel tables system concepts –user view of tables one dimension view two...

38
1 Chapter 13 - Mutlilevel Tables • System Concepts – User View of tables • one dimension view • two dimension view • three dimension view

Upload: jocelin-leonard

Post on 17-Jan-2016

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

1

Chapter 13 - Mutlilevel Tables

• System Concepts– User View of tables

• one dimension view• two dimension view• three dimension view

Page 2: 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

Page 3: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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

Page 4: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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

Page 5: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

5

• COBOL Implementation– Review of OCURS & REDEFINES clauses– Review of PERFORM VARYING statement– Representation of data storage and

memory allocation

Page 6: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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

Page 7: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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

Page 8: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension 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

Page 9: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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.

Page 10: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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

Page 11: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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

Page 12: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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

Page 13: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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).

Page 14: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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)

Page 15: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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

Page 16: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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

Page 17: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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

Page 18: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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)

Page 19: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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

Page 20: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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.

Page 21: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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.

Page 22: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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.

Page 23: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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

Page 24: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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.

Page 25: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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

Page 26: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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)

Page 27: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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.

Page 28: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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)

Page 29: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

29

Indicate the appropriate storage schematic

Page 30: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

30

Write a PERFORM VARYING statement to determine the annual sales for the third branch office.

Page 31: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

31

Write a PERFORM VARYING statement to determine the corporate sales for May.

Page 32: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

32

Write a PERFORM VARYING statement to determine the corporate sales for the entire year.

Page 33: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

33

What are the differences between 1 & 2 & 3 level tables?

Page 34: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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:

Page 35: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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:

Page 36: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

36

Write the code to determine how many elements are equal in the first 2 rows of A-TABLE.

Page 37: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

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.

Page 38: 1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view

38

• Table lookups– Two level lookup– Program specifications– Range-step tables– Program Listing