RPG3 RPG400 RPGLE in all its glorious free format styley

  • Home
  • /
  • Blog
  • /
  • RPG3 RPG400 RPGLE in all its glorious free format styley

December 2, 2010

RPG3 RPG400 RPGLE in all its glorious free format styley

By NickLitten

December 2, 2010

ILE, modernization, modernize, programming, RPG, RPG3, RPGLE, snippet

Last night I was asked what the differences between RPG versions were: RPG3 RPG400 RPGLE: IBM have gone out of their way to make the version naming and releases differences so quirky, dirty and convoluted 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 RPGLE (ILE, RPG4, FreeFormat)

RPG3 looks like this:

rpg3 rpg400 rpgleH 1
 * ------------------------------------------------------------- * 
 * | here is some dummy code in rpg3 from the 1980's |
 * ------------------------------------------------------------- *
FEZAP05L1UF E K DISK KINFSR *PSSR A UC

* load the screen fields
C                   EXSR                              SUBR01
C                   MOVEL *ON                 *INLR
 *
 * this is a subroutine
C SUBR01   BEGSR
C                  Z-ADD   0                        X              30
C                  OPEN     EZAP05L1
C                  READ    EZAP05L1                               N 05
C *IN05       DOWEQ*OFF
C STAT05    IFEQ      *BLANKS
C                  ADD       1                       X
C X              ADD       60                     Y               20
C                  MOVEL *ON                 *IN99
C                  ENDIF
C                  READ    EZAP05L1                               05
C                  ENDDO
C                   Z-ADD  X                        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 variables
D x             S                                3 0
D y             S                                3 0
D z             S                                3 0

// load the screen fields

C                     Exsr      SUBR0001
C                     Eval      *Inlr = *On

// some routine thing
C SUBR0001  Begsr
C                     Clear     X
C                     Open     EZAP05L1
C                     Read(n) EZAP05L1
C                     Dow      Not %EOF(EZAP05L1)
C                     If           STAT05 = *BLANKS
C                     Eval       X = 1
C                     Eval       DA(X) = @DTOX
C                     Eval       Y = X + 60
C                     Eval       *In(y) = *On
C                     EndIf
C                     Read       EZAP05L1
C                     EndDo
C                     Eval        Z = X
C                     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 variables
D x S 3 0
D y S 3 0
D z S 3 0

// load the screen fields
/FREE
  Exsr Subroutine01;
  *inlr = *on;

// this is a dummy subroutine doing something pointless
Begsr 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;
/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: /history-ibm-rpg-programming-language

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips

>