January 7

0 comments

Upgrade RPG CALL statement to RPGLE Procedure call

By NickLitten

January 7, 2016

#call, #ILE, #modernization, #parms, #procedure, #RPG, #snippet

Back in the olden days – RPG was this column based thing that looked magical and quite unlike any other programming language. But, it’s a new age and RPG has evolved, added a sprinkle of ILE pixie dust and now lets us code fully backwards compatible programm calls in a much neater format free’d from old column constraints.

It’s easy to refactor old CALL STATEMENTS and make them in to modern PROCEDURES. It looks nicer. It’s easier to read.

Lets see how to do it:

Old style program calls might look like this:

C           Call  'SY7020R01' 
C           Parm               ServiceOrder 
C           Parm               ScheduleCode 
C           Parm               s@Units 
C           Parm               s@AppDate 
C           Parm               s@DropDays 
C           Parm               s@ResultDate

So to make this into a PROCEDURE style call we would define the procedure like this:

dcl-pr addWorkDaystoDate extpgm('SY7020R01'); 
  *n char(9) const; // ServiceOrder 
  *n char(5) const; // ScheduleCode 
  *n zoned(5); // s@Units 
  *n packed(8); // s@AppDate 
  *n zoned(2); // s@DropDays 
  *n zoned(8); // s@ResultDate 
end-pr;

Note that I defined the size of each parameter and added a //comment to tell anyone what that parameter is.

Also note that I defined CONST against the first two parameters because in this case, those two are static (non-changing) values and its the S@* values that are being returned from the program that I’m calling.

I looked at the program being called pgm(SY7020R01) and found that it was a program for adding days to a business day for work orders. So, I decided to call my procedure ‘addWorkDaystoDate

Now to use this in my code I can replace that original RPG400 block of code with this RPGLE block of code:

addWorkDaystoDate( ServiceOrder : 
                   ScheduleCode : 
                   s@Units : 
                   s@AppDate : 
                   s@DropDays : 
                   s@ResultDate );

Boom!

Modernizing old RPG code is fun.

Most recently I’ve been formatting my procedure calls like this:

addWorkDaystoDate( ServiceOrder  
                 : ScheduleCode  
                 : s@Units  
                 : s@AppDate  
                 : s@DropDays  
                 : s@ResultDate
                 );

I know code style is a personal thing but I like this layout because it draws my eye to each parameter and also let me easily copy/paste or re-order parms while in the IDE Editor.

🙂

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

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

>

Snug CBD

 20% Discount

I have partnered with SNUG CBD givING you Organic CBD
20% discount code "NL20"