Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Query regarding MOVE

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Query regarding MOVE
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: 8154
Location: East Dubuque, Illinois, USA

PostPosted: Fri Jan 07, 2011 4:07 pm    Post subject:
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    Post subject:
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: 8154
Location: East Dubuque, Illinois, USA

PostPosted: Fri Jan 07, 2011 4:23 pm    Post subject:
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: 6968
Location: porcelain throne

PostPosted: Fri Jan 07, 2011 4:25 pm    Post subject:
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    Post subject:
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    Post subject:
Reply with quote

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

CICS Moderator


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

PostPosted: Fri Jan 07, 2011 6:07 pm    Post subject: Reply to: Query regarding MOVE
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

Active Member


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

PostPosted: Fri Jan 07, 2011 6:26 pm    Post subject:
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: 2504
Location: Atlanta, Georgia, USA

PostPosted: Fri Jan 07, 2011 7:59 pm    Post subject: Reply to: Query regarding MOVE
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    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 Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Move from Comp3 variable to Edited Va... sreekusr COBOL Programming 8 Thu Aug 10, 2017 4:20 pm
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us