View previous topic :: View next topic
|
Author |
Message |
mubashshirji
New User
Joined: 14 Nov 2006 Posts: 16
|
|
|
|
Consider the code below :
WORKING STORAGE SECTION.
01 var1 PIC 9(4).
01 var2 REDEFINES var1 PIC 9(8).
01 var3 PIC 9(8).
PROCEDURE DIVISION.
MOVE 100 TO var1.
MOVE 1000 TO var2.
COMPUTE var3 = var1+var2.
DISPLAY var3.
STOP RUN.
Here size of var2 is greater than var1 . Can a variable of larger size redefine a variable of smaller size and vice versa ? |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi There,
Yes. Redefines just causes both fields to start at the same location. |
|
Back to top |
|
|
mubashshirji
New User
Joined: 14 Nov 2006 Posts: 16
|
|
|
|
Thanx a lot Ekta |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
not sure what COBOL or mainframe you are using, but if you had at least attempted to test this, you would have received a compiler error.
read the manual, it is very clear what a redefine does; you could have answered your own question.
no way in the world that you can redefine 4 bytes into 8. |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi there,
Contrary to what Dick says Redefining A with B means, A and B will start from the same location So if B is of larger length than A, it just eats into memory locations that are probably allocated to other program variables. It is advisable not to do so because we could get a SOC abend if some other variable data is overwritten so it wont give u any compilation error
Hope it will helpful |
|
Back to top |
|
|
|