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

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


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

Senior Member


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

PostPosted: Thu Feb 22, 2007 6:36 pm
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: 97
Location: India

PostPosted: Fri Feb 23, 2007 11:07 am
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
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

Moderator Emeritus


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

PostPosted: Fri Feb 23, 2007 9:33 pm
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
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

Moderator Emeritus


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

PostPosted: Sun Feb 25, 2007 12:24 am
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
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

Moderator Emeritus


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

PostPosted: Mon Feb 26, 2007 1:09 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Cobol program with sequence number ra... COBOL Programming 5
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts To Remove spaces (which is in hex for... JCL & VSAM 10
Search our Forums:

Back to Top