Question about aplhanumeric to numeric cobol move



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Question about aplhanumeric to numeric cobol move

Postby gauravchaubey » Fri Mar 27, 2015 10:45 pm

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 !
gauravchaubey
 
Posts: 2
Joined: Sun Feb 24, 2013 7:45 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Question about aplhanumeric to numeric cobol move

Postby Terry Heinze » Fri Mar 27, 2015 11:46 pm

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.
.... Terry
Terry Heinze
 
Posts: 239
Joined: Wed Dec 04, 2013 11:08 pm
Location: Richfield, MN, USA
Has thanked: 12 times
Been thanked: 11 times

Re: Question about aplhanumeric to numeric cobol move

Postby gauravchaubey » Sat Mar 28, 2015 12:03 am

Thanks Terry, I understand your explanation.
But I am still wondering why its not giving SOC7 ?
gauravchaubey
 
Posts: 2
Joined: Sun Feb 24, 2013 7:45 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Question about aplhanumeric to numeric cobol move

Postby BillyBoyo » Sat Mar 28, 2015 12:06 am

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".
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Question about aplhanumeric to numeric cobol move

Postby Robert Sample » Sat Mar 28, 2015 12:48 am

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.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post