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

Can I redfine 9(3) with X(5)? What is the result of below?


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

New User


Joined: 05 Sep 2006
Posts: 6

PostPosted: Tue Mar 06, 2007 10:57 am
Reply with quote

What would be the result of the following?

05 WS-A PIC 9(3).
05 WS-B REDEFINES WS-A PIC X(5).


Move 999 to WS-A.
Display WS-B.
Back to top
View user's profile Send private message
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Canada

PostPosted: Tue Mar 06, 2007 11:36 am
Reply with quote

WS-B will have 999

Please search the forum before you make a post.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Tue Mar 06, 2007 6:38 pm
Reply with quote

I would expect a compile error as WS-B is longer than WS-A.
Back to top
View user's profile Send private message
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Canada

PostPosted: Tue Mar 06, 2007 7:38 pm
Reply with quote

Phil,
I tried it out and i got the value 999 moved to WS-B.

REDEFINING the varaible longer or shorter will not give a compiler error.It is possible for truncation of data if the redefined variable is shorter.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Wed Mar 07, 2007 6:54 pm
Reply with quote

I see I was wrong about the compiler error.

However, notwithstanding the lack of a compile warning/error, you really don't want the redefining variable to be longer.

Above, the actual value of WS-B is:
bytes 1-3 = '999'
bytes 4-5 = x'00'

Here's the hex display:
999
FFF00
99900

This test:

IF WS-B = '999'
DISPLAY 'EQUALS 999'
ELSE
DISPLAY 'NOT EQUALS 999'
END-IF.

produces this output:

NOT EQUALS 999

because the compare of '999' against the X(5) field is trying to match '999' blank-blank.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Wed Mar 07, 2007 8:20 pm
Reply with quote

muthuvel wrote:
I tried it out and i got the value 999 moved to WS-B.
No, not quite, if you had done a display '*' WS-B '*' you would have seen "*999??* where the ? is whatever was previously in WS-B.
Quote:
REDEFINING the variable longer or shorter will not give a compiler error.It is possible for truncation of data if the redefined variable is shorter.
No, not quite, it is more dependent upon the compiler. Either way you will never get truncation; if the compiler can't handle it, it will fail compile; if the compiler can handle it, it will reserve the extra space after the redefined data to cover for the longer redefining data.
Back to top
View user's profile Send private message
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Canada

PostPosted: Thu Mar 08, 2007 9:01 pm
Reply with quote

Phil and William,
Thanks icon_rolleyes.gif
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 first column truncated in search result IBM Tools 13
No new posts SDSF like solution in EJES (store com... All Other Mainframe Topics 4
No new posts executing XCTL command in COBOL witho... CICS 10
No new posts Undesired result while joining files. SYNCSORT 3
No new posts COBOL - Array result in single variab... COBOL Programming 3
Search our Forums:

Back to Top