340 pts.
 How to move an AS/400 numeric field to an alphanumeric field without disturbing the value in it?
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
  Help
 Approved Answer - Chosen by carlosdl

Try the EVALR op code.

ANSWERED:  Nov 23, 2010  4:52 PM (GMT)  by carlosdl

 
Other Answers:

Hey Phil,

You are a Genius.
It worked excellent!!
I tried all combinations of %EDITC but in vain, as I used only EVAL
I did not think of EVALR.
That solved my problem.
Great!!

Svanky

———————————————————————————————
Thanks but WoodEngineer deserves the <– approved button.
He identified the need for EVALR.

Good question and good responses.

Phil

Last Wiki Answer Submitted:  November 25, 2010  2:39 pm  by  philpl1jb   44,190 pts.
Latest Answer Wiki Contributors:  svankipu   340 pts.
To see other answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Use EVALR and EDITW(MyVar:’0 . ‘). After the ’0′ you must put 7 blanks, the decimal point and 2 more blanks.

Wilson

 2,385 pts.

 

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

 44,190 pts.

 

Hi,

Here is another solution:

charvar = %editc(numvar:'X'); // ... this keeps leading zeros

charvar = %editc(numvar:'Z'); // ... this suppresses leading zeroes

YuVa47

 1,285 pts.

 

Fixed !

Thanks for the observation Phil.

 63,535 pts.

 

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

 108,310 pts.

 

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

 44,190 pts.

 

Thank You very much WoodEngineer.
Sorry I never came back to this site after that. Sorry for the Delay in acknowledgement.

Svanky

 340 pts.

 

Hi there,

i have a problem getting the value -.50 to a char -0.50. This is possible?
 10 pts.

 
“…getting the value -.50 to a char -0.50. This is possible?”

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.

.
The first things we need to know are the definitions of the numeric and character fields. Then we need to know if you want the value left- or right-justified. Finally, we should know what you need the character field for. Is this going to be displayed on a screen? Put in a database file? Printed on a report? There are multiple methods that can be different for different uses.
.
Tom
 108,310 pts.