You are currently on IBM Systems Media’s archival website. Click here to view our new website.


RPG IV Prototypes: What are they and why should you care?

If you've ever debugged a problem caused by a parameter mismatch between the calling and called programs, you know that one with RPG III errors in parameter lists aren't discovered until run-time. Wouldn't it be nice if the compiler could validate parameter lists and prevent such errors from occurring? That's one of the many things that prototypes can do for you.

Prototypes were added to RPG IV in OS/400 V3R2/V3R6. Although their initial purpose was to support prototyping of subprocedures, the compiler writers realized that prototypes could also provide this support between called programs.

A prototype is a way of describing the interface (i.e., the number and type of parameters) to a program or bound procedure. It's similar to a PLIST or the list of PARMs following a CALL or CALLB operation code. However, prototypes can have functions beyond the options available with ordinary PARMs and PLISTs.

The following code excerpt shows how prototypes help prevent parameter mismatches:

D Gross                           9S 2
D Allow                           9S 2
D Net                             9S 2
:    :    :    :    :     :    :
C                    Call       'PX027C'
C                    Parm                   Gross
C                    Parm                   Allow
C                    Parm                   Net

The problem arises if program PX027C expects the second parameter to be seven digits long instead of nine digits. Prototypes could help find this type of error more quickly and easily. The prototype for program PX027C might resemble this:

D TaxCalc          PR                   ExtPgm('PX027C')
D  GrossPay                       9S 2
D  Allowances                     7S 2
D  NetPay                         9S 2

And the call to it would look like this:

C                    CallP      TaxCalc( Gross : Allow : Net)


Jon Paris is a technical editor with IBM Systems Magazine and co-owner of Partner400.

Susan Gantner is a technical editor with IBM Systems Magazine and co-owner of Partner400.



2019 Solutions Edition

A Comprehensive Online Buyer's Guide to Solutions, Services and Education.

New and Improved XML-INTO

Namespace support makes the opcode a viable option

Authenticating on the Web

The finer points of OpenRPGUI, Part 1

The Microphone is Open

Add your voice: Should IBM i include open-source RPG tools?

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link iPad App Google Play Store
IBMi News Sign Up Today! Past News Letters