Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Question on Redefining alphanumeric to numeric

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Question on Redefining alphanumeric to numeric
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    Post subject:
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    Post subject:
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Mon Mar 22, 2010 2:21 pm    Post subject:
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: 1278
Location: Belgium

PostPosted: Mon Mar 22, 2010 2:26 pm    Post subject:
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: 1218
Location: Israel

PostPosted: Mon Mar 22, 2010 2:38 pm    Post subject:
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    Post subject:
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    Post subject: Reply to: Question on Redefining alphanumeric to numeric
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    Post subject:
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    Post subject: Reply to: Question on Redefining alphanumeric to numeric
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    Post subject:
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Mon Mar 22, 2010 3:21 pm    Post subject:
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    Post subject: Reply to: Question on Redefining alphanumeric to numeric
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts Fault Analyzer - listings question. egrove IBM Tools 4 Thu Aug 11, 2016 5:31 pm
No new posts Casting a Binary Number to Numeric in... Bob Steinkraus Java & MQSeries 6 Tue Aug 09, 2016 5:58 pm
No new posts dataset copy question - REPRO or some... atulxp TSO/ISPF 2 Wed Aug 03, 2016 10:56 pm
This topic is locked: you cannot edit posts or make replies. Alphanumeric to Numeric move on UNIX mistah kurtz COBOL Programming 16 Wed Jul 27, 2016 8:47 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us