How to move an AS/400 numeric field to an alphanumeric field without disturbing the value in it?

600 pts.
Tags:
AS/400
DB2/400
OS/400
RPG/400
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

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

Discuss This Question: 11  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • WoodEngineer
    Try the EVALR op code.
    6,650 pointsBadges:
    report
  • WilsonAlano
    Use EVALR and EDITW(MyVar:'0 . '). After the '0' you must put 7 blanks, the decimal point and 2 more blanks. Wilson
    2,485 pointsBadges:
    report
  • philpl1jb
    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
    49,940 pointsBadges:
    report
  • YuVa47
    Hi, Here is another solution:
    charvar = %editc(numvar:'X'); // ... this keeps leading zeros
    
    charvar = %editc(numvar:'Z'); // ... this suppresses leading zeroes
    
    YuVa47
    1,300 pointsBadges:
    report
  • carlosdl
    Fixed ! Thanks for the observation Phil.
    69,400 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • philpl1jb
    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
    49,940 pointsBadges:
    report
  • svankipu
    [...] How to move an AS/400 numeric field to an alphanumeric field without disturbing the value in it? [...]
    0 pointsBadges:
    report
  • svankipu
    Thank You very much WoodEngineer. Sorry I never came back to this site after that. Sorry for the Delay in acknowledgement. Svanky
    600 pointsBadges:
    report
  • rcvp87
    Hi there,
    i have a problem getting the value -.50 to a char -0.50. This is possible?
    10 pointsBadges:
    report
  • TomLiotta
    "...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
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following