COBOL Renames Clause with Examples

COBOL Renames clause is used to regroup the elementary data items and gives them an alternative name. This is a logical grouping of the elementary data items which are defined in a sequential order.It is useful for renaming by overlapping elementary elements.66 Level number is used for defining it.

ex:
01 WW-VAR1.
   05 WW-V1     PIC XX.
   05 WW-V2     PIC XXX.
   05 WW-V3.
     10 WW-V3-1 PIC X.
     10 WW-V3-2 PIC XX.
     10 WW-V3-3 PIC X.
     10 WW-V3-4 PIC XX.
   05 WW-V4     PIC X(06).
   05 WW-V5     PIC X(10).
   05 WW-V6     pic x(04).
   66 WW-RNM1 RENAMES WW-V2 THRU WW-V3-2.
   66 WW-RNM2 RENAMES WW-V2 THRU WW-V3-4.

– 01 , 77 levels can not be used for renames.

Redefines with Renames:
– It can be used on redefined variables but that should not end within the redefined variable.
Ex:

01 WW-VAR1. 
 05 WW-V1 PIC XX VALUE 'AA'. 
 05 WW-V2 PIC XXX. 
 05 WW-V3 REDEFINES WW-V2. 
   10 WW-V3-1 PIC X. 
   10 WW-V3-2 PIC XX. 
   10 WW-V3-3 PIC X. 
   10 WW-V3-4 PIC XX. 
 05 WW-V4 PIC X(06) VALUE 'G12345'. 
 66 WW-RNM1 RENAMES WW-V2 THRU WW-V3-2.

This gives an error because ww-v2 and ww-v3-1 + ww-v3-2 has same length.

IGYDS0014-S “RENAMES” object “WW-V3-2” was contained within, or had a common leftmost byte with, object “WW-V2”. The “RENAMES” clause was discarded.

66 WW-RNM1 RENAMES WW-V1 THRU WW-V3-2. It works because renaming starts from ww-v1.

It works in below case as well, here I increased the length of ww-v3-2.

1 WW-VAR1. 
 05 WW-V1 PIC XX VALUE 'AA'. 
 05 WW-V2 PIC XXX. 
 05 WW-V3 REDEFINES WW-V2. 
   10 WW-V3-1 PIC X. 
   10 WW-V3-2 PIC XXx. 
   10 WW-V3-3 PIC X. 
   10 WW-V3-4 PIC XX. 
 05 WW-V4 PIC X(06) VALUE 'G12345'. 
 66 WW-RNM1 RENAMES WW-V2 THRU WW-V3-2.

Renames with OCCURS ->
In Example-1, any group variable from ww-v2 to ww-v3-4 should not contain occurs.
So WW-V1, WW-V2, WW-V3 & WW-V4 should not contain occurs.
But ww-v3-1 to ww-v3-4 can contain occurs BUT should not contain Ocuurs depending on Clause.

Add a Comment

Your email address will not be published. Required fields are marked *