Doing Loop the Do Loops in RPG3 and RPG /Free

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

RPG3

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

RPG400

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

RPG4 – also known as RPGLE /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 🙂

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

(0 votes) 0/10