IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Can a var. of larger size redefine a var. of smaller size


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
mubashshirji

New User


Joined: 14 Nov 2006
Posts: 16

PostPosted: Wed Nov 15, 2006 4:48 pm
Reply with quote

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
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Wed Nov 15, 2006 4:54 pm
Reply with quote

Hi There,

Yes. Redefines just causes both fields to start at the same location.
Back to top
View user's profile Send private message
mubashshirji

New User


Joined: 14 Nov 2006
Posts: 16

PostPosted: Wed Nov 15, 2006 5:00 pm
Reply with quote

Thanx a lot Ekta
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Nov 15, 2006 5:13 pm
Reply with quote

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
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Wed Nov 15, 2006 5:51 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts Using Java/C/C++ to retrieve dataset ... Java & MQSeries 6
No new posts Find the size of a PS file before rea... COBOL Programming 13
No new posts Masking variable size field - min 10 ... DFSORT/ICETOOL 4
No new posts Dataset size increase on adding 1 byt... DFSORT/ICETOOL 8
No new posts TWA size of the CPLT transaction CICS 0
Search our Forums:

Back to Top