.st0{fill:#FFFFFF;}

Doing Loop the Do Loops in RPG3 and RPG /Free 

 October 21, 2020

By  NickLitten

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

RPG3

        DO   SAVRRN X
        ADD  PLOP THING
 X      IFGT 10
 FIELD1 CAT  FIELD2 RESULT 
        END
        END

RPG400

 DO     SAVRRN  X
        EVAL    THING = PLOP + THING
 X      IFGT    10
        EVAL    RESULT = FIELD1 + FIELD2
        ENDIF
        ENDDO

RPGLE – also known as RPG /FreeFormat

For x = 1 to SAVRRN by 1;

 Thing += Plop; 

 If x > 10;
  Result = Field1 + Field2; 
 Endif;

EndFor;  

/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

When modernizing old RPG programs be careful! They 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 the video here

NickLitten


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!

>