Tuesday, December 6, 2011

COBOL: How internally Redefines and Renames clause works

The RENAMES clause specifies alternative, possibly overlapping, groupings of elementary data items.

The REDEFINES clause allows you to use different data description entries to describe the same computer storage area.

The following example will help us to understand better :

01  RECORD-II.                    
   05 DN-1.                      
      10 DN-2... .                
      10 DN-2A... .              
   05 DN-1A REDEFINES DN-1.      
      10 DN-3A... .              
      10 DN-3... .                
      10 DN-3B... .              
   05 DN-5... .                  
66  DN-6 RENAMES DN-2 THROUGH DN-3.

<---------------RECORD-II------------>|
<-----------DN-1------------->|  
---------------------------------------
|   DN-2   |       DN-2A      |  DN-5 |
---------------------------------------
<-----------DN-1A------------>|        
------------------------------        
| DN-3A |  DN-3  |   DN-3B    |        
-------------------------------        
|<-----DN-6----->|                        




Below is one more example that will give you another use of RENAMES clause. Let us say we have the below record structure in a copybook named MYCPYBK.

01 EMP-REC.
   05 EMP-NO                                 PIC X(05).
   05 EMP-NAME                               PIC X(10).
   05 THIS-IS-A-LENGHTY-FIELD-NAME-TO-HANDLE PIC X(20).
   05 EMP-DEP                                PIC X(04).
   05 EMP-SALARY                             PIC S9(5)V99 COMP-3.

Obviously field “THIS-IS-A-LENGHTY-FIELD-NAME-TO-HANDLE” is too lengthy. You want to give another name for this lengthy field without changing the copybook. Here is how you do it.

COPY MYCPYBK.

66 SHORT-FIELD RENAMES THIS-IS-A-LENGHTY-FIELD-NAME-TO-HANDLE.

Now you can use the SHORT-FIELD in the program and it will refer to that lengthy field.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.