Redefines: What is var1/ var2 ?



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

Redefines: What is var1/ var2 ?

Postby abkumarch » Thu Nov 08, 2007 1:23 am

01 ws-data
05 var1 pic X(05)
05 var2 REDEFINES var1 pic 9(5)


p.d.
MOVE 'abcde' TO var1
NOW what is the value of var1 & var2 ?
abkumarch
 
Posts: 21
Joined: Tue Oct 30, 2007 3:14 am
Has thanked: 0 time
Been thanked: 0 time

Re: Redefines: What is var1/ var2 ?

 

Re: Redefines: What is var1/ var2 ?

Postby dick scherrer » Thu Nov 08, 2007 2:07 am

Hello,

What happens when you try this?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Redefines: What is var1/ var2 ?

Postby CICS Guy » Thu Nov 08, 2007 3:53 am

abkumarch wrote:NOW what is the value of var1 & var2 ?
Quite simple, var1 will contain 'abcde' and so will var2....
But, var2 will be kinda garbagey and could result in anything from '12345' to ASRA/S0C7, depending upon how it gets used/referenced.....
CICS Guy
 
Posts: 255
Joined: Wed Jun 20, 2007 4:08 am
Has thanked: 0 time
Been thanked: 0 time

Re: Redefines: What is var1/ var2 ?

Postby cravi_pdy » Tue Nov 13, 2007 5:37 pm

I think var1 will be abcde, and var2 will be totally 00000.
cravi_pdy
 
Posts: 5
Joined: Tue Nov 13, 2007 5:06 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Redefines: What is var1/ var2 ?

Postby CICS Guy » Tue Nov 13, 2007 8:04 pm

cravi_pdy wrote:I think var1 will be abcde, and var2 will be totally 00000.
Nope....Not with that redefinition, both datanames contain the same data....
CICS Guy
 
Posts: 255
Joined: Wed Jun 20, 2007 4:08 am
Has thanked: 0 time
Been thanked: 0 time

Re: Redefines: What is var1/ var2 ?

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

Var1 & Var2 are refer to the same COMPUTER STORAGE AREA.
Clearly,the value of VAR1:abcde and the VAR2:abcde. :roll:
Correct me ... IF sth is wrong,thx x:
extasy
 
Posts: 2
Joined: Thu Nov 29, 2007 12:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Redefines: What is var1/ var2 ?

Postby kiran_ragam » Sun Dec 09, 2007 3:40 pm

hi
Redefines means different data items using same memory location.
there is var1:'abcde' and var2 also have 'abcde' because these 2 variables using same memory.
kiran_ragam
 
Posts: 5
Joined: Sun Dec 09, 2007 3:27 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Redefines: What is var1/ var2 ?

Postby nikhilgalgate » Thu Dec 27, 2007 2:28 pm

I agree with Kiran

kiran_ragam wrote:hi
Redefines means different data items using same memory location.
there is var1:'abcde' and var2 also have 'abcde' because these 2 variables using same memory.


You may check it practically. :geek:
nikhilgalgate
 
Posts: 9
Joined: Tue Dec 25, 2007 1:12 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Redefines: What is var1/ var2 ?

Postby sureshbabu » Thu Jan 03, 2008 1:37 pm

here var1 is alphanumeric
var2 is numeric
here var1 is given value 'abcd' which is alphbitic
but var2 is numeric ,,the problem is solved
and redefine shoud use same memory location
so can a same memory location can be used for two variables with different pictures
please continue this
sureshbabu
 
Posts: 7
Joined: Tue Dec 18, 2007 12:39 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Redefines: What is var1/ var2 ?

Postby dick scherrer » Tue Jan 15, 2008 2:43 am

Hello,

so can a same memory location can be used for two variables with different pictures
Yes, but this will typically cause more problems than providing solutions. It is another of the things that might be done, but should be avoided. The example that started this topic is a rather bad example.

One time when such a redefinition might be used is when input data might be in different formats. Then, care must be taken to ensure that the correct definition is used n the particular part of the code.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post