Redefines clause is used to define a storage with different data description. If one or more data items are not used simultaneously, then the same storage can be utilized for another data item. So the same storage can be referred with different data items.
01 WS-NAME. 05 WS-FIRST-NAME PIC X(05) VALUE 'KALAI'. 05 WS-FILLER PIC X(01) VALUE SPACES. 05 WS-LAST-NAME PIC X(05) VALUE 'SRINI'. 01 WS-FULL-NAME REDEFINES WS-NAME PIC X(11). |
Following are the details of the used parameters −
WS-NAME is Redefined Item
WS-FULL-NAME is Redefining Item
In above example WS-TOTAL-NAME will use same memory area allocated to WS-NAME. So Ws-TOTAL-NAME will have 'KALAI SRINI'
Let us see another example below,
01 WS-OLD PIC X(10). 01 |
Following are the details of the used parameters −
WS-OLD is Redefined Item
WS-NEW1 and WS-NEW2 are Redefining Item
Tips:
Level number of Redefined Item and Redefining Item should be same.
Redefines definition must be the next data description you want to redefine.
A redefining item will always have the same value as a redefined item.
REDEFINES clause cannot be used for level numbers 66 and 88.
REDEFINES may not be used in a level 01 entry in the File Section.
Number of characters need not be the same for Redefined Item and Redefining Item. Compiler generates warning if number of characters in Redefining item is greater than Redefined item.
Several data items can redefine the same data item.
Example: Let's see another example,
IDENTIFICATION DIVISION. PROGRAM-ID. CBLREDEF. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-DESCRIPTION. 05 WS-DATE1. 10 WS-YEAR PIC X(4) VALUE '2020'. 10 WS-MONTH PIC X(2) VALUE '08'. 10 WS-DATE PIC X(2) VALUE '20'. 05 WS-DATE2 REDEFINES WS-DATE1 PIC 9(8). PROCEDURE DIVISION. DISPLAY "WS-DATE1 : "WS-DATE1. DISPLAY "WS-DATE2 : "WS-DATE2. GOBACK. |
When you compile and execute the above program it produces the following result −
WS-DATE1 : 20200820 WS-DATE2 : 20200820 |
RENAMES clause is used for regrouping elementary data items and gives one name to it. REDEFINES clause allow you to use different data descriptions entries to describe same memory area.
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!