View previous topic :: View next topic
|
Author |
Message |
ashok.gkyadav
New User
Joined: 05 Sep 2006 Posts: 6
|
|
|
|
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 |
|
|
muthuvel
Active User
Joined: 29 Nov 2005 Posts: 217 Location: Canada
|
|
|
|
WS-B will have 999
Please search the forum before you make a post. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
I would expect a compile error as WS-B is longer than WS-A. |
|
Back to top |
|
|
muthuvel
Active User
Joined: 29 Nov 2005 Posts: 217 Location: Canada
|
|
|
|
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 |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
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 |
|
|
muthuvel
Active User
Joined: 29 Nov 2005 Posts: 217 Location: Canada
|
|
|
|
Phil and William,
Thanks |
|
Back to top |
|
|
|