.st0{fill:#FFFFFF;}

Right Adjust Numeric into Alpha field using RPG Free 

 July 26, 2017

By  NickLitten

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:

dcl-s myNumber zoned(10:0) inz(1234)
dcl-s myAlpha char(10) inz(*BLANKS)

RPG Code Snippet Right Adjust Numeric

Some programmers will forget that a = b is actually eval a = b because the eval is silent šŸ™‚

We have two easy ways of transforming using RPG4:

With Zero Suppression

If we want to be transformed right justified as ‘ 1234” then:

Eval(r) ResultVariable = %char(myNumber);

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(myNumber:'X');

Yes – I know! That EDITC %BIF is ugly isnt it?

But it works and that’s 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 Grammar had enforced a nice rule on the %CHAR to perhaps allow us something like %char(:*NOSUPPRESS) or something like that…

But Hey Ho. šŸ™

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"cff50":{"name":"Main Accent","parent":-1},"a344d":{"name":"Accent Transparent","parent":"cff50"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"cff50":{"val":"var(--tcb-skin-color-0)"},"a344d":{"val":"rgba(46, 138, 229, 0.85)","hsl_parent_dependency":{"h":210,"l":0.54,"s":0.78}}},"gradients":[]},"original":{"colors":{"cff50":{"val":"rgb(0, 178, 255)","hsl":{"h":198,"s":1,"l":0.5}},"a344d":{"val":"rgba(0, 178, 255, 0.85)","hsl_parent_dependency":{"h":198,"s":1,"l":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__

Get In Touch

Iā€™m always looking for awesome input, feedback and critique!

>