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

IBM i > DEVELOPER > RPG

The Case of the Missing Parameters


Prototypes is a topic weve covered before. In a previous article, we explained the basics of how and why to prototype the parameters for program calls and introduced you to the joys of the CONST keyword. Here, well outline other keywords that you may find useful and cover a few more areas related to prototypes.

 

The OPTIONS keyword is used on parameter fields in a prototype, much like CONST, and has several potential values. The most commonly used of these is Options(*NoPass). This allows you to specify that a parameter is optional. Lets examine a simple example.

Suppose youve written a procedure that calculates the last day of the month for any date passed to it.

The prototype for this procedure might resemble this:

D LastDayMonth    PR              D   DatFmt(*USA)
D   WorkDate                      D   DatFmt(*USA)

As you can see, it takes a *USA date as the parameter and returns a date in the same format. Now suppose that you need to introduce a new version of the procedure that allows the date to be advanced by a specified number of months before calculating the last day. Of course one option would be to simply create a completely new procedure, but a better option would be to extend the functionality of the existing routine. However, if were to simply add an extra parameter, we would be forced to find every location where the existing routine was used and add the additional parameter.

Options(*NoPass) provides a better way. First, modify the prototype to look like this:

  D LastDayMonth    PR              D   DatFmt(*USA)
  D   InpDate                       D   DatFmt(*USA)
  D   Months                       3P 0 Options(*NoPass)

This allows the procedure to be called with a single parameter, like this:

C                   Eval     Day = LastDayMonth(WorkDate)

Or with two parameters, like this:

C                   Eval     Day = LastDayMonth(WorkDate: MonthsAdv)

Of course to accommodate existing callers of this procedure, we must modify the procedure itself so that it will work as it did originally for callers passing only a single parameter.

 

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.



Advertisement

Advertisement

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