RENAMES Clause
RENAMES Clause Example
Scenario - Renaming some variables from source group.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. RENAMESE.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR1.
02 WS-GRP-ITEM1.
05 WS-VAR11 PIC X(10) VALUE "MAINFRAMES".
05 FILLER PIC X(01).
05 WS-VAR12 PIC X(03) VALUE "ARE".
05 FILLER PIC X(01).
05 WS-VAR13 PIC X(10) VALUE "LEGENDARY".
05 FILLER PIC X(01).
05 WS-VAR14 PIC X(10) VALUE "SYSTEMS".
* Renaming WS-GRP-ITEM3
66 WS-GRP-ITEM2 RENAMES WS-VAR11 THRU WS-VAR13.
PROCEDURE DIVISION.
DISPLAY "Group Item1: " WS-GRP-ITEM1.
DISPLAY "Group Item2: " WS-GRP-ITEM2.
STOP RUN.
Output -
Group Item1: MAINFRAMES ARE LEGENDARY SYSTEMS Group Item2: MAINFRAMES ARE LEGENDARY
Explaining Example -
In the above example:
- WS-GRP-ITEM1 is a group item with multiple elementary variables. WS-GRP-ITEM2 is renaming from WS-VAR11 THROUGH WS-VAR13 of WS-GRP-ITEM1. So, WS-GRP-ITEM2 points the data from WS-VAR11 to WS-VAR13 and displays the same.