Doing Loop the Do Loops in RPG3 and RPG /Free 

 June 10, 2017

By  NickLitten

So, whenever possible, if I’m editing some old RPG3 or RPG400 code I spend a coffee* cleaning the code up to a more readable form. Cleaning old Do Loops in RPG3 can be a head scratching experience:

  • 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 its into RDi and convert to /FREE

(If you dont have RDi then checkout it’s predecessor WDSC7. Websphere Development Studio Client is old technology but better than nothing and if your not able to cough up $800 on IBM’s Rational Developer for i version… c’mon IBM come up with a sensible price for a source code editor. Obviously, the most sensible is $FREE.)

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


        DO   SAVRRN X
 X      IFGT 10


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

RPG4 – also known as RPGLE /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 šŸ™‚

* 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.


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!