Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Need help to understand the behavior of MOVE

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Prasun De

New User


Joined: 17 Jan 2008
Posts: 28
Location: Kolkata, INDIA

PostPosted: Sun Sep 05, 2010 8:39 am    Post subject: Need help to understand the behavior of MOVE
Reply with quote

A PIC X(3) VALUE 'AAA'
B PIC 9(3)

MOVE A TO B
Display B

The above code displays AA1 in sysout.

Please help me understand this. This was actually an interview question. I told it will be a SOC7 But when I tried it is going over my head.
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sun Sep 05, 2010 8:56 am    Post subject:
Reply with quote

Hello,

I believe we would all be better off if it actually did abend. . . icon_smile.gif

Unfortunately, what you have observed is the way it is supposed to work (i.e. it is a feature rather than a problem).

The hex for AAA is x'C1C1C1'. When this is moved to an unsigned zoned decimal field, the sign is converted to an "F" sign (assumed positive).

Change B to pic s9(3) and run again. . .
Back to top
View user's profile Send private message
Prasun De

New User


Joined: 17 Jan 2008
Posts: 28
Location: Kolkata, INDIA

PostPosted: Sun Sep 05, 2010 9:39 am    Post subject:
Reply with quote

Yes, I tried and got it dispalyed as AAA,

So what I'm getting is, For unsigned zoned decimal the assumed positive sign is inserted into the last byte but for Signed zoned decimal, the Sign is stored separately...
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sun Sep 05, 2010 9:53 am    Post subject:
Reply with quote

Hello,

Well, not really "separately".

A signed +1 is an x'C1' which is an A when displayed. An unsigned 1 is an x'F1' which is a 1 when displayed. And to complete the set, a signed -1 is an x"D1' which is a J when displayed.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Sun Sep 05, 2010 6:32 pm    Post subject:
Reply with quote

Quote:
So what I'm getting is, For unsigned zoned decimal the assumed positive sign is inserted into the last byte but for Signed zoned decimal, the Sign is stored separately...
No, you need to click on the manuals link at the top of the page, find the COBOL Language Reference manual sections about internal representation of the different formats of variables, and read it thoroughly. Your question indicates you have no understanding of the internal formats of variables and any competent COBOL programmer should have a good understanding of this topic.
Back to top
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Mon Sep 06, 2010 4:29 pm    Post subject: Reply to: Need help to understand the behavior of MOVE
Reply with quote

@Robert & @Dick - I have a question.

In the above scenario, the sending field is alphanumeric and receiving is Numeric(Usahe Display).
So it should follow the rule stated in elementary move from alphanumeric to numeric.....
Which says, it is possible but and i quote from manual
Quote:
Figurative constants and nonnumeric literals must consist only of numeric characters and X will be treated as numeric integer fields.


Which means...when the sending field contains numeric values....then only the move is possible.

But the above scenario doesn't conform to the manual.

Am i missing something?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Sep 06, 2010 4:49 pm    Post subject:
Reply with quote

you keep using numeric display fields, which are basically alphanumeric,
but allows the CLASS test IF NUMERIC.

otherwise, numeric display fields allow any type of garbage to be moved in.
if the PIC clause has a sign, the sign byte will be moved but ignoring the high-order bits.

if you want to discuss numeric move rules, deal with a numeric field - comp-3.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Mon Sep 06, 2010 7:07 pm    Post subject:
Reply with quote

saurabh39, you missed this quote from section 6.2.24.1.1 of the COBOL Language Reference manual on elementary move rules, talking about numeric receiving fields:
Quote:
When the category of the sending item is alphanumeric, alphanumeric-edited, national, or national-edited, the data is moved as if the sending item were described as an unsigned integer.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Mon Sep 06, 2010 8:58 pm    Post subject: Re: Reply to: Need help to understand the behavior of MOVE
Reply with quote

saurabh39 wrote:
@Robert & @Dick - I have a question.

In the above scenario, the sending field is alphanumeric and receiving is Numeric(Usahe Display).
So it should follow the rule stated in elementary move from alphanumeric to numeric.....
Which says, it is possible but and i quote from manual
Quote:
Figurative constants and nonnumeric literals must consist only of numeric characters and X will be treated as numeric integer fields.


Which means...when the sending field contains numeric values....then only the move is possible.

But the above scenario doesn't conform to the manual.

Am i missing something?

Your excerpt from the manual deals with figurative constants and literals (i.e. hardcoded values), not general move logic.
Back to top
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Mon Sep 06, 2010 10:43 pm    Post subject: Reply to: Need help to understand the behavior of MOVE
Reply with quote

Thanks Robert & Kjeld for clarification.
Yes my missed the below quote(my mistake)

Quote:

When the category of the sending item is alphanumeric, alphanumeric-edited, national, or national-edited, the data is moved as if the sending item were described as an unsigned integer.


But now I have another question, if Alphanumeric sending item is treated as unsigned integer, then all the alphanumeric to numeric move should be valid, then in what case will we get SOC7.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Tue Sep 07, 2010 12:09 am    Post subject:
Reply with quote

You misunderstand again -- alphanumeric sending items being treated as unsigned integer does not mean any conversion of characters to numbers will occur. If you move an AAA to a PIC S9(03) COMP-3 variable, you'll still get a S0C7 abend. Unsigned integer means the decimal point is aligned after the last character of the sending variable, and no sign conversion will be attempted -- and nothing else is meant or implied by the quoted statement. Invalid data in the sending variable still causes S0C7 abends.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Sep 07, 2010 12:20 am    Post subject:
Reply with quote

Hello,

Quote:
then all the alphanumeric to numeric move should be valid
Why do you believe thie?

You need to spend much more time doing research and should probably run 100 or more experiments using all kinds of data definitions and values.

When there was a better method of training, this type of question was for curiosity/learning rather than for implementation. Every numeric "input" field was completely edited before the code moved the field or tried to use it in a numeric comparison or computation. There was a substantial penalty for "being slack" by not incorporating complete validity checking.
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
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm
No new posts CICS NEW SIT PARAMETERS CICS BEHAVIOR... Kyle Carroll CICS 0 Fri Nov 04, 2016 11:55 pm
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
This topic is locked: you cannot edit posts or make replies. Alphanumeric to Numeric move on UNIX mistah kurtz COBOL Programming 16 Wed Jul 27, 2016 8:47 pm
No new posts Need information on COBOL MOVE CORRES... subratarec COBOL Programming 10 Tue Jun 28, 2016 10:38 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us