RPG Evolution and Refactoring - Step 1 of 4

Submitted by NickLitten on Fri, 09/11/2009 - 12:59

I've recently been writing all my new programs in RPG Free format. Attending RPGWORLD earlier this year, gave me the impetus to finally commit myself to the new and improved style of RPG coding.

I'm currently  in contract at a shop that still has twenty year old programs running in production, the developers still write in RPG3 and shun any development techniques that have been introduced this century. "I havent got time to learn all that newfangled business" is the war cry. "Thats why your code is unreadable, the system runs like a dog, change management is out of control and there are so many bugs" is my silently worded response.

rpg fourAs an RPG programmer I am amazed that other programmers are simply not interested in learning the benefits of the latest generations of RPG. There are lots of flavours and any programmer worth his salt should be proficient in all of them:  RPG2, RPG3, RPG400, RPGILE, RPG4, RPG/Freeformat

I wish IBM had simply named it RPG1-2-3-4-5 but in true befuddling IBM style the Report Program Generators language naming structure is nearly as poor as the naming standards for the System i itself.

Anyway, I digress, my task yesterday was to write a bunch of little utility programs adding up various elements of the JBA Accounts Receivable database to compare values with what was stored in the accounts hierarchy.

For example, "Does the total value of orders actually match all the orders added together?" and "How many invoices and how $much are outstanding this year by month" relatively simple to write and the first program was already written.

This first program was, quite amazingly,  written in 2008! Some programmers are frozen in the land of the 1980's and refuses to move up from RPG3. The old style code works, dont get me wrong, but can be easily upgraded to a twenty year newer version which is vastly more readable, efficient and easy to maintain - in a few simple steps.

So here's the code:

 

     H        1
       * program to fix SLP06 records
     FEFP01L01IF  E           K        DISK         KINFSR *PSSR
     FACSUMMARUF  E           K        DISK         KINFSR *PSSR
     ILDA       E DSLDA
     IPSTAT     ESDSPSDS
     C           *NAMVAR   DEFN *LDA      LDA
     C                     IN   LDA
     C           K01       KLIST
     C                     KFLD           CUSN06
     C           L#CONO    SETLLACSUMMAR
     C           L#CONO    READEACSUMMAR                 06
     C           *IN06     DOWEQ*OFF
     C           K01       CHAINEFP01L01             02
     C           *IN02     IFEQ *OFF
     C                     Z-ADDAMOUNT    BODV06
     C                     ELSE
     C                     Z-ADD0         BODV06
     C                     END
     C                     UPDATSLR06
     C           L#CONO    READEACSUMMAR                 06
 E01?C                     END
     C                     SETON                         LR
     C                     OUT  LDA
      *****************************************************************
      /COPY OSLCOPYSRC/QRPGSRC,PSSR

 

Notice there are no comments, not even an author name.

I decided to take this program and upgrade it to RPG/FREE so I can show him the thought process betweens versions and hopefully entice him to write newer code: RPG Free Format is neater, easier to read and more efficient.

So, I've broken it into 3 very simple steps

Lets take the code and upgrade it to RPG/4 - Step 1


Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Some Bloke

Projex dot com is the cyber home of Nick Litten an AS400 IBMi developer, RPG programmer, SOA code enthusiast, website tinkerer, information technology evangelist, early adopter, proponent of open source and hopeless technology addict...

Nick Litten looking dazed while refactoring some RPG2 code to kick it into this century

Born and raised in Rainy England, now enjoying programming in the sunshine of Southern USA. Founder of SOFTWARE PROJEX.

Clustermap

Locations of visitors to this page

glqxz9283 sfy39587stf02 mnesdcuix8
sfy39587stf03
sfy39587stf04