Pages

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:

CRTSRCPF FILE(MYLIB/QRPGLESRC) RCDLEN(112) +
            TEXT('Source for RPGLE members')
CRTSRCPF FILE(MYLIB/QRPGSRC) TEXT('Source for RPG 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.

20 comments:

  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

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

    ReplyDelete
  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

    ReplyDelete
    Replies
    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.

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

      Delete
    3. Actually I love writing in free rpg

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

    ReplyDelete
  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 :)

    ReplyDelete
    Replies
    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.

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

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

      Delete
  6. Even in 2018 RPGIII is still being worked with. I work for a company using V7R1 and Movex ERP system 10.6 on top of that which was written in RPGIII back in 1997. I don’t work directly with the iSeries yet but the team that do, which consists of 2 people are Implementing a Warehouse Management System which the company wants to use into Movex. The team which looks after the iSeries are doing a lot of modifying to the Movex code to make this work, and are doing a remarkable job. I don’t know if they are converting the programs to RPGLE, I have not asked but they are very experienced so I would assume they are.
    I try to learn as much as I can from them.

    ReplyDelete
    Replies
    1. Just because you can does not make it a wise decision for you or your career.

      There is lots of software that runs on IBM i that was written in RPG3.

      There are many programmers who will still only use RPG3. It is a shame as with all the enhancements being made to modern RPG, they cannot use them. They have to create complex algorithms in RPG3 that come are part of modern RPG. For example date math (try adding 21 days to a date or calculate the number of days between two dates in RPG3 and you will see what I mean).

      I also wonder how many interviews you would pass if you admitted that you have not updated your skills since the 1990s! Could you say that and be taken seriously if we were talking about any other programming language?

      Delete
  7. I'm trying to become a IBM i dev in 2021. My training instructor believes the industry is still so heavily reliant on legacy (RPGIII) code that even new devs need to have a firm grasp of the paradigm. I think I'll probably want to move any code base I'm confronted with forward but I imagine there will always be a lot of push back from above (management) and below (inertia of the code itself).

    ReplyDelete
  8. I used CVTRPGSRC but getting error saying original member in original file in original library has unsupported members.. Please help.

    ReplyDelete
    Replies
    1. Check if the program has /COPY in it. CVTRPGSRC does not convert those external source members. You cannot have a RPGLE program with RPG copy members in it.

      You will have to convert those too, and possibly change the /COPY statements to use the converted members.

      Delete
  9. I made the type RPG and able to run the CVTRPGSRC command to move in new library with len 112. but code inside didn't get converted to free form... Any ideas why that didn't happen?

    ReplyDelete
    Replies
    1. CVTRPGSRC does not convert RPG to free form RPG. It just converts RPRG to fixed form RPGLE.

      Delete
  10. How do I resolve 'The type of specification is not valid or is out of sequence.' on every line of the code that I am want to convert to Free?

    ReplyDelete
    Replies
    1. As I mentioned above CVTRPGSRC does not create free format RPG code.
      You will have to check the generated RPGLE fixed format source to see what the problems are.

      Delete

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.