RPG Evolution, Modernization and Refactoring – Setting RPG Free

Setting RPG Free

Convert RPG from Column to Free Format Version 1

So, if we take the code and actually upgrade it to be the freeformat style of RPG/Free we can see all the mainline specs are now written in freeform code style.

Kind of!

For ten years we had Freeform RPG. But it wasn't really fully freeform because the Header specs, File specs and Data definitions still remained in column based so let's go through this step first:

h datfmt(*iso) timfmt(*iso) option(*nodebugio) debug
// system name: fix slp06
// program desc: fix the records on slp06 - Setting RPG Free
// program no: ef001
// date: 09/09/09 (sadly not at 9:09)
// author: nick@nicklitten.com
Fefp01l01 if e k disk infsr(*pssr)
Facsummar uf e k disk infsr(*pssr)
// Externally defined file defn's for *LDA and *PSDS
D lda e ds extname(lda) dtaara(*LDA)
D pstat esds extname(psds)

 in lda;
 setll l#cono acsummar;
 reade l#cono acsummar;

 dow not %eof(acsummar);
   // get customer order total from work file (efp01) which
   // is generated by accumulating OEP65 invoices
   chain cusn06 efp01l01;
   if %found(efp01l01);
     bodv06 = amount;
     bodv06 = 0;
   update slr06;
   // Update Account Balances new Order Total
   reade l#cono acsummar;

// --- Program Termination ---
out lda;
*inlr = *on;

//standard error handling routine.
/include qgpl/qrpglesrc,pssr

This is the same program in RPG Free Format.

As you can see, I've spaced the code out to make it more readable, added comments, Key Lists are now listed by field and Eval statements are not required and generally kicked it around a bit.

I think it's a huge improvement in readability.

Easier code to read means easier to maintain means saving time means saving money!

What do you think?

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}