Page 1 of 1

MOVE alphanumeric to numeric and S0C7.

Posted: Thu Sep 05, 2013 10:19 am
by Neeraj N
Hi,

I've been asked that if can we move the alphanumeric value to numeric variable? For example,

Code: Select all

01 WS-ALPHA PIC X(4) VALUE 'ABCD'.
01 WS-NUM    PIC S9(3).
If we move WS-ALPHA to WS-NUM - will that be allowed?

My answer was yes we can move.

Then I was asked that will it get S0C7?

I said MOVE will not cause abend. if WS-NUM was comp-3, it could have S0C7 but with the definitions above there will not be any S0C7 by only MOVE. Possibly a COMPUTE might generate a S0C7 but not the MOVE.

Please help me to understand if it's correct.

Thanks,

Re: MOVE alphanumeric to numeric and S0C7.

Posted: Thu Sep 05, 2013 11:59 am
by William Collins
Well, some of what you have said is correct. Howerver, why don't you try it? With a USAGE DISPLAY numeric and a PACKED-DECIMAL/COMP-3. Then look at the Language Reference and the Programming Guide to see if you can clear it up yourself, and then come back here with any problems you still have.

You are correct when you say that the MOVE will not abend, but not when you think a COMPUTE might, althoug that could be true with other data. Also, with that data, you won't have a problem with PACKED-DECIMAL/COMP-3.

Re: MOVE alphanumeric to numeric and S0C7.

Posted: Sun Sep 22, 2013 6:04 pm
by Neeraj N
William Collins wrote:Howerver, why don't you try it? With a USAGE DISPLAY numeric and a PACKED-DECIMAL/COMP-3. Then look at the Language Reference and the Programming Guide to see if you can clear it up yourself, and then come back here with any problems you still have.
Thanks for the guidance William, however, unfortunately I don have Mainframe Access these days and can not experiment this... :oops:. And that's why appearing in Interviews.

I'm trying to get the Hercules working on my PC but that's a daunting task in itself...

Re: MOVE alphanumeric to numeric and S0C7.

Posted: Sun Sep 22, 2013 8:05 pm
by William Collins
OK. These days it is ulikely that the MOVE itself will have an instruction generated which will cause an abend.

Using the subsequent result for calculation is a different thing.

Here is your number (S9(3)).

Code: Select all

ZNZNSN
The right-most half byte of each byte is the "Numeric" nybble - and should always contain a hexadecimal 0-9. If it does not, any calculation with it will cause an abend (S0C7).

The left-most half-byte of the right-most byte is the "Sign" nybble - and should always contain a hexadecimal A-F. If it does not, any calculation with it will cause an abend (S0C7).

The remaining left-most half-byte are the "Zone" nybbles. As these are simply discarded when a Numeric (PIC 9 field with not COMP*) is "packed" for some calculation, they may contain any value and have no affect at all on the processing.

In your example there can not possibly in any circumstance be a S0C7. You should check, since you have a four-byte alpha-numeric and a three-byte numeric, which byte gets truncated.

Code: Select all

X'F1F2'
X'F1C2'
X'F1E2'
X'C1F2'
X'91F2'
X'F1C2'
X'C1C2'
X'F112'
X'F1FF'

MOVE PIC XX TO PIC S99.
You should be able to explain for each X'hhhh' example what the outcome will be - the value, or S0C7, from what I have described and from reading the Language Reference and Programmer's Guide where necessary.

Re: MOVE alphanumeric to numeric and S0C7.

Posted: Mon Sep 21, 2015 12:12 pm
by Neeraj N
Thanks William.

What is this number referring to? I don't understand it:
William Collins wrote:Here is your number (S9(3)).

Code: Select all

ZNZNSN

Re: MOVE alphanumeric to numeric and S0C7.

Posted: Mon Sep 21, 2015 3:11 pm
by William Collins
Z is for Zone, N is for Numeric. S is for Sign. Your number is PIC S9(3), so it appears as Z-N-Z-N-S-N in half-bytes or ZN-ZN-SN in bytes.

An example. If you have positive 123 in the field, it is stored as F1F2C3, where the Fs are the Zone, the digits are the Numeric, and the C is the Sign.

Re: MOVE alphanumeric to numeric and S0C7.

Posted: Mon Sep 21, 2015 3:48 pm
by William Collins
Just realised this is almost exactly two years later :-)

Re: MOVE alphanumeric to numeric and S0C7.

Posted: Mon Mar 28, 2016 11:24 am
by Neeraj N
William Collins wrote:Just realised this is almost exactly two years later :-)
On our client machines Internet is blocked and we don't get to access site like this, so the delay. :(