View previous topic :: View next topic
|
Author |
Message |
technut
New User
Joined: 27 Dec 2007 Posts: 73 Location: India
|
|
|
|
Hi,
77 FIELDAL PIC X(3).
77 FIELDNM REDEFINES FIELDAL PIC S9(3).
I tried displaying FIELDNM after moving ' -1' to FIELDAl and its displaying the same correctly.
But when I try to add 1 to FIELDNM and try displaying, SYSOUT shows the result as A.
It would be great if somebody could explain the concept here. The result of the add should have been ZERO right! why A is getting displayed? Am I not supposed to REDEFINE FIELDNM with S9(3)?
I am sure this is a very basic question and someone should have asked this before. I tried searching the forum but could not find similar question and that is why I am posting the question. |
|
Back to top |
|
|
manikawnth
New User
Joined: 07 Feb 2007 Posts: 61 Location: Mumbai
|
|
|
|
Hi,
Can you post the exact instructions
and the hex data of SYSOUT display after MOVE and after ADD statements?
Hex data is achieved by using SET HEX ON on the command line of SYSOUT.
Thanks,
Manikanth |
|
Back to top |
|
|
technut
New User
Joined: 27 Dec 2007 Posts: 73 Location: India
|
|
|
|
Actually the result of add shows '00B' instead of 'A'. I was looking at a wrong SYSOUT previously I guess. I really apologize for the confusion.
Code: |
000013 -1
46F444444444444444444444444444444444444444444444444444444444444444444444
001000000000000000000000000000000000000000000000000000000000000000000000
------------------------------------------------------------------------------
000014 00B
FFC444444444444444444444444444444444444444444444444444444444444444444444
002000000000000000000000000000000000000000000000000000000000000000000000
------------------------------------------------------------------------------
|
|
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
I always thought that PIC S9(3) occupies 2 bytes. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
S9(3) takes 3
S9(3) comp-3 takes 2
S9(3) sign leading separate takes 4
but in none of them x'4060F1' = -1
PIC --9 might work, but can't remember if you can calculate with edited fields nowadays or that you have to move it to a numeric field first. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
GuyC wrote: |
but in none of them x'4060F1' = -1 |
but yet X'4060F1' = C' -1'
I think that when you add 1 to C' -1', the programs packs the number.
It then becomes equal to 1 (just as if you had X'F0F0F1' in the field).
The result becomes +2 which unpacked gives X'F0F0C2'
So everything is logical, even if the result is not what was expected. |
|
Back to top |
|
|
manikawnth
New User
Joined: 07 Feb 2007 Posts: 61 Location: Mumbai
|
|
|
|
Hi Peter,
S9(3) COMP occupies 2 bytes where as without COMP it will occupy 3 bytes.
Hi Tech,
Actually that was my confusion.
The 2 COBOL statements will be expanded as follows:
Code: |
0004D6 D202 8053 A0E7 MVC 83(3,8),231(10) WS-VALUE
002905 ADD
0004DC F212 D1A8 8053 PACK 424(2,13),83(3,8) TS2=0
0004E2 FA10 D1A8 A096 AP 424(2,13),150(1,10) TS2=0
0004E8 F811 D1A8 D1A8 ZAP 424(2,13),424(2,13) TS2=0
0004EE F321 8053 D1A8 UNPK 83(3,8),424(2,13) WS-VALUE
|
After execution of 0004D6, the target will have 4060F1 (-1)
After execution of 0004DC, the target will have 001F
After execution of 0004E2, the target will have 002F
After execution of 0004E8, the target will have 002C
After execution of 0004EE, the target will have F0F0C2 (00B)
I strongly believe that this is character representation of the negative value.
Which is absolutely fine...
Kindly verify your compiler listing and let me know
If you want to look the result as 2, the last step of execution should result in a value F0F0F2 instead of F0F0C2.
So kindly try declaring like this and verify
FIELDNM REDEFINES FIELDAL PIC S9(3) SIGN LEADING. |
|
Back to top |
|
|
technut
New User
Joined: 27 Dec 2007 Posts: 73 Location: India
|
|
|
|
Hi,
Thanks a lot for looking into this.
I will check compiler listing and suggest the options but before that, the result should be ZERO and not TWO right? I am adding 1 to -1!
Regs.. |
|
Back to top |
|
|
manikawnth
New User
Joined: 07 Feb 2007 Posts: 61 Location: Mumbai
|
|
|
|
Hi Tech,
I am sorry, the result should be Zero. |
|
Back to top |
|
|
technut
New User
Joined: 27 Dec 2007 Posts: 73 Location: India
|
|
|
|
Compiler listing.
000089 ADD
000960 F212 D168 24C8 PACK 360(2,13),1224(3,2) TS2=0
000966 FA10 D168 A044 AP 360(2,13),68(1,10) TS2=0
00096C F811 D168 D168 ZAP 360(2,13),360(2,13) TS2=0
000972 F321 24C8 D168 UNPK 1224(3,2),360(2,13) FIELDNM
I tried giving SIGN LEADING but its abending with SOC7 in the ADD command. |
|
Back to top |
|
|
manikawnth
New User
Joined: 07 Feb 2007 Posts: 61 Location: Mumbai
|
|
|
|
Y dont u operate on COMPutational variables and then move to arithmetic |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
GuyC, Manikawnth
yes thats right. I was focused on COMP-3 . |
|
Back to top |
|
|
technut
New User
Joined: 27 Dec 2007 Posts: 73 Location: India
|
|
|
|
Hi Manikawnth,
Are you asking me to define FIELDNM as COMP variable?
Please clarify! |
|
Back to top |
|
|
manikawnth
New User
Joined: 07 Feb 2007 Posts: 61 Location: Mumbai
|
|
|
|
No!!! Define some other variable and do the necessary arithmetic operations on it and move the final result into S9(3).
When ever u do the move and add operations just verify the listing also to make sure that required assembler instructions are generated to get the expected result.
Thanks,
Manikanth |
|
Back to top |
|
|
|