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