View previous topic :: View next topic
|
Author |
Message |
dilpreet
New User
Joined: 18 Mar 2008 Posts: 34 Location: INDIA
|
|
|
|
Was asked that
01 a pic x(4)
01 b redifine a pic 9(4)
move 'ABCD' to a
display b
What would be the display
Answered:
some value other than ABCD will be displayed but it wont abend the program.
Please clear the doubt!!!! |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
The actual answer is that ABCD will be displayed. The REDEFINE doesn't change the value of the variable, and PIC 9(04) displays the same as PIC X(04). |
|
Back to top |
|
|
zh_lad
Active User
Joined: 06 Jun 2009 Posts: 115 Location: UK
|
|
|
|
How about redefining as COMP-3?
05 WS-A PIC X(5) VALUE 'ABCDE'.
05 WS-B REDEFINES WS-A PIC S9(5) COMP-3.
05 WS-C PIC 9(5).
05 WS-D PIC X(5).
05 WS-E REDEFINES WS-D PIC 9(5).
Display shows following values:
WS-A = ABCDE
4EE6C474CCCCC
062010E012345
----------------------------------
WS-B = Ü1Ü2Ü
4EE6C474FFFFF
062020E0C1C2C
************************************************
MOVE WS-A TO WS-C
Why does WS-C does not show 'ABCDE'? Why deos it show following? How is it different from REDEFINE?
-------------
WS-C = ABCD5
4EE6C474CCCCF
062030E012345
************************************************
I have tested redfine as numeric and it shows 'ABCDE'
MOVE 'ABCDE' TO WS-D
WS-D = ABCDE
4EE6C474CCCCC
062040E012345
-------------
WS-E = ABCDE
4EE6C474CCCCC
062050E012345
It would be great if you could clear the doubt.
Many thanks! |
|
Back to top |
|
|
Asif Bhatkar
New User
Joined: 21 Dec 2009 Posts: 5 Location: India
|
|
|
|
I too faced this type of situation when testing for alphanumeric to numeric moves, but not able to find exact reason.
When the variable is alphanumeric the internal representation is C1 to C5 (A to E), but when we move it to numeric variable it changes the last characters internal representation to F5 (from C5). I think it may be due to the sign which is stored in the left half of LSB (For default DISPLAY format) |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Click on the manuals link at the top of the page, find the COBOL Language Reference and Programming Guide manuals, and read them to find out what the internal formats for data are. If you do this, you will find that a PIC S9(05) COMP-3 field actually uses THREE bytes, not five bytes so your redefine has problems from the start.
Your move of WS-A to WS-C is 5 bytes to 5 bytes and WS-C is USAGE DISPLAY, which means the move will work fine. However, COBOL will guarantee that the value is not signed and will do an OI (Or Immediate) assembler instruction against hex 'F0' for the last byte of the variable. This changes the hex 'C5' ('E') value to hex 'F5' ('5').
REDEFINES causes the two variables to occupy the exact same memory locations. It is up to the programmer to ensure that the two variables are the same length and of compatible types. USAGE DISPLAY and USAGE COMP-3 are NOT compatible and cannot be redefined on each other without causing problems. |
|
Back to top |
|
|
|