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

Question on Redefining alphanumeric to numeric


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
technut

New User


Joined: 27 Dec 2007
Posts: 73
Location: India

PostPosted: Mon Mar 22, 2010 12:12 pm
Reply with quote

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

New User


Joined: 07 Feb 2007
Posts: 61
Location: Mumbai

PostPosted: Mon Mar 22, 2010 1:56 pm
Reply with quote

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

New User


Joined: 27 Dec 2007
Posts: 73
Location: India

PostPosted: Mon Mar 22, 2010 2:13 pm
Reply with quote

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

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Mon Mar 22, 2010 2:21 pm
Reply with quote

I always thought that PIC S9(3) occupies 2 bytes.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Mar 22, 2010 2:26 pm
Reply with quote

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

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Mar 22, 2010 2:38 pm
Reply with quote

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

New User


Joined: 07 Feb 2007
Posts: 61
Location: Mumbai

PostPosted: Mon Mar 22, 2010 2:42 pm
Reply with quote

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

New User


Joined: 27 Dec 2007
Posts: 73
Location: India

PostPosted: Mon Mar 22, 2010 2:49 pm
Reply with quote

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

New User


Joined: 07 Feb 2007
Posts: 61
Location: Mumbai

PostPosted: Mon Mar 22, 2010 2:52 pm
Reply with quote

Hi Tech,
I am sorry, the result should be Zero.
Back to top
View user's profile Send private message
technut

New User


Joined: 27 Dec 2007
Posts: 73
Location: India

PostPosted: Mon Mar 22, 2010 3:06 pm
Reply with quote

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

New User


Joined: 07 Feb 2007
Posts: 61
Location: Mumbai

PostPosted: Mon Mar 22, 2010 3:12 pm
Reply with quote

Y dont u operate on COMPutational variables and then move to arithmetic
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Mon Mar 22, 2010 3:21 pm
Reply with quote

GuyC, Manikawnth

yes thats right. I was focused on COMP-3 .
Back to top
View user's profile Send private message
technut

New User


Joined: 27 Dec 2007
Posts: 73
Location: India

PostPosted: Mon Mar 22, 2010 3:55 pm
Reply with quote

Hi Manikawnth,

Are you asking me to define FIELDNM as COMP variable?

Please clarify!
Back to top
View user's profile Send private message
manikawnth

New User


Joined: 07 Feb 2007
Posts: 61
Location: Mumbai

PostPosted: Mon Mar 22, 2010 3:57 pm
Reply with quote

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
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Question for file manager IBM Tools 7
No new posts question for Pedro TSO/ISPF 2
No new posts Convert HEX to Numeric DB2 3
No new posts Find a record count/numeric is multip... COBOL Programming 1
Search our Forums:

Back to Top