RPG Program Source Code – Clever or Clear?

  • Home
  • /
  • Blog
  • /
  • RPG Program Source Code – Clever or Clear?

August 8, 2017

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"}

Start your
7-day free trial

Take This Course with ALL ACCESS

Unlock your Learning Potential with instant access to every course and all new courses as they are released.
 [ For Serious Software Developers only ]

IBM i Training For Technology Experts


Successfully Work Remote 

 $ 129.00  $59.00

By adding new skills in information technology, employers will be confident that you have the necessary skills and tools needed to successfully work remotely


Snug CBD

 20% Discount

I have partnered with SNUG CBD givING you Organic CBD
20% discount code "NL20"