Difference bw RENAMES and REDEFINES



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Difference bw RENAMES and REDEFINES

Postby kbmkris » Thu Sep 27, 2007 6:04 am

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
kbmkris
 
Posts: 1
Joined: Wed Sep 26, 2007 5:38 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Difference between RENAMES and REDEFINES

Postby kiran » Thu Sep 27, 2007 9:43 am

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
kiran
 
Posts: 17
Joined: Mon Sep 03, 2007 10:45 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Difference between RENAMES and REDEFINES

Postby marso » Sun Sep 30, 2007 2:24 pm

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.
User avatar
marso
 
Posts: 12
Joined: Mon Jul 30, 2007 5:04 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Difference between RENAMES and REDEFINES

Postby extasy » Thu Nov 29, 2007 1:40 pm

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.
extasy
 
Posts: 2
Joined: Thu Nov 29, 2007 12:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Difference between RENAMES and REDEFINES

Postby Tzadik Vanderhoof » Fri Nov 30, 2007 10:47 pm

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.
Tzadik Vanderhoof
 
Posts: 21
Joined: Tue Nov 13, 2007 11:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Difference between RENAMES and REDEFINES

Postby kiran_ragam » Sun Dec 09, 2007 4:14 pm

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.
kiran_ragam
 
Posts: 5
Joined: Sun Dec 09, 2007 3:27 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Difference between RENAMES and REDEFINES

Postby vasanthamugi » Sat Dec 22, 2007 2:46 pm

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.
vasanthamugi
vasanthamugi
 
Posts: 14
Joined: Thu Dec 20, 2007 2:38 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Difference between RENAMES and REDEFINES

Postby dilip1234th » Sat Jan 05, 2008 3:12 pm

RENAMES clause will occur only at 66 Level.

Check this REDEFINE and RENAME CLAUSE
dilip1234th
 
Posts: 1
Joined: Wed Jan 02, 2008 1:06 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post