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
 

 

what happens to spaces when we move x(23) to 9(23) ?

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

New User


Joined: 24 Aug 2005
Posts: 24
Location: Hyderabad

PostPosted: Thu Feb 22, 2007 11:39 am    Post subject: what happens to spaces when we move x(23) to 9(23) ?
Reply with quote

What happens when we move spaces from x(23) to 9(23).....
For Ex:
if I move x(23) which has value ''123456789 '' to 9(23)....
what value wil be populated to Numeric value.....

How to pad zeroes instead of Spaces while this movement....as I need that Numeric value for computation??

Please help.
Back to top
View user's profile Send private message

raak

Active User


Joined: 23 May 2006
Posts: 166
Location: chennai

PostPosted: Thu Feb 22, 2007 12:39 pm    Post subject:
Reply with quote

To Pad Zeroes instead of Spaces while moving, u have to use

INSPECT VARIABLE-2 REPLACING ALL SPACES BY ZEROES.


And u have to define the Variable-2 which is 9(23) as JUSTIFIED RIGHT.
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


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

PostPosted: Thu Feb 22, 2007 6:36 pm    Post subject:
Reply with quote

Why not actually test your question and DISPLAY the result field?
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 95
Location: India

PostPosted: Fri Feb 23, 2007 11:07 am    Post subject: Re: what happens to spaces when we move x(23) to 9(23) ?
Reply with quote

softwareengineer wrote:
What happens when we move spaces from x(23) to 9(23).....
For Ex:
if I move x(23) which has value ''123456789 '' to 9(23)....
what value wil be populated to Numeric value.....

How to pad zeroes instead of Spaces while this movement....as I need that Numeric value for computation??

Please help.


Hi
I think it will start from Left to Right (Left alignment) since, the movement is from alpa-num to num, and the remaining space would be filled by zeros.

Eg

MOVE X TO N

WHERE X IS PIC X(10) VALUE ?12345?
N IS PIC 9(10).


For the above example.

N will contain 1234500000 unless you explicitly specify as right alignment.
Back to top
View user's profile Send private message
sachin_star3
Warnings : 1

New User


Joined: 30 Sep 2006
Posts: 78
Location: pune

PostPosted: Fri Feb 23, 2007 11:39 am    Post subject:
Reply with quote

YES
RAJESH IS CORRECT
REMAING FILLED IS AUTOMATICALLY FILLED BY ZEROES
FROM -
SACHIN BORASE
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: Fri Feb 23, 2007 9:33 pm    Post subject:
Reply with quote

Hello,

Rather that post what we think will happen, it is most often better to just run a little test and be sure what will happen (at least on your system),

This code
Code:
       01  SOMESTUFF3.                                   
           05 THE-XFIELD   PIC X(10) VALUE '12345     '.
           05 THE-NUMBER   PIC 9(10).                   

          MOVE THE-XFIELD TO THE-NUMBER. 
          DISPLAY THE-NUMBER.             

gives

Code:
12345    0

Changing the x field to
Code:
        05 THE-XFIELD   PIC X(10) VALUE '12345'.

gives the same result.

Code:
        05 THE-XFIELD   PIC X(10) VALUE '12345ABCD+'.   

gives
Code:
12345ABCD   


Changing the instructions to move a value into the x field, then moving the x field to the number
Code:
 
        MOVE 12345 TO THE-XFIELD.             
        MOVE THE-XFIELD TO THE-NUMBER.       
        DISPLAY THE-NUMBER.                   
        MOVE '12345__)) ' TO THE-XFIELD.     
        MOVE THE-XFIELD TO THE-NUMBER.       
        DISPLAY THE-NUMBER.                   

gives
Code:

12345    0   
12345__))0   


Note that in no case was the receiving field padded with zeros.

If you'd like to try any others, have a go on your system. . . .
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Feb 24, 2007 10:50 am    Post subject:
Reply with quote

Hi SE,

Probably the simplest way to "move" it is:
Code:

COMPUTE PIC-9 = FUNCTION NUMVAL (PIC-X)

These intrinsic functions (e.g. NUMVAL) can also be invoked thru LE subroutines (their prefix is CEE - check the manual for details).

One advantage is that they return a non-zero code when the sending field contains invalid data - e.g. 12Y456, where the FUNCTION will abend the pgm. But if you're sure of the content the FUNCTION approach might be OK.
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 Feb 25, 2007 12:24 am    Post subject:
Reply with quote

Hello,

Before the COMPUTE you could/should specifically check if NOT NUMERIC and deal with it before the code can abend - a programmed error message/user abend is far preferable to an 0c7 or other uncontrolled abend.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Feb 25, 2007 10:11 pm    Post subject:
Reply with quote

Hi Dick,

Unfortunately there may be spaces in the sending field causing the NUMERIC test to fail. I think the LE call may be the only way to get around that problem.

That, or the brute force method of moving it byte by byte to a zero filled receiving field, checking for non-numerics along the way.
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: Mon Feb 26, 2007 1:09 am    Post subject:
Reply with quote

Yup, there may be - i'm guessing there will be. I should have been more complete with my "NOT NUMERIC" suggestion.

For TS -

Before any "move" can be done with that PIC X data to some kind of numeric field, the rules for the field have to be defined. Are both leading and trailing spaces valid? Might there be commas, a decimal point, or a sign? And on, and on. . .

Simply changing the spaces to zeros will most likely give an undesirable result. Replacing 3 trailing spaces with 3 zeros just multiplied the value by 1000. icon_redface.gif

Putting the code into production without the proper edits is just begging for a call when the job abends in the middle of the night. . .
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 Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm
No new posts DB2 9.1.0 not move values to Host-Var... Miguel Fernandez DB2 8 Wed Jan 25, 2017 8:24 pm
No new posts DB2 9.1.0 not move values to Host-Var... Miguel Fernandez DB2 0 Wed Jan 25, 2017 8:23 pm
No new posts DB2 9.1.0 not move values to Host-Var... Miguel Fernandez DB2 0 Wed Jan 25, 2017 8:21 pm
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


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