View previous topic :: View next topic
|
Author |
Message |
softwareengineer
New User
Joined: 24 Aug 2005 Posts: 24 Location: Hyderabad
|
|
|
|
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 |
|
|
raak
Active User
Joined: 23 May 2006 Posts: 166 Location: chennai
|
|
|
|
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 |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
Why not actually test your question and DISPLAY the result field? |
|
Back to top |
|
|
rajesh_mbt
New User
Joined: 27 Mar 2006 Posts: 97 Location: India
|
|
|
|
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 |
|
|
sachin_star3 Warnings : 1 New User
Joined: 30 Sep 2006 Posts: 78 Location: pune
|
|
|
|
YES
RAJESH IS CORRECT
REMAING FILLED IS AUTOMATICALLY FILLED BY ZEROES
FROM -
SACHIN BORASE |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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
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
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
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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.
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 |
|
|
|