Page 1 of 1

Difference bw RENAMES and REDEFINES

PostPosted: Thu Sep 27, 2007 6:04 am
by kbmkris
What is the difference between RENAMES and REDEFINES clause? Could you explain with some example. I went through the COBOL Language Reference, but I am not able to get that clearly.

Thanks,
Bala

Re: Difference between RENAMES and REDEFINES

PostPosted: Thu Sep 27, 2007 9:43 am
by kiran
Hi

renames : regrouping of data elements is nothing but renames
for this we have to use 66 level number
redefines : reusing of storage space is nothing but redefines
for this level number must be same

Re: Difference between RENAMES and REDEFINES

PostPosted: Sun Sep 30, 2007 2:24 pm
by marso
Here is a REDEFINES example:
03  date-eur.
    05  date-eur-dd     pic xx.
    05  date-eur-mm     pic xx.
    05  date-eur-yyyy   pic xxxx.
03  date-usa            REDEFINES date-eur.
    05  date-usa-yyyy   pic xxxx.
    05  date-usa-dd     pic xx.
    05  date-usa-mm     pic xx.


Here is a RENAMES example:
03  date-eur.
    05  date-eur-dd     pic xx.
    05  date-eur-mm     pic xx.
    05  date-eur-cc     pic xx.
    05  date-eur-yy     pic xx.
    66  date-eur-yyyy   RENAMES date-eur-cc THRU date-eur-yy.

Re: Difference between RENAMES and REDEFINES

PostPosted: Thu Nov 29, 2007 1:40 pm
by extasy
Hi,kbmkris
Hope my answer will help you...
REDEFINES:Give a computer storage area MORE THAN ONE names that all point to this area.
Even this data-type of every names can be different.
    01 TS-DATA.                       
    05 VAR1                PIC X(5).
    05 VAR2 REDEFINES VAR1 PIC 9(5).

RENAMES:Regroup some of the Elementary-data-item in a GROUP.It gives this ele-data-item a new name can be operate more convenience.
    01 TS-GROUP.                     
    05 G-VAR1              PIC X(5).
    05 G-VAR2              PIC X(5).
    05 G-VAR3              PIC X(5).
    66 TS-RENAME                     
    RENAMES G-VAR1 THRU G-VAR2.   

Correct me ,plz if sth is wrong...thx.

Re: Difference between RENAMES and REDEFINES

PostPosted: Fri Nov 30, 2007 10:47 pm
by Tzadik Vanderhoof
RENAMES lets you give a name to series of items without needing to have a group item above them. For example,
01 full-date.
  05 dt-month pic 99.
  05 dt-day  pic 99.
  05 dt-year pic 9999.
01 short-date renames dt-month thru dt-day.


Notice that there is no need to define a group item that includes only dt-month and dt-day, because I can use "thru". For "redefines" you would need a separate group item for those 2 items.

Another advantage of "renames" is that you don't need to specify any pic. It just puts together all the pic's that you are renaming to create a new one for the renamed item. In this example, it automatically comes up with pic 9999 for short-date, without you having to put it in the code.

On the other hand, the disadvantage of "renames" is that you can't change the format at all. That is what "redefines" is for.

Re: Difference between RENAMES and REDEFINES

PostPosted: Sun Dec 09, 2007 4:14 pm
by kiran_ragam
hi,
RENAME is nothing but regrouping of data items,it should be given 66 level only
EX.
01 emp-rec
05 emp-name pic x(10).
05 emp-no pic 9(5).
01 emp-sal
05 ta-da pic 9(3).
05 bonus pic 9(3).
66 re-emp renames emp-no thru ta-da.
so re-emp regroups emp-no and ta-da.
REDEFIES:different data items using same memory location.
EX.
01 emp-rec.
05 emp-name pic x(20).
05 ws-emp-rec redefines
10 emp-first-name pic x(5).
10 enp-last-name pic x(5).
in redefines clause redefines variable should follow the first variable.

Re: Difference between RENAMES and REDEFINES

PostPosted: Sat Dec 22, 2007 2:46 pm
by vasanthamugi
Rename clause is used for renaming a particular defined variable.
redefing clause is used for redefing the same working storage area by more than one variable
example for rename clause:
01 empno
05 empno1 pic 9(4).
05 empno2 pic 9(4).
01 empname.
05 empname1 pic x(10).
05 empname2 pic x(10).
01 empsalary.
05 empsal1 pic 9(4).
05 empsal2 pic 9(4).
66 empdetails rename empno thru empsalary.
example for redefine clause
01 a pic 9(5)
01 b redefines a pic 9(5) value 10000.
//*here the variable b will take the memory of a
display b.
//*here the output will be 10000.
01 c redefines b pic 9(3) value 100.
display c.
//* here the output will be 100.

now consider we can redefine pic 9(6) by pic 9(8). and we can also redefine pic 9(5) by pic 9(2).
we can also redefine pic 9(3) by pic x(2).

if i am wrong in any of the description i given above am sorry , please correct me.

Re: Difference between RENAMES and REDEFINES

PostPosted: Sat Jan 05, 2008 3:12 pm
by dilip1234th
RENAMES clause will occur only at 66 Level.

Check this REDEFINE and RENAME CLAUSE