How to move a numeric field to an alphanumeric field without disturbing the value in it.
I have a numeric field(9,2) with value MyVar = 9876543.21
I need to move this (as it is)into an alphanumeric field(12 A), without distorting the value in it.
But if I use %CHAR, it gets moved along with decimals, but getting left-justified, leaving the blanks on right-side.
If i use %EDITC(MyVar:'X'), it gets moved left-justified; also the decimals are missing.
I think Numeric value should be right-justified right?
Pls. let me know if anybody has done this earlier.
Thanks very much,
Svanky
Software/Hardware used:
as/400, rpg/400, rpgle, db2/400, os/400
ASKED:
November 23, 2010 11:18 AM
UPDATED:
December 8, 2010 6:40 AM
Use EVALR and EDITW(MyVar:’0 . ‘). After the ’0′ you must put 7 blanks, the decimal point and 2 more blanks.
Wilson
or
EVALR myChar = %EDITC( myVar : ’4′)
the editcode format will determine if the values have a trailing blank/-, commas, zero values etc. If you choose a format the produces a format less than 12 characters long when working with 9.2 then you will get trailing blanks .. but the EVALR would remove all but the sign blank/- .. format ’4′ does not display the sign.
Phil
Hi,
Here is another solution:
YuVa47
Fixed !
Thanks for the observation Phil.
I think Numeric value should be right-justified right?
Maybe. Without knowing why you’re putting a numeric (9,2) into a 12A field in the first place, there’s no way to know.
Tom
Right Tom
Another possible solution was to make the character field the correct width to accomodate the actual data. So the field would be 10A if using format ’4′ .. 9 digits,1 decimal point.
Phil
Thank You very much WoodEngineer.
Sorry I never came back to this site after that. Sorry for the Delay in acknowledgement.
Svanky
Hi there,
It’s possible, though it has some very specific requirements. You’re asking for a leading sign instead of a trailing sign. And you’re also asking for a leading zero before the decimal point.