66 Level Number
Special purpose level number 66 is used to create another logical group by regrouping the elementary variables of a group. The RENAMES clause is used along with the 66-level number to rename the group. The 66-level number, combined with the REDEFINES clause, provides a flexible way to view and manipulate data.
Syntax -
----+----1----+----2----+----3----+----4----+----5----+
01 WS-VAR-GRP1.
05 WS-VAR-A PIC ...
05 WS-VAR-B PIC ...
.
.
05 WS-VAR-N PIC ...
05 WS-VAR-O PIC ...
.
.
05 WS-VAR-Z PIC ...
66 WS-VAR-GRP2 RENAMES VAR-A THRU VAR-N.
In the above syntax,
- WS-VAR-GRP1 - Specifies source group variable.
- WS-VAR-A, ..., WS-VAR-N - Specifies starting and ending elementary variables to be renamed.
- WS-VAR-GRP2 - Specifies target variable.
Points to note -
- THRU or THROUGH keyword is used only when renaming some elementary variables.
- THRU or THROUGH can be ignored when renaming the entire group.
Rules to Remember -
- Renaming elementary variables should be in sequential order.
- 66 level number shouldn't have a PIC or PICTURE clause.
- The RENAMES clause should follow the target variable in the declaration.
- Level-01, level-77, level-88, or other level-66 entries can't be renamed.
- Elementary variables that are declared with the OCCURS clause should not be renamed.
Explaining in detail -
Scenario1 - Renaming group variable.
The declaration of the group variable and renaming of the group variable are as follows -
02 A.
05 ITEM1 PIC X(5).
05 ITEM2 PIC X(5).
05 ITEM3 PIC X(5).
05 ITEM4 PIC X(5).
05 ITEM5 PIC X(5).
66 B RENAMES A.
In the above example, group variable A is declared with five elementary variables from ITEM1 to ITEM5. B is defined as the renaming of A without the THROUGH clause. Here, B is just a renaming variable for the data in variable A and uses the same memory location used by A.
The below diagram can explain how A and B represent memory -
Scenario2 - Renaming some elementary variables under a group.
The declaration of group variables and renaming of some elementary variables as follows -
02 A.
05 ITEM1 PIC X(5).
05 ITEM2 PIC X(5).
05 ITEM3 PIC X(5).
05 ITEM4 PIC X(5).
05 ITEM5 PIC X(5).
05 ITEM6 PIC X(5).
05 ITEM7 PIC X(5).
05 ITEM8 PIC X(5).
05 ITEM8 PIC X(5).
05 ITEM10 PIC X(5).
66 B RENAMES ITEM1 THRU ITEM6.
In the above example, group variable A is declared with ten elementary variables from ITEM1 to ITEM10. B is defined as the renaming of A with six elementary variables from ITEM1 to ITEM6. Here, B is just a renaming variable for the data from ITEM1 to ITEM6 and uses the same memory location used by A.
The below diagram can explain how A and B represent memory -
Practical Example -
Scenario - Variable declaration using 66-level number and the variable usage in PROCEDURE DIVISION.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. RENAME.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR.
02 WS-GRP-ITEM1.
05 WS-VAR1 PIC X(10) VALUE "MAINFRAMES".
05 FILLER PIC X(01).
05 WS-VAR2 PIC X(08) VALUE "ARE VAST".
05 FILLER PIC X(01).
05 WS-VAR3 PIC X(01) VALUE "&".
05 FILLER PIC X(01).
05 WS-VAR4 PIC X(10) VALUE "LEGENDARY".
05 FILLER PIC X(01).
05 WS-VAR5 PIC X(10) VALUE "SYSTEMS".
* Renaming WS-GRP-ITEM1
66 WS-GRP-ITEM2 RENAMES WS-VAR1 THROUGH WS-VAR2.
01 WS-VAR2.
02 WS-GRP-ITEM3.
05 WS-VAR31 PIC X(10) VALUE "MAINFRAMES".
05 FILLER PIC X(01).
05 WS-VAR32 PIC X(03) VALUE "ARE".
05 FILLER PIC X(01).
05 WS-VAR33 PIC X(10) VALUE "LEGENDARY".
05 FILLER PIC X(01).
05 WS-VAR34 PIC X(10) VALUE "SYSTEMS".
* Renaming WS-GRP-ITEM3
66 WS-GRP-ITEM4 RENAMES WS-GRP-ITEM3.
PROCEDURE DIVISION.
DISPLAY "GROUP ITEM1: " WS-GRP-ITEM1.
DISPLAY "GROUP ITEM2: " WS-GRP-ITEM2.
DISPLAY "GROUP ITEM3: " WS-GRP-ITEM3.
DISPLAY "GROUP ITEM4: " WS-GRP-ITEM4.
STOP RUN.
Output -
GROUP ITEM1: MAINFRAMES ARE VAST & LEGENDARY SYSTEMS GROUP ITEM2: MAINFRAMES ARE VAST GROUP ITEM3: MAINFRAMES ARE LEGENDARY SYSTEMS GROUP ITEM3: MAINFRAMES ARE LEGENDARY SYSTEMS
Explaining Example -
In the above example:
- WS-GRP-ITEM1 is a group item with multiple variables. WS-GRP-ITEM2 is defined as the renaming of WS-GRP-ITEM1 from WS-VAR1 THROUGH WS-VAR2. So, WS-GRP-ITEM2 displays the data from WS-VAR1 to WS-VAR2.
- WS-GRP-ITEM4 is defined as renaming the entire group item WS-GRP-ITEM3. So, WS-GRP-ITEM4 displays the data the same as WS-GRP-ITEM3 displays.