How do I right adjust a numeric into an alpha field using RPG4?
I have a NUMERIC in an RPG program that I want to move RIGHT into an Alpha field. In the old days of RPG3 I would use MOVE but in the new days of RPG4 I have a couple of more flexible solutions. So, lets say we have a numeric field containing the number 1234, defined as an signed numeric 10 long it would be stored as - 0000000123. And a Result field which is a big long alpha field:
d $Numeric s 10s 0 inz(1234)
d $Result s 10a inz(*BLANKS)
With Zero Suppression
If we want to be tranformed right justified as ' 1234'' then:
Eval(r) ResultVariable = %char($Numeric);
Note that the %CHAR %BIF will zero suppress the front of any numeric value.
Without Zero Suppression
If we want to be right justified and show the entire number '0000001234'' then:
Eval(r) ResultVariable = %editc($Numeric:'X');
Yes - I know! That EDITC %BIF is ugly isnt it?
But It works and thats how we do it. It's easy once you get used to it, but I'm still left with the wish that that Lords of RPG Programmer Grammer had enforced a nice rule on the %CHAR to perhaps allow us something like %char($Numeric:*NOSUPPRESS) or something like that...
But Hey Ho. :(
