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

Need help to understand the behavior of MOVE


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Sun Sep 05, 2010 8:56 am
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
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

Moderator Emeritus


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

PostPosted: Sun Sep 05, 2010 9:53 am
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: 8700
Location: Dubuque, Iowa, USA

PostPosted: Sun Sep 05, 2010 6:32 pm
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
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
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: 8700
Location: Dubuque, Iowa, USA

PostPosted: Mon Sep 06, 2010 7:07 pm
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
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
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: 8700
Location: Dubuque, Iowa, USA

PostPosted: Tue Sep 07, 2010 12:09 am
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

Moderator Emeritus


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

PostPosted: Tue Sep 07, 2010 12:20 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts Try to understand IMS control block IMS DB/DC 0
No new posts How to move DB2 Installation HLQ DB2 4
No new posts How to move values from single dimens... COBOL Programming 1
Search our Forums:

Back to Top