RPG

Doing Loop the Loops in RPG3 and RPG /Free

Submitted by NickLitten on Thu, 03/15/2012 - 15:31
rpg do loops

So, whenever possible, if I'm editing some old RPG3 or RPG400 code I spend a coffee* cleaning the code up to a more readable form:

  • Use CVTRPGSRC if its old RPG3 stuff
  • Change '1' to *ON
  • Change '0' to *OFF
  • Change Z-ADD to EVAL
  • Insert comments where applicable
  • put some spaces between subroutines and blocks of functionally similar code
  • Then its into WDSC7 and convert to /FREE

Websphere is old technology but I'm not going to spend over $800 on IBM's Ratinal Developer for i version... cmon IBM come up witha sensible price for a source code editor. Obviously, the most sensible is FREE.

DO LOOPS are something that always make me scratch my head when uplifting to RPG4. So just for my reference here is an example of the exact same code in RPG3, RPG400 and RPG4.

RPG3

             DO        SAVRRN        X

X           IFGT      10

             some clever code here

             END

             END

RPG400

             DO        SAVRRN        X

X           IFGT      10

             some clever code here

             ENDIF

             ENDDO

RPG4

   for x = 1 to SAVRRN by 1;

      if x > 10;

         some clever code here  

      endif;

   endfor;      

/me loves some RPG Free format  :)

You can do it the clumsy way, or you can do it the easy, straightforward way.

Submitted by NickLitten on Wed, 02/08/2012 - 11:44
RPG is going back to the future

I stumbled across this article with some really neat RPG tricks... I'm using one at moment so am cut/pasting it here for quick reference for myself. I've met the author (Mr Bob Cozzi) at the RPGWORLD conference back in 2009. Very smart cookie. I can tell you:

 

How Do I Left-Justify Text Within a Character Field?

Clumsy Solution 1:

D Start           S              5U 0
D End             S              5U 0
D Len             S              5U 0
D MyValue         S            300A   Inz('    01234567')

C     ' '           Check     myValue       Start
C     ' '           CheckR    myValue       End
C                   eval      Len = (End - Start) + 1
C                   eval      myValue = %subst(myValue:Start:Len)

 

This solution uses a typical application of the %SUBST built-in function to extract just the data within the original MYVALUE field and move it, left-justified, into itself via the EVAL opcode.

Clumsy Solution 2:

D Start           S              5U 0
D MyValue         S            300A   Inz('    01234567')

C     ' '           Check     myValue       Start 
C                   eval      myValue = %subst(myValue:Start)

 

Exit Programs, Audit Trails and APIs

Submitted by NickLitten on Thu, 07/21/2011 - 10:58

Question: All the Exit Program examples I see are in the C Language. Is it possible to write Exit Programs in RPG?

Answer: Yes, but you must write a data structure as same as it in the C header file. The C header file is H/QSYSINC. This include is also available for other languages in QSYSINC/QRPGSRC, QSYSINC/QRPGLESRC, QSYSINC/QLBLSRC, and QSYSINC/QCBLLESRC.

Question: I have been asked to find out how AS/400 users can change their passwords using a web browser application.  We will synch user info to the NT Domain server to enable validation and signon.  The AS/400 passwords expire every 30 days.  The users must be able to maintain their passwords without leaving the web application (a combination of Cold Fusion, Javascript and HTML).  Off the shelf packages are OK, or IBM supplied API that support some sort of encryption (we don't want passwords xmitted over the internet in the clear.)  Any and all suggestions are appreciated. (12/99)

Answer 1:  If Java is an option then you can use the Java ToolKit for AS/400.  The code used to exchange and/or change passwords is encrypted out the wazoo before it is sent over the net. Unless you are going to use some sort of strong encryption for sending the password from the browser (implemented in an applet) to the http server I would suggest supporting SSL on the www server.

as400 users become iseries users become IBMi users

Submitted by NickLitten on Thu, 07/21/2011 - 10:33
rpg code example seu pdm

User profiles are such a wonderful and flexible part of the IBMi operating system. Group profiles, Security levels, authorization lists.... good stuff:

Managing User Profiles

Question I am having a problem with user profiles disabling randomly.

Answer 1. It sounds like someone has used the Security Toolkit to activate the "automatically disable inactive profiles" option. That's not really it's name. It's name is "Analyze Profile Activity" on the menu option, which sounds benign enough, but in fact it will initiate this scheduled auto-disable.

From the Security Toolkit (GO SECTOOLS) choose option 4 (ANZPRFACT) and set the number of days to *NOMAX. This will prevent any profile from being automatically disabled by this new feature.

Alternately, you could leave the auto-disable at 90 days, and then use options 2 & 3 on that same menu to exclude certain profiles from being disabled.

Answer 2. When you use ANZPRFACT command for the first time it creates an entry in the job scheduler to run weekly. Just delete the job from the job scheduler. I don't know what problems you are having with the command. But I had a problem with the command under V3R2 for new profiles. If the user profiles weren't use they would get disabled. I called IBM support line and I installed a PTF that would look at the last used date and the creation date of the object.

Zend Framework for RPG programmers

Submitted by NickLitten on Wed, 06/08/2011 - 12:13

The Zend Framework is a neat thing for letting my RPG programmers brain run a little wild. Yes it's object Oriented and not (necessarily) that easy to adapt to the linear model that us old schoolers may be used to. But does that mean we can’t adopt it?robbie was an rpg programmer

"Hell No!"

- "Adapt and Survive" is the motto of all us lucky people who have grown up through the AS400 years.

RPG Code Hints and Tips – using slash Title Mainline

Submitted by NickLitten on Wed, 04/20/2011 - 09:16

I'm in the middle of refactoring a load of old Projex400 RPG code from RPG3 upto RPG4 and using all the modern BIF's. It's a fun thing to do in the evening while I'm hiding in an hotel room in rainy Ohio. But I digress...    Inevitably my first compile will fail and I normally want to jump to the 'C' specs to have a look at what I've got wrong... this normally involves repeatedly pressin the page-down key until my finger tip gets numb.

rpg programming help

But wait, I stumbled across a neat little code snipper that saves time and looks good in the code as well.

Use the /title command in the source code to add a comment to your spool file listing.

This was used a lot in the old days of programming along with the /page and /eject codes. I have started using the ‘/title mainline’ as the first line of ‘c’ specs in RPG4/Column-Based, or just before the /FREE in RPG4/FreeFormat.

Why?

RPG3 versus RPG400 versus RPG4 in all its glorious free format styley

Submitted by NickLitten on Thu, 12/02/2010 - 10:59

i love programming in RPGLast 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:

 

Web Services in native RPG straight from IBMi

Submitted by NickLitten on Thu, 11/11/2010 - 09:21

 

I've long been a follower of Mr Aaron Bartell - a nice guy and one of the most dynamic IBMi developers I have come across for a while.

His company, Krengel Tech, have some neat functions that simplify getting good old AS400 data (yes, I know its an iSeries or IBMi but sometimes I just like to type the old names :) )  out there to the Internet Super Web Highway Thingie...

In simplistic terms, RPG-XML Suite essentially is an RPG service program that allows RPG programmers the ability to compose, transmit, and parse XML along with many other supporting subprocedures. These three capabilities fully equip an RPG programmer to offer (or provide) web services on the iSeries as well as call (or consume) web services on remote machines.

Calling Web Services with RPG-XML Suite

The illustration below demonstrates how an RPG program on your iSeries can "call" a web service that resides on another machine. The RPG program composes and passes an XML stream from the remote web service on the Server/Client and receives back the response XML which it parses for its data contents. For example, the RPG program could send an XML invoice to a business partner to automate the billing process, or a purchase order could be sent to a supplier to automate the shipping of widgets to your company.

squish out blanks in a string using RPG

Submitted by NickLitten on Fri, 10/29/2010 - 16:10
dont squish me

So, as part of an IBMi project which is rebuilding a bunch of source libraries on the development machine, I always think backup before touching. Obviously an offline backup is first and foremost and then I thought "Wouldnt it be nice if I could copy all this source code to the IFS for easy referencing with NOTEPAD?"

The answer was YES... in true Projex style this turned into a command and CPYSRC2IFS was born.

History of the IBM RPG programming language

Submitted by NickLitten on Thu, 07/22/2010 - 12:54
from the r to the p to the g

when lady operators were ever so proper and more than a little but saucy

So, as an RPG* Developer I am definitely biased towards IBM's best and most versatile language. IBM RPG has evolved massively from the early Report Program Generator that it was designed to be. The latest Incarnation of RPG is a leading edge web -savvy object oriented SOA language.

Here is my personal version of how RPG has evolved:

  • 1960's(this is a decade of code evoloution): RPG was introduced but called something else. Dunno, much about this as I was only 3 years old and was busy learning to walk. Programmers started the decade wearing sharp 1950's style suits and ended it wearing tie-dyes and Greenpeace badges.
     
  • 1970's: RPG II was introduced with the System/3 series of computers. It was later used on System/32, System/34, and System/38 and then the System 36 (!), with an improved version of the language. RPG2 was a beautiful language using a logic cycle, arrays and data structures and internal file layouts. Complex, hard to master and quirky... but strangely addictive.

this weeks neat little RPG snippet

Submitted by NickLitten on Mon, 07/19/2010 - 10:35

I was recently copied on an interoffice email from a fellow RPG chappie (he's quite sharp actually despite his funny mockney accent).

Aforementioned Mockney-Coder was modifying a recent program, written by a legacy RPG3 programmer (these creatures are very rare to find in the wild and we have placed them on the endangered species list).

Amazingly, there are still a handful of RPG Programmers out there who still write in RPG3. RPG3 was upgraded to RPG400 in 1993(?) so if they havent upgraded to RPG400 yet then the chances of getting up to RPGLE and then to RPG/FREE are slim to none.

But Mockney-Coder is a diligent chap and he mentioned a neat little alternative piece of RPG/FREE code that could be used to replace the large subroutines and array handling code chunks needed to perform the same thing in the old fashioned and clunky column based RPG varieties. After all, Variety is the spice of life...

all names have been removed to protect the innocent ;)

Don’t know if you are using /Free or not because I have been hiding a lot lately.

Replacing a variable string within a field using SQL REPLACE on the IBMi

Submitted by NickLitten on Wed, 01/20/2010 - 23:04
using RPG %REPLACE or SQL Alternative

If you are one of the lucky programmers fortunate enough to program in RPG you will know of the ever increasing IBM supplied %BIF's that have made our life easier over the last few years. %REPLACE is groovy that lets us manipulate data content in any string: %replace(from-string:to-string{:starting-position{:length}})

The RPG4 %REPLACE Built In Function is very powerful but also quite complicated:

IBMi + WDSC7.0 + TN5250 = Wow Squared!

Submitted by NickLitten on Tue, 12/15/2009 - 11:20

WebSphere Development Tools for the IBMi is Very Very Very Cool!

I've just installed WDSC7.0 for the first time (/me ducks from the barrage of rotten fruit launched at him from the rowdy-RDi-crowd) and have almost had a religious experience with it.

For years I've been feverishly hammering away in S.E.U. and P.D.M. mistakenly thinking that I just haven't got the time to learn a new G.U.I for writing RPG and CL programs on the IBMi.

Look at that - I used WDSC, RDi, SEU, PDM, GUI and IBMi all in the same paragraph ;) but at least I never used the word leverage or any other business junk phrases like lets run that idea up the flagpole and see who salutes

Possibly I'm the only IBMi Developer who wasnt already using a modern source code editor, in which case you're laughing at me, but just in case you (dear reader) are still in the world of SEU then just stop right now and get a copy of WDSC7 from your IBM business partner. It's FREE as its been replaced by the new, very expensive, re branded Rational Developer.

Pay I.T. forward

Submitted by NickLitten on Wed, 12/02/2009 - 06:26
what does this button do?

Wow! It's December already!

After a whirlwind year involving moving the whole family, two dogs and a pile of News 3x/400 magazines to this side of the pond I cant believe it's nearly 2010 already. Two thousand nine has seen us settling into our new life in the US, focussing mainly on IBMi and I feel that I've reached a kind of career milestone. After a couple of years focusing on other areas, in the IT wilderness, this year has seen my return to the IBM Midrange club and in the immortal words of Gary Glitter “I’m glad to be back

The last twelve months have seen huge changes in my personal outlook on information technology and my role within it. I've learned more about programming techniques than I thought possible and its seriously changed how I approach my role as an IBMi Developer.

I've attended a couple of fantastic conferences (Rpg World and iSeries Devcon) that have re-ignited my passion and combined with meeting a bunch of terrific IT Peeps* has helped me to evolve and shrug off my Legacy AS400 RPG Analyst Programmer skin and emerge blinking as a Modern IBMi Developer.

ILE RPG certified programmers are extinct

Submitted by NickLitten on Mon, 11/30/2009 - 13:15

Well... they will be at the end of 2009!

For some very strange reason, IBM have decided to kill the ILE RPG Programmer certification. As we all know, being an RPG Programmer is a rare skill set nowadays... and it's becoming rarer. I kind of feel guilty for never standing up and doing the certification. But then again, as I'm typing that I'm also thinking that I actually dont want a little plaque in my dilbertesque cubicle announcing to the world that I know how to do my job: I have a job therefore I know how to do it.

Would the aforementioned little plaque make me feel loftier than my sans-plaque peers? Maybe, just maybe  ;)

 

Setting RPG Slash Free - Step 4 of 4

Submitted by NickLitten on Sun, 09/13/2009 - 19:13

Convert it to FREE FORMAT

Of course, I use the Projex400 command to do this step. This is what the SETSRCFREE command gives us:

   h datfmt(*iso) timfmt(*iso) option(*nodebugio) debug
*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
* *
* system name: fix slp06 *
* *
* program desc: fix the records on slp06 *
* *
* program no: ef001 *
* *
* date: 09/09/09 (sadly not at 9:09) *
* *
* author: nick...@projex.com *
* *
*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
Fefp01l01 if e k disk infsr(*pssr)
Facsummar uf e k disk infsr(*pssr)
*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
* Externally defined file defn's for *LDA and *PSDS
D lda e ds extname(lda) dtaara(*LDA)
D pstat esds extname(psds)
*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
/FREE
in lda;
setll l#cono acsummar;
reade l#cono acsummar;
dow not %eof(acsummar);
// get customer order total from work file (efp01) which
// is generated by accumulating OEP65 invoices
chain cusn06 efp01l01;
if %found(efp01l01);
bodv06 = amount;
else;
bodv06 = 0;
endif;
update slr06; // Update Account Balances new Order Total
reade l#cono acsummar;
enddo;
// --- Program Termination ---
out lda;
*inlr = *on;
/END-FREE
*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
* standard error handling routine. *
*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
/Copy qgpl/qrpglesrc,pssr

Thats the same program in RPG Free Format.

Paroling RPG4 - Step 3 of 4

Submitted by NickLitten on Sat, 09/12/2009 - 20:12

Upgrade RPG4 to use free-friendly code standards

If we were using Rational Developer/i software we could do this automatically. But as a manual process its simple, if a little tedious. Basically when we are going to skim through the code and replace all indicators with the modern and preferred %FOUND BIF technique:
 
     H debug
      *****************************************************************
      *                                                               *
      *  system name:     fix slp06                                   *
      *                                                               *
      *  program desc:    fix the records on slp06                    *
      *                                                               *
      *  program no:      ef001                                       *
      *                                                               *
      *  date:            09/09/09 (sadly not at 9:09)                *
      *                                                               *
      *  author:          Nick.Litten@projex.com                      *
      *                                                               *
      *****************************************************************
     Fefp01l01  if   e           k disk    infsr(*pssr)
     Facsummar  uf   e           k disk    infsr(*pssr)
     D lda           e ds                  extname(lda)
     D pstat         esds                  extname(psds)
     C     *dtaara       define    *lda          lda
     C                   in        lda
     C     l#cono        setll     acsummar
     C     l#cono        reade     acsummar
 1b  C                   dow       not %eof(acsummar)
     C     cusn06        chain     efp01l01
 2b  C                   if        %found(efp01l01)
     C                   eval      bodv06 = amount
 2x  C                   else
     C                   eval      bodv06 = 0
 2e  C                   endif
     C                   update    slr06
     C     l#cono        reade     acsummar
 1e  C                   enddo
     C                   eval      *inlr = *on
     C                   out       lda
     ?*****************************************************************
     ?*  standard error handling routine.
     ?/Copy qgpl/qrpglesrc,pssr

RPG Three becomes Four - Step 2 of 4

Submitted by NickLitten on Fri, 09/11/2009 - 18:52

CVTRPGSRC - IBM Command to upgrade RPG3 to RPG4

After running CVTRPGSRC on the old source a new member is created in QRPGLESRC:

      * program to fix SLP06 records
     H DEBUG
     FEFP01L01  IF   E           K DISK    INFSR(*PSSR)
     FACSUMMAR  UF   E           K DISK    INFSR(*PSSR)
     D LDA           E DS                  EXTNAME(LDA)
     D PSTAT         ESDS                  EXTNAME(PSDS)
     C     *DTAARA       DEFINE    *LDA          LDA
     C                   IN        LDA
     C     K01           KLIST
     C                   KFLD                    CUSN06
     C     L#CONO        SETLL     ACSUMMAR
     C     L#CONO        READE     ACSUMMAR                               06
 1b  C                   DOW       *IN06        = *OFF
     C     K01           CHAIN     EFP01L01                           02
 2b  C                   IF        *IN02        = *OFF
     C                   EVAL      BODV06 = AMOUNT
 2x  C                   ELSE
     C                   EVAL      BODV06 = 0
 2e  C                   ENDIF
     C                   UPDATE    SLR06
     C     L#CONO        READE     ACSUMMAR                               06
 1e  C                   ENDDO
     C                   EVAL      *INLR = *ON
     C                   OUT       LDA
     ?*****************************************************************
     ?*  standard error handling routine.
     ?/Copy qgpl/qrpglesrc,pssr

 

As you can see the code if more or less the same, with the exception of few elements to make it more readable.

Pages

Subscribe to RSS - RPG

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