.st0{fill:#FFFFFF;}

RPG3 RPG400 RPGLE in all its glorious free format styley 

 December 2, 2010

By  NickLitten

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-ADD0 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 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 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;
/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: /history-ibm-rpg-programming-language

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad 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 remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"cff50":{"name":"Main Accent","parent":-1},"a344d":{"name":"Accent Transparent","parent":"cff50"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"cff50":{"val":"var(--tcb-skin-color-0)"},"a344d":{"val":"rgba(46, 138, 229, 0.85)","hsl_parent_dependency":{"h":210,"l":0.54,"s":0.78}}},"gradients":[]},"original":{"colors":{"cff50":{"val":"rgb(0, 178, 255)","hsl":{"h":198,"s":1,"l":0.5}},"a344d":{"val":"rgba(0, 178, 255, 0.85)","hsl_parent_dependency":{"h":198,"s":1,"l":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__

Get In Touch

I’m always looking for awesome input, feedback and critique!

>