RPG3 versus RPG400 versus RPG4 in all its glorious free format styley
Last night I was asked what the differences between RPG versions were. IBM have gone out of their way to make the version naming and releases differences so quirky, dirty and convuluted that I'm not even sure they know what to call the current incarnation of this beautiful programming language.
Anyhooo, here's a quick splurge and some code examples of RPG3, RPG400 and RPG4 (FreeFormat)
RPG3 looks like this:
H 1* ------------------------------------------------------------- ** | here is some dummy code in rpg3 from the 1980's |* ------------------------------------------------------------- *FEZAP05L1UF E K DISK KINFSR *PSSR A UC* load the screen fieldsC EXSR SUBR01C MOVEL*ON *INLR** this is a subroutineC SUBR01 BEGSRC Z-ADD0 X 30C OPEN EZAP05L1C READ EZAP05L1 N 05C *IN05 DOWEQ*OFFC STAT05 IFEQ *BLANKSC ADD 1 XC X ADD 60 Y 20C MOVEL*ON *IN99C ENDIFC READ EZAP05L1 05C ENDDOC Z-ADDX Z 10
C ENDSR/COPY OSLCOPYSRC/QRPGSRC,PSSR
RPG – Restricted to 6 character field names, indicators make code hard to follow, no inbuilt date or time functions, no built in functions, no code monitor groups (preventing dumps), no sub procedures, no IFS or XML handling and the list goes on.
No longer supported or developed by IBM.
Here it is after upgrading to RPG400 (1990s style) using IBM’s CVTRPGSRC
H DEBUG// ---------------------------------------------------// | here is some dummy code in rpg400 from the 1990's |// ---------------------------------------------------FEZAP05L1 UF A E K DISK INFSR(*PSSR)F USROPN// define program variablesD x S 3 0D y S 3 0D z S 3 0// load the screen fieldsC Exsr SUBR0001C Eval *Inlr = *On// some routine thingC SUBR0001 BegsrC Clear XC Open EZAP05L1C Read(n) EZAP05L1C Dow Not %EOF(EZAP05L1)C If STAT05 = *BLANKS
C Eval X = 1C Eval DA(X) = @DTOXC Eval Y = X + 60C Eval *In(y) = *OnC EndIfC Read EZAP05L1C EndDoC Eval Z = XC Endsr/copy ezgcopysrc,pssr
Language has evolved and now has increased from 6 to 10 character field names and added lots of the main built in functions (dates, times, ifs, xml, subprocs, etc). Note that variables can now be defined in the nice 'D' specifications at the beginning of code which is more logical and easier to find definitions of variables used in code.
Finally, here is the same code in modern RPG4(Freeform) upgraded using Websphere Developer Studio
H debug// -------------------------------------------------------// | here is some dummy code in rpg4 from the 2000 onwards |// -------------------------------------------------------Fezap05l1 uf a e k disk infsr(*pssr)F usropn// define program variablesD x S 3 0D y S 3 0D z S 3 0// load the screen fields/FREEExsr Subroutine01;*inlr = *on;// this is a dummy subroutine doing something pointlessBegsr Subroutine01;Clear x;Open ezap05l1;Read(n) ezap05l1;Dow not %eof(ezap05l1);IF stat05 = *blanks;
x = 1;y = x + 60;*in99 = *on;EndIf;Read ezap05l1;EndDo;z = x;Endsr;/END-FREE/copy ezgcopysrc,pssr
This is the current version as supported by IBM. Code is very very similar to the old RPG400 style but layout is now in a modern left adjusted style.
If you can code in RPG400 you can code in RPG4 with with a minimal learning curve. Fields can be named anything: so if we have a value called ‘Customer Credit Limit’ in RPG3 it might be ‘CUSCLM’ in RPG400 ’CUSTCRDLIM’ in RPG4=’CustomerCreditLimit’ – readability improvement is obvious. Comments are now denoted by ‘//’ as opposed to ‘*(‘ this is to keep the code style in line with Java.
That’s it really.
All of us RPG Programmers write in all 3 versions as they are so similar but the benefits of RPG4 are obvious in speed of development, readability of code and all the new built functions mean the language itself does a lot of the clever stuff behind the scenes where we would have to write copybooks and subprograms in RPG3 to do the same thing in the olden days.
Earlier this year I wrote an article listing the versions of RPG – you might find it interesting just so you can follow the technical RPG version discussions that your team are having: http://www.projex.com/blog/history-ibm-rpg-programming-language








Add new comment