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

Query regarding MOVE


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

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Fri Jan 07, 2011 2:20 pm
Reply with quote

Tried below code it works in cobol.
why ??
ws-num would not contain non numeric value.

Output of below code
ABCDE
ABCD5

Working-storage section
01 WS-GRP.
05 WS-NUM PIC 9(5).
05 WS-STR PIC X(10).
01 WS-NUM2 PIC 9(5).
Procedure division
MOVE 'ABCDEFGDHAK' TO WS-GRP.
MOVE WS-NUM TO WS-NUM2.
Display WS-NUM.
Display WS-NUM2.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 07, 2011 4:07 pm
Reply with quote

A very common mistake beginners make in COBOL is to think that a numeric variable will only contain numbers. THIS IS NOT TRUE! As your example shows, a numeric zoned decimal variable may contain numbers or letters and COBOL will not have any problem with that. If you added one to WS-NUM, you would find the value becomes 12345 due to the way COBOL does arithmetic.

It is the responsibility of the programmer to ensure that a numeric variable contains only numbers -- COBOL has no such rule and will not enforce any such restriction, as you have seen.
Back to top
View user's profile Send private message
bhairon singh rathore

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Fri Jan 07, 2011 4:14 pm
Reply with quote

Thanks Robert,

Then when the concept of SOC7 comes into picture
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 07, 2011 4:23 pm
Reply with quote

The S0C7 abend occurs when you do arithmetic with a packed decimal (note this is COMP-3) variable that contains data that does not match the packed decimal requirements. The zoned decimal variable you used would not cause a S0C7 abend because when you add 1 to it, the variable is first packed -- which ignores the first 4 bits of each byte -- then the addition is done to the packed decimal value then the value is unpacked, at which time the first 4 bits of each byte are set such that only numbers are present.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jan 07, 2011 4:25 pm
Reply with quote

keep in mind that PIC 9(9) or S9(9) is numeric DISPLAY usage
which are baiscally alphanumeric elements that can be used in arithmetic instructions. (where as alpha elemens - X) can not.

you enter the world of actual numeric elements when your usage is COMP-3.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Jan 07, 2011 4:27 pm
Reply with quote

'E' is x'C5', an unsigned move forces hex F in the sign nibble.
The fifth byte thus becomes x'F5', which is... '5' icon_exclaim.gif
Back to top
View user's profile Send private message
bhairon singh rathore

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Fri Jan 07, 2011 5:40 pm
Reply with quote

Thanks,
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Jan 07, 2011 6:07 pm
Reply with quote

Adding to Kjeld's post, after WS-NUM is loaded with ABCDE, move it to an S9(05) COMP-3 field and it will equal P'12345'.

Internally, a PACK instruction discards the zones (except for the last byte, where the byte is flipped and the zone becomes a sign-nibble). Plus, if the receiving field is signed, an internal ZAP is issued (after the PACK) of the packed-field itself to ensure a 'C' (or a 'D' for negative) sign-nibble.

However, if the receiving field is not signed, the compiler will issue an OI X'0F' against the last byte, instead of a ZAP, to ensure an 'F' sign-nibble.

Bill
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri Jan 07, 2011 6:26 pm
Reply with quote

Wrinkle

You may do arithmetic with an S9(5) DISPLAY, and under certain circumstances the compiled code will convert to packed-decimal and then convert back. If I remember, this is in fact to do an OI dealing with the sign.

The point is, invalid numeric in the originating field may then cause an S0C7, even though your field is DISPLAY.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Jan 07, 2011 7:59 pm
Reply with quote

Code:

03  WS-NUM PIC 9(05).
03  WS-NEUTRAL PIC 9(05) COMP-3.
03  WS-SIGNED PIC S9(05) COMP-3.

MOVE LOW-VALUES TO WS-NUM (1:).
MOVE WS-NUM TO WS-NEUTRAL.
MOVE WS-NUM TO WS-SIGNED.

The MOVE of LOW-VALUES to WS-NUM (1:) is legitimate because WS-NUM is treated by the compiler as if it were PIC X(05). Without the reference modification, you'd get a compile error.

The first MOVE of WS-NUM to WS-NEUTRAL will work and the result in WS-NEUTRAL will be X'00000F' or Packed-Neutral ('F' sign-nibble) as the compiler will issue an OI X'0F' against the last byte after the PACK.

The second MOVE of WS-NUM to WS-SIGNED will raise an 0C7 because a ZAP will be issued against the packed-field itself (after the PACK) and because the sign-nibble is X'0', the data-exception occurs.

Both examples are based upon the default compiler option of NUMPROC(NOPFD).

Use NUMPROC(PFD) at your own risk and consider the potential pitfalls.... ;o)

HTH....

Bill
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 RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
Search our Forums:

Back to Top