Page 1 of 1

Question about aplhanumeric to numeric cobol move

PostPosted: Fri Mar 27, 2015 10:45 pm
by gauravchaubey
I have tried the following code:
ws-var-alpha PIC X(4) value 'ABCD'
ws-var-num PIC 9(4) vaue zeros.

move ws-var-alpha to ws-var-num.
display 'ws-var-alph:' ws-var-alpha.
display 'ws-var-num:' ws-var-num.

I have received the following output:

ws-var-alph:ABCD
ws-var-num:ABC4

Anyone please explain how this value is coming in ws-var-num and why its not giving error.

Thanks in advance !

Re: Question about aplhanumeric to numeric cobol move

PostPosted: Fri Mar 27, 2015 11:46 pm
by Terry Heinze
Someone who knows Assembler can probably explain it better, but:
The 1st 3 characters of the source field get moved to the 1st 3 characters of the destination field.
Since the low-order nibble (half-byte) of the 4th character is a 4 (D is X'C4'), it gets moved to the low-order nibble of the 4th character.
COBOL forces an unsigned 'F' into the high-order nibble since the destination field is defined as numeric.

Re: Question about aplhanumeric to numeric cobol move

PostPosted: Sat Mar 28, 2015 12:03 am
by gauravchaubey
Thanks Terry, I understand your explanation.
But I am still wondering why its not giving SOC7 ?

Re: Question about aplhanumeric to numeric cobol move

PostPosted: Sat Mar 28, 2015 12:06 am
by BillyBoyo
Because you haven't done anything to get a S0C7 is the first thing. The second thing is that it is perfectly valid for doing numeric stuff with. Even if you did an ADD or something, you'd not get a S0C7.

Try with "ABC* and "AB*C".

Re: Question about aplhanumeric to numeric cobol move

PostPosted: Sat Mar 28, 2015 12:48 am
by Robert Sample
A S0C7 ABEND only occurs when you are attempting to use non-numeric data for arithmetic operations. The data exception occurs when converting zoned decimal to packed decimal and the zoned decimal value does not match the requirements for a zoned decimal number.