COBOL REDEFINES
COBOL REDEFINES
The REDEFINES clause allows the same memory area to be described
by different data items. In program if we are sure that 2 or more
date names are not in use at same time then we go for redefines
clause.
01 WS-NAME.
05 WS_FST-NAME PIC X(05) VALUE “John”.
05 WS_FST-NAME PIC X(05) VALUE “Mike”.
01 WS-TOTAL-NAME REDEFINES WS-NAME PIC X(10).
In above example WS-TOTAL-NAME will use same memory area allocated
to WS-NAME. So Ws-TOTAL-NAME will have “John Mike”
1. Level numbers of WS-DATA-NAME1 and WS-DATA-NAME2 should be same.
2. REDEFINES clause cannot be used for level numbers 66 and 88.
3. REDEFINES may not be used in a level 01 entry in the File Section.
4. Number of characters need not be the same for WS-DATA-NAME1 and
WS-DATA-NAME2. Compiler generates warning if number of characters
in WS-DATA-NAME2 is greater than WS-DATA-NAME2.
5. Several data items can redefine the same data item.
6. Data items redefining the storage of a data item must immediately
follow the description of that data item.
Difference between REDEFINES and RENAMES:
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
|