October 21


Doing Loop the Do Loops in RPG3 and RPG /Free

By NickLitten

October 21, 2020

RPG, doloop, forloop, freeform, modernization, RPG400, syntax

Do Loops in RPG

Whenever I find myself editing some old RPG3 or RPG400 code, I try to spend a coffee* cleaning the code up to a more modern and readable form.

* A ‘coffee’ is the amount of time it takes to drink a regular cup of brew. This is slightly shorter than the English standard time unit of a ‘tea’ because that also has ‘biscuits’ multiplied by ‘dunk’ to take into consideration.

Basic RPG Source Code cleanup is simple:

  • Use CVTRPGSRC if its old RPG3 stuff
  • Change ‘1’ to *ON
  • Change ‘0’ to *OFF
  • Change Z-ADD to EVAL
  • Decide how to EVAL all the MOVE and MOVEL opcodes
  • Insert comments where applicable
  • Remove crappy/old/redundant code where applicable
  • put some spaces between subroutines and blocks of functionally similar code
  • Then it’s into RDi and convert to /FREE

(If you don’t have RDi then check out its predecessor WDSC7. Websphere Development Studio Client is old technology but better than nothing and if you are not able to cough up $900 on IBM’s Rational Developer for i version… c’mon IBM come up with a sensible price for a source code editor!!! If you want us, Freelance Software Developers, to endorse and promote your editor it must be a price that we can afford! Obviously, the most sensible is $FREE.)

Having said that, cleaning old Do Loops in RPG3 can be a head scratching experience:

DO LOOPS are something that often cause me to scratch my head when uplifting to RPGLE. So just for my reference here is an example of the exact same code in RPG3, RPG400 and RPGLE (or RPG5 as its sometimes called).

Do Loops in RPG3 and RPG /Free


        DO   SAVRRN X
 X      IFGT 10


        EVAL    THING = PLOP + THING
 X      IFGT    10
        EVAL    RESULT = FIELD1 + FIELD2

RPGLE – also known as RPG /FreeFormat

For x = 1 to SAVRRN by 1;

 Thing += Plop; 

 If x > 10;
  Result = Field1 + Field2; 


/me loves some RPG Free format. It makes this lovely old RPG language readable and slinky 🙂

That was fun!

RPG Modernization in more detail

Modernizing rpg

The GOLDERN rules when modernizing old RPG programs is be careful!

  • Take Backups before you start
  • Take regular backups while you are working
  • Consider obvious logic changes
  • Consider the “what if” scenarios
  • Think outside the box
  • Test, Test and Test again

Legacy programs come in all shapes and sizes and the detail of modernization can swing between basic opcode uplifts to entire logic changes (for example removing indicators, moving subroutines in sub-procedures with local variables, or changing date variables from old 6/8 character numerics to modern 10 character date and timestamp variables)

Modernizing the code is like open heart surgery and needs a comprehensive test plan.

If you want to watch a real(ish)time recording of me modernizing some old RPG3 code then you can watch this thrilling dull video, which is part of the RPG Modernization Course

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

Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips