CVTRPGSRC – the first step in modernizing RPG3 or RPG400 to modern RPGLE Freeform

IBM i

Aug 02

Convert RPG Source

This is a standard IBM i command which will ‘Convert RPG Source’ (CVTRPGSRC) from RPG III or RPG/400 source code to ILE RPG source code.

If you are running on a system using the old (1980’s format) RPG source code — easily recognisable because it uses the short column widths and has limitation like 6 character field names — then this is the firs step in code modernization. The CVTRPGSRC command will take the old RPG format and increase it RPGLE format (ten character field names, new opcodes and ability to enter the RPG code in /free format)

Here is a simple program in RPG3:

 ‚H*****************************************************************
 ‚H* EXAMPLE RPG3 Program receiving parms, reading file and *
 ‚H* returning values in *LDA (JBA/System21 style) *
 ‚H*****************************************************************
 H 1
 FCOMPANY IF E K DISK KINFSR *PSSR
 ILDA E DSLDA
 IPSTAT ESDSPSDS
 C EXSR INIT
 C K01 CHAINCOMPANY 01
 C *IN01 IFEQ *OFF
 C MOVELVTID01 VTIDPM
 C ELSE
 C MOVEL*ALL'9' VTIDPM
 C END
 C OUT LDA
 C MOVEL*ON *INLR
 ‚C*****************************************************************
 ‚C* init subroutine
 ‚C*
 ‚C*****************************************************************
 C INIT BEGSR
 ‚C* get the lda
 C *NAMVAR DEFN *LDA LDA
 C IN LDA
 C* Get the parms
 C *ENTRY PLIST
 C PARM CONOPM 2
 C PARM VTIDPM 20
 ‚C* Key Fields
 C K01 KLIST
 C KFLD CONOPM
 C ENDSR
 ‚C*****************************************************************
 ‚C* standard error handling routine.
 C/COPY OSLCOPYSRC/QRPGSRC,PSSR
 ‚C*****************************************************************

So, lets process this using CVTRPGSRC:

CVTRPGSRC FROMFILE(NLITTEN/QRPGSRC)
FROMMBR(RPG3)
TOFILE(NLITTEN/QRPGLESRC)
TOMBR(RPGLE)
LOGFILE(*NONE)

When we run this it generates a new RPGLE version of the code in QRPGLESRC source and it looks like this:

 H*****************************************************************
 H* EXAMPLE RPG3 Program receiving parms, reading file and *
 H* returning values in *LDA (JBA/System21 style) *
 H*****************************************************************
 H DEBUG
 FCOMPANY IF E K DISK INFSR(*PSSR)
 D LDA E DS EXTNAME(LDA)
 D PSTAT ESDS EXTNAME(PSDS)
 C EXSR INIT
 C K01 CHAIN COMPANY 01
 C *IN01 IFEQ *OFF
 C MOVEL VTID01 VTIDPM
 C ELSE
 C MOVEL *ALL'9' VTIDPM
 C END
 C OUT LDA
 C MOVEL *ON *INLR
 C*****************************************************************
 C* init subroutine
 C*
 C*****************************************************************
 C INIT BEGSR
 C* get the lda
 C *DTAARA DEFINE *LDA LDA
 C IN LDA
 C* Get the parms
 C *ENTRY PLIST
 C PARM CONOPM 2
 C PARM VTIDPM 20
 C* Key Fields
 C K01 KLIST
 C KFLD CONOPM
 C ENDSR
 C*****************************************************************
 C* standard error handling routine.
 C/COPY OSLCOPYSRC/QRPGSRC,PSSR
 C*****************************************************************

Note that this doesnt look too different. We can see that field names are bigger but it still doesnt convert the OPCODES (operation codes) to the newer format or preferred values. For example, I would prefer to use EVAL for the MOVEL statements.

Follow

About the Author

IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Alpha Nerd 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 in the words of the most interesting man in the world: Stay thirsty my friend.