RPGIV – numeric field to character field

485 pts.
Tags:
iseries v5r4
RPG IV
Experience shows you cannot move a numeric field to a character field using EVAL - so what is the best method? Is Movel the only way? Thanks.

Software/Hardware used:
iSeries V5.4

Answer Wiki

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

EVAL FIELDC = %EDITC(FIELDN : ‘X’) <– use appropriate edit code for your purpose
Phil

////////

The X edit code ensures a hexadecimal F sign for positive fields and a hexadecimal D sign for negative fields. However, because the system does this, you normally do not have to specify this code. Leading zeros are not suppressed. <b>You can use %EDITC with the X edit code to convert a number to character with leading zeros. However, be aware that negative numbers can produce unexpected results; for example, %EDITC(-00123:’X’) will give the result ‘0012L’.</b>

Another method is

Eval FieldC = %Char(FieldN)

In this case leading zeros are suppressed and remember that you can use EVALR to right adjust (Move).

Wilson

————–
Excellent point Wilson.
You’ve got all the edit codes, edit words, and %Char to use with EVAL and EVALR.
Phil

Discuss This Question: 2  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
  • NeilD
    Thanks for your help guys. NeilD
    485 pointsBadges:
    report
  • Ramandeep
    EVAL Char_Field = %Char(Num_Field) is the best way of assigning Character to numeric value. In Somecase you may like to replace spaces with zeros by setting numeric value in right side. Use following in such cases.... EVALr Char_Field = %Char(Num_Field) Eval Char_Field = %Xlate(' ':'0':Char_Field)
    10 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