Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several...
-
Upload
gwendoline-fox -
Category
Documents
-
view
228 -
download
1
Transcript of Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several...
![Page 1: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/1.jpg)
1
Chapter 6
Structured Data
![Page 2: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/2.jpg)
2
Structured Data
• A data structure, or record, in COBOL is a method of combining several variables into one larger variable.– Example:
![Page 3: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/3.jpg)
3
Structured Data
• THE-WHOLE-MESSAGE is a structure variable or simply a structure.
• It is occasionally referred to as a compound variable or compound data.
• In a structure variable, the highest-level variable (the one that includes all the individual variables) has the level number 01.
• The 01 level must appear in Area A (columns 8 through 12).• The structure variable name appears in Area B (columns 12
through 72), and it does not have a PICTURE. • The variables that fall within the structure begin with numbers
higher than 01, and start in Area B (columns 12 through 72).
![Page 4: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/4.jpg)
4
Structured Data
• You can use the individual variables within a structure in the program as though they still were level 01 variables.
• In addition, you can use the structure variable as a variable. – For example, if all the variables within a structure
variable can be displayed, the structure variable itself can be displayed as a variable
![Page 5: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/5.jpg)
5
Structured Data
![Page 6: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/6.jpg)
6
Filler and How to use it?
![Page 7: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/7.jpg)
7
Filler and How to use it?
• They are used to format part of the display and are assigned values in the definition, but nothing is ever moved to these values in the program.
• They exist only to fill out THE-WHOLE-MESSAGE.
• this type of value in a structure variable can be defined as a filler by using the COBOL reserved word FILLER.
![Page 8: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/8.jpg)
8
Filler and How to use it?
![Page 9: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/9.jpg)
9
Filler and How to use it?
• A FILLER cannot be treated as a variable. • It is used to reserve space in a structure
variable. • You can assign a PICTURE and a VALUE to a
FILLER when it is defined, but you cannot use MOVE with FILLER.
![Page 10: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/10.jpg)
10
Calculating length of Data Structure
• A data structure is actually a series of individual variables, laid end to end in memory.
• The length of a simple data structure, such as this one (see example at next slide) used to create a displayable message, is the sum of all the lengths of the individual parts.
![Page 11: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/11.jpg)
11
Calculating length of Data Structure
![Page 12: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/12.jpg)
12
Calculating length of Data Structure
• A structure variable is treated as an alphanumeric variable. It has an implied PICTURE of X(nn), where nn is equal to the length of the structure variable.
• THE-WHOLE-MESSAGE has an implicit PICTURE of X(61).
![Page 13: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/13.jpg)
13
Calculating length of Data Structure
• You can move a value to a structure variable, but the move will affect the entire length of the variable.
• A structure variable and the variables that are the elements of a structure occupy the same memory area.
• When a variable is created by the compiler, it sets aside a number of bytes in memory that can be used to hold data.
![Page 14: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/14.jpg)
14
Calculating length of Data Structure
![Page 15: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/15.jpg)
15
Calculating length of Data Structure
• Compare figure 8.2 and figure 8.3• The two fillers, as well as EMP-NUMBER and EMP-
HOURLY, occupy some bytes that are in the same space in memory as the structure variable EMPLOYEE-DATA.
• When you use a command in COBOL to modify a variable in memory, the command looks at variables in memory as individual units.
• If you move a value to EMP-NUMBER, or use ADD 1 TO– EMP-NUMBER, COBOL acts on EMP-NUMBER as if it were a
single variable and ignores the fact that EMP-NUMBER is part of the structure EMPLOYEE-DATA.
![Page 16: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/16.jpg)
16
Calculating length of Data Structure
• If you move a message to EMPLOYEE-DATA, the command treats EMPLOYEE-DATA as if it were a PIC X(20) (the implied picture) and ignores the fact that EMPLOYEE-DATA has smaller variables within it.– Example
![Page 17: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/17.jpg)
17
Calculating length of Data Structure
• The variables in EMPLOYEE-DATA do not disappear, but the MOVE affects all 20 bytes of memory.
• The individual variables might no longer contain data that is correct for that variable type.
• From the figure:– EMP-NUMBER now contains ore, which certainly is not
valid numeric data. – This isn't a problem as long as you don't use a
command on EMP-NUMBER, such as ADD 1 TO EMP-NUMBER. I'll return to this issue in a moment.
![Page 18: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/18.jpg)
18
Calculating length of Data Structure
• This use of a structure variable is fairly common in display and print programs that might use a structure to format and display information line by line, and then at the end of the program might move a message to the entire structure and display it.
![Page 19: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/19.jpg)
19
Nested Structure Variables
• Any structure can contain another structure.
• The indention makes it clear that these variables are subordinate to THE-MESSAGE.
![Page 20: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/20.jpg)
20
Nested Structured Variables
• Refer to coding 1.• To calculate the length of a structure variable
containing one or more other structure variables.
![Page 21: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/21.jpg)
21
Misusing Structures
• It is common to find programs that define data structures in WORKING-STORAGE that never are used as structures.
• Grouping variables together under a structure variable because they are similar or to keep things tidy isn't a good practice.
• It is better to use comments in WORKING-STORAGE to separate groups of variables used for different purposes.
![Page 22: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/22.jpg)
22
Level 77
• When you see data in a structure in a program, you assume that the structure is used somewhere in the program as a structure, and you can be confused if it is not.
• A variable that is not a structure can be given a level number of 77 instead of 01:– For examples , see next slide
![Page 23: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/23.jpg)
23
Level 77
![Page 24: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/24.jpg)
24
Level 88
• Level 88 is a special level number used to improve the readability of COBOL programs and to improve IF tests.
• A level 88 looks like a level under another variable, – It does not have a PICTURE, – but it does have a value.
![Page 25: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/25.jpg)
25
Level 88
• A level 88 is always associated with another variable and is a condition name for that variable.
• Both of the following conditions test whether YES-NO is equal to "Y":
![Page 26: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/26.jpg)
26
Level 88
![Page 27: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/27.jpg)
27
Level 88
![Page 28: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/28.jpg)
28
Level 88
![Page 29: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/29.jpg)
29
Level 88
![Page 30: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/30.jpg)
30
Level 88
![Page 31: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/31.jpg)
31
Level 88
![Page 32: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/32.jpg)
32
Q&A
• Q What happens if I move to a FILLER?– A You can't. The compiler does not recognize FILLER as
a variable name; it is used only to reserve space in a structure variable.
– If you include a command such as MOVE 1 TO FILLER in a program, it will not compile and produces an error.
– You can move values to a structure variable that contains a FILLER.
– The MOVE will affect the structure variable and all of the variables within the structure, but you cannot directly move values to a FILLER.
![Page 33: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/33.jpg)
33
Q&A
• Q Why do I need to know the lengths of structures?– A You don't yet, but you will need to know how to
calculate this when you start creating printed reports (in Day 10, "Printing").
![Page 34: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/34.jpg)
34
Quiz
1. What is the length of THE-WHOLE-MESSAGE in the following example?
![Page 35: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/35.jpg)
35
Quiz
2. What is the implied PICTURE of THE-WHOLE-MESSAGE in question 1?
3. What is a data structure?4. If you move a value to a structure variable,
what happens to the values in the individual variables within the structure?
5. In the following code, what is another way of performing the test at line 004600?
![Page 36: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/36.jpg)
36
Quiz
6. In the following code, what is another way of performing the test at line 004600?
![Page 37: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/37.jpg)
37
Quiz
7. In the following code, what is another way of performing the test at lines 004600 and 004700?
![Page 38: Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.](https://reader036.fdocuments.us/reader036/viewer/2022062304/56649cc45503460f9498d664/html5/thumbnails/38.jpg)
38
Quiz
8. Devise a level 88 condition name for YES-NO that would simplify the tests at lines 004600 through 004900 in the following code: