RPG Program Source Code – Clever or Clear? 

 August 8, 2017

By  NickLitten

I’ve been working on an interesting project focused on taking some old RPG code and re-factoring it to make it more efficient. Fascinating work for a client that is focused on doubling its IBM i throughput and reducing the CPU load of all its old programs. This has frequently made me choose between writing a single line of %BIF’d up code that looks slick and minimalist – or – using clear rpg programming standards aka: writing multiple lines of code that are more readable and arguably (marginally) less efficient.

/me remembers the AS400 “SETON vs MOVEL *ON” arguments of yesteryear with a fond smile…

My official position on this: I prefer code readability over specialized (aka clever!) techniques.

I would rather write code that is a little more verbose, and well commented rather than do the same thing in a cryptic or obfuscated manner.

I just had to decipher this RPGLE line of code, because it was just too long and verbose but with no comments whatsoever:

BackDoorExtns = %Trim(BackDoorExtns) + 'CEL' + '000' + %Char(%len(%Trim(cleanCellNumber))) + %char(%DEC(cleanCellNumber:MoreCellPrec:MoreCellDec)) ;

This line of code basically receves an incoming cellphone, from a JSON webservice input, and converts to numeric (with the %DEC BIF) and then puts it in this string (backdoorExtns) but this line of code will BOMB if the cleanCellNumber variable has alphameric values so I changed it to:

RPG Code Snippet clear rpg programming standards//Calculate cellphone number (morecell) and wrap in string with "CEL" control code at start
// JSON inputs the cellphone in incoming character field "cleanCellNumber" but if
// its actually dirty/non-numeric then set to *ZERO
   morecell = %DEC(cleanCellNumber:MoreCellPrec:MoreCellDec); 
   EvalR MskLen = '000' + %Char(%len(%Trim(cleanCellNumber)));
   BackDoorExtns = %Trim(BackDoorExtns) + 
                  'CEL' + MskLen + %char(morecell) ; 
   updateThisReservation = *on; 
on-error 105; 
    morecell = 0; 

Yes, I’m guilty of waffling in my comments and sometimes using variable names that make me smile:

If WhiskyEmpty;

Remember, Software undergoes beta testing just before it’s released.

Beta is Latin for “the program still doesn’t work”.


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!