380 pts.
 RPGIV – numeric field to character field
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
ASKED: October 2, 2009  9:01 AM
UPDATED: October 5, 2009  10:34 AM

Answer Wiki:
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
Last Wiki Answer Submitted:  October 2, 2009  3:02 pm  by  WilsonAlano   2,385 pts.
All Answer Wiki Contributors:  WilsonAlano   2,385 pts. , philpl1jb   44,200 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


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


 

Thanks for your help guys.

NeilD

 380 pts.

 

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 pts.