ILERPG.com β€” IBM i Β· ILE RPG Β· AS400 Mastery
2 min readΒ· Admin

Prototypes and Parameters in ILE RPG: Making Every Call Checkable

Within a single module, the compiler derives a prototype from each procedure interface. As soon as a procedure is called from somewhere else β€” another module, another program β€” the caller needs a prototype of its own. That prototype is what lets the compiler check every call.

Prototype and interface

DCL-PR describes how a procedure or program is called: its return type and its parameters. DCL-PI describes the same thing at the point of definition. The compiler checks calls against the prototype and checks the interface against the prototype, so a mismatch is a compile error rather than a production incident.

How parameters are passed

With no keyword, a parameter is passed by reference: the procedure works on the caller's storage, and changes are visible to the caller. CONST passes a read-only reference; the procedure cannot change it, and the caller may pass an expression or a value of a compatible type, which the compiler converts into a temporary. VALUE passes a copy.

dcl-pr adjustQty;
  qtyRef   packed(7:0);          // changes reach the caller
  qtyConst packed(7:0) const;    // read-only; expressions allowed
  qtyValue packed(7:0) value;    // a private copy
end-pr;

The working default is CONST for inputs, plain reference only for genuine outputs, and VALUE where the procedure needs a local, modifiable copy or where an API requires it.

Optional parameters

OPTIONS(*NOPASS) lets callers leave trailing parameters off; the procedure tests %PARMS against %PARMNUM(name) before touching them. OPTIONS(*OMIT) lets callers pass the placeholder *OMIT; the procedure tests %ADDR(parm) = *NULL.

Programs and system procedures

EXTPGM('NAME') prototypes a program call β€” QCMDEXC, for instance. EXTPROC('name') prototypes a procedure by its external name, including C runtime functions. A program's own entry parameters are declared with a DCL-PI: in the main source section of a cycle-main program, or on the MAIN procedure, with EXTPGM, in a linear-main one.

Lesson 25's exercise inspects QCMDEXC on PUB400, designs a set of prototypes, and then compiles and calls procedures that use each way of passing parameters.

Get the lesson

Lesson 25, β€œPrototyping: DCL-PR, DCL-PI, and Passing Parameters,” is part of Beginner ILE RPG in IBM i ILE RPG Mastery and is available at ILERPG.com for USD 10. The complete Beginner ILE RPG series β€” all 18 lessons β€” is USD 180, or USD 135 with coupon code RPG30, which takes 25% off when you purchase the full series.