Level Numbers
- Level numbers play the most important role in declaring the variables in the application programs.
- They specify the hierarchy or level of data items or variables.
Syntax -
level-number {variable|FILLER} ...
- level-number -
- Level number is a one or two-digit numeric value. Valid level numbers are - 01, 02, ...49, 66, 77 and 88.
- Level numbers 01 or 77 should begin in Area A.
- A level-numbers 02 through 49, 66 and 88 can begin in either Area A or Area B.
- variable - Identifies the variable used in the program.
- FILLER - FILLER is a keyword and is optional. We can't able to refer FILLER in the program.
Level Number Types -
Level numbers are of two types based on their usage purpose -
- General purpose level numbers (01 to 49)
- Special purpose level numbers (66, 77 and 88)
General purpose level numbers (01 to 49) -
- General purpose level numbers declare regular variables that simply process the data.
- The level number hierarchy starts from 01 through 49.
- The hierarchy of level numbers should be in ascending order. i.e., 01 is the highest level number, and 49 is the lowest level number.
Example -
Scenario - Declaring employee record.
----+----1----+----2----+----3----+----4----+----5----+
01 EMPLOYEE-RECORD.
05 EMP-ID PIC 9(5).
05 EMP-NAME.
10 FIRST-NAME PIC X(15).
10 MIDDLE-NAME PIC X(10).
10 LAST-NAME PIC X(20).
Explaining Example -
In the above example:
- EMPLOYEE-RECORD, and EMP-NAME are group variables, and FIRST-NAME, MIDDLE-NAME, LAST-NAME are the elementary variables.
- EMP-NAME is a group variable with three elementary variables: FIRST-NAME (15 bytes), MIDDLE-NAME(10 bytes), and LAST-NAME(20 bytes). So, the total length of the EMP-NAME is 45 bytes.
- Lastly, EMPLOYEE-RECORD has two variables: EMP-ID(5 characters), EMP-NAME(45 bytes). So, the total EMPLOYEE-RECORD size is 50 bytes.
Special purpose level numbers (66, 77 and 88) -
These level numbers are used for special purposes like renaming a variable and declaring individual variables and conditional names. Those are -
- 66 level number
- 77 level number
- 88 level number
Level number 66 is used to create another logical group by regrouping the elementary variables of a group. The RENAMES keyword is used along with the 66-level number to rename the group.
Example -
Scenario - Create a employee record with EMP-ID and EMP-NAME alone.
----+----1----+----2----+----3----+----4----+----5----+
01 EMPLOYEE-RECORD.
05 EMP-ID PIC 9(5).
05 EMP-NAME.
10 FIRST-NAME PIC X(15).
10 MIDDLE-NAME PIC X(10).
10 LAST-NAME PIC X(20).
05 DATE-OF-BIRTH.
10 DOB-YEAR PIC 9(4).
10 DOB-MONTH PIC 9(2).
10 DOB-DAY PIC 9(2).
66 EMPLOYEE-REC01 RENAMES EMP-ID THRU EMP-NAME.
In the above example, EMPLOYEE-REC01 contains only EMP-ID and EMPLOYEE-NAME.
- In some scenarios, the variables are neither allowed to be converted to group variables nor elementary variables, such as constants. They have no immediate relationship to any other variables. Those variables are called Individual variables.
- Level number 77 is used to declare the individual variables.
Example -
Scenario - Create a employee record with EMP-ID and EMP-NAME alone.
----+----1----+----2----+----3----+----4----+----5----+
77 WS-PI PIC 9V9(2) VALUE 3.14.
In the above example, WS-PI contains the value 3.14, and it is not allowed to change its declaration.
- The 88-level number defines a name for a value or a set of values under the variable.
- The 88-level number provides a descriptive name for a condition.
- The name associated with 88 level numbers is called as Condition Name, and the variable with 88 level numbers attached to it is called as Conditional Variable.
Example -
Scenario - condition name with all its formats.
----+----1----+----2----+----3----+----4----+----5----+
01 WS-ALPHABET PIC X(01).
* Condition names with single values
88 ALPHABET-A VALUE "A".
88 ALPHABET-S VALUE "S".
* Condition names with multiple values
88 VOWELS VALUE "A" "E" "I" "O" "U".
* Condition names with range of values
88 VALID-ALPHABET VALUE "A" THROUGH "Z".
88 CONSONANTS VALUE "B" THRU "D"
"F" THRU "H"
"J" THRU "N"
"P" THRU "T"
"V" THRU "Z".
In the above example:
- WS-ALPHABET is a condition variable with condition names under it.
- ALPHABET-A and ALPHABET-S are the condition names with single values.
- VOWELS is a condition name with multiple values.
- VALID-ALPHABET and CONSONANTS are the condition names with range of values.