Wednesday, June 12, 2013

RPG III let it rest in peace

When the IBM System/38 was released, in 1978, it came with a new version of RPG, RPG III. This was a language that was very advanced for its time, introducing many features we recognize in today's RPG. When the AS400 was released in 1988 it too had RPG III as its main programming language.

Now, 35 years after its birth it is time to let RPG III go and let it RIP.

When OS/400 V5R1 was released, 2001, IBM said that they would be no longer adding anything new to RPG III, and that RPG IV, first introduced in V3R1 in 1994, was the way to go.

Since then IBM has added all kinds of built in functions and features to RPG IV, and now RPG/free, that make it a much better and easier language to work with.

I currently work in a very heterogeneous software environment on the IBM i where some of the software is home-grown and the rest is purchased from software vendors. When making modifications to the home-grown code I often encounter a RPG, or even RPG38, source member. Rather than modify the RPG member I convert it to RPGLE, RPG IV, and make the changes in that. Why? I can incorporate the modern features and functions of the RPG IV into the code to simplify my modification and increase my productivity.

When converting RPG members to RPGLE you need to aware of the following are not supported in RPGLE:

  • Auto report function.
  • FREE operation code.
  • DEBUG operation code.

There is also the difference in size of the source member. RPG source members are 80 characters, with an additional 12 character for the source sequence number and the date, which makes a source member size of 92 characters. RPGLE members are 100 characters, with the same additional characters, makes the source member 112 characters.

When creating the source files you have to enter the record length (RCDLEN) for QRPGLESRC, but not for QRPGSRC as the default it 92:

            TEXT('Source for RPGLE members')

There is a command, CVTRPGSRC, that does the conversion of the source. It does not change code layout, except where required, and it does not create perfect RPGLE code, but it is better than having to convert the source yourself.

CVTRPGSRC will convert member types: RPG, RPT, RPG38 , RPT38, SQLRPG.
It does not: RPG36, RPT36.

Below shows how I use the command, notice that I...

  • Expand copy member, i.e. include all the code from any /COPY source members.
  • Do not bother with the Log file. If there is an error a report is produced listing them.

           Convert RPG Source (CVTRPGSRC)

 Type choices, press Enter.

 From file  . . . . . . . . . . . > QRPGSRC   
   Library  . . . . . . . . . . . >   MYLIB     
 From member  . . . . . . . . . . > TESTRPG   
 To file  . . . . . . . . . . . . > QRPGLESRC 
   Library  . . . . . . . . . . . >   MYLIB     
 To member  . . . . . . . . . . . > *FROMMBR  

                Additional Parameters

 Expand copy member . . . . . . . > *YES
 Log file . . . . . . . . . . . . > *NONE     
   Library  . . . . . . . . . . .               

You can see an error report I generated here»

Below is an example of a very simple RPG program I converted to RPGLE.

Original RPG
FTESTLF  UF  E           K        DISK                      A
C                     MOVE 'GO'      ACTION
C           ACTION    CHAINTESTLFR              01
C           *IN01     IFEQ *ON
C                     WRITETESTLFR
C                     ELSE
C                     UPDATTESTLFR
C                     ENDIF
C                     MOVE *ON       *INLR
Converted RPGLE
FTESTLF    UF A E           K DISK
C                   MOVE      'GO'          ACTION
C     ACTION        CHAIN     TESTLFR                            01
C     *IN01         IFEQ      *ON
C                   WRITE     TESTLFR
C                   ELSE
C                   UPDATE    TESTLFR
C                   ENDIF
C                   MOVE      *ON           *INLR

They look the same, but now I can include RPG IV operations and built in functions in the converted source, for example for date validation, which I could not do in the original RPG member.

You can learn more about the CVTRPGSRC command from the IBM website here»


This article was written for IBM i 7.1, and it should be compatible with earlier releases.


  1. simon actually the money is with the guys who can maintain the old code you right would not write new programs in anything other than free rpg but in most shops nowadays very rarely writing new programs ...mostly modifying old rpg 3 programs

  2. As I mention above, I work in such an environment where we still have many hundreds of RPGIII programs. Every time we need to modify one we convert it to RPGLE & then make the modification. Then you can start using the RPGLE features that make it a so much better language than RPGIII. The code you will add will be more efficient, & you will be a more efficient (less time to make mods) & more valuable employee.

    For example: Date & time handling. In RPGIII it is not easy, in RPGLE it is a breeze.

  3. no doubt you right ...but a small change to an rpg3 program with very localised testing or a complete retest because you converted it ...I love using free etc but my boss hates me converting old programs after all if you are just using the ile converter you dont gain much

    1. When RPGLE first came out I managed to get documentation from IBM i explaining how that the compilers all changed with the introduction of ILE & that objects created using ILE (RPGLE, CLLE, etc) produce a smaller & more efficient object.

      Being a skeptic I put it to the test on a E70 (yes it was that long ago) with three programs:
      1. RPGIII written by another program to ensure I could not be accused of bias.
      2. The RPGLE version of the RPGIII program that has been converted using the IBM conversion tool.
      3. I wrote the RPGLE based on the original RPGIII using EVAL, date & time etc.

      The numbers I saw the fastest was No.3, the slowest No.1.

    2. You can write efficient code in RPGIII, but I am sure any RPG programmer can write code that is at least as good if not better in RPGLE.

    3. Actually I love writing in free rpg

  4. About the /free option of ILE:
    I work with an environment hat contains RPG3 und ILE sources side by side. We have a compilation tool in use that is capable of doing the conversion to ILE on compile time, so most of the sources in RPG3 stay RPG3 but are compiled as ILE to make them debuggable more easy. Although ILE has so many advantages but at least /free has one disadvantage: If you do not work very strict on your code formatting using free easily can create unreadable spagetti code. It is very important to indent the lines correctly using /free or you may get a mess like seen in other languages. Using the old, column orientated type of code, regardless of using RPG3 or ILE prevents this, even if you must implement some things more difficult. Of course Iam sure there are formatting tools somewhere, but we do not have such on our system, Maybe I am just a vintage lover as I started with RPG3 , but I use /Free only if it really provides advantages. Many programs contain little /free code and many code in column orientation. I think making both possible in ILE was a correct decision from IBM. Whatever, this option makes ILE RPG a unique language.

  5. when, someone like myself inherits a system written entirely in RPG3 that's what you have to learn first and naturally start modifying programs and writing new code in it. the system is due to be replaced years ago although I I'd to try putting sql into rpg. and I might write my first RPG4 program to do this. But I'm in no position to let RPG3 rest in peace on a live system with some massive monolithic programs 30k lines you have to modify. add new fields into the labyrinth trying to intuit your way around. test it in the live environment and copy the programs to live. RPG3 is refusing to rest in peace so long as these programs are still running :)

    1. Why modify RPGIII programs?
      At least you should convert them to RPGLE and modify them in modern RPG. This way you are taking the first step in placing the old with the new.

    2. We did that. Couldn't wait to convert. Got burned a couple times.
      When this code
      C ADD 1 @COUNT
      is converted to this code
      C EVAL @COUNT = @COUNT + 1
      You could experience this error
      Receiver value too small to hold result.
      In your legacy app it could have been anticipated and expected as part of the design to roll over to zero with the left most digit dropped. Not in ILE, at least not without issuing a hard error. If you're the old programmer then you may catch it when you convert. The new guy most likely won't.

      All I'm saying is you're taking a chance on introducing a problem that wasn't there before. Fix it but don't break it.

    3. I agree, with most things the first time you try it you get burnt. But the trick is to learn from those errors.

      Note: This should not be used as an excuse not to move to RPGLE/RPGIV.


To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.