News
Abstract
Support has been added for optional parameters for external procedures and functions
Content
You are in: IBM i Technology Updates > Db2 for i - Technology Updates > Db2 for i Functional Enhancements > Optional parameter support for External procedures and functions
Varying length parameter lists for external procedures and functions
To determine the number of parameters passed to an ILE service program, external procedures and functions written in ILE RPG can use the %PARMS built-in function and all ILE languages can use the ILE _NPMPARMLISTADDR built-in function.
When a procedure within an ILE service program is written to accept a varying number of input parameters, SQL procedures and functions that call the program set the operational descriptor to indicate the parameter count. This number can be relied on by the ILE service program to determine the parameter count.
In the following example, two SQL functions are defined to use the same entry point name in an RPG service program, each passing a different number of parameters. This same service program could be called from many other ILE programs. The ILE RPG %PARMS built-in function is used to determine how many parameters are passed.
CREATE FUNCTION RFUNC1 (P1 CHAR(5))
RETURNS INT
LANGUAGE RPGLE
PARAMETER STYLE GENERAL
EXTERNAL NAME 'TSTLIB/TSTSRVPGM(RPGPGM1)'
CREATE FUNCTION RFUNC2 (P1 CHAR(5),
P2 CHAR(10))
RETURNS INT
LANGUAGE RPGLE
PARAMETER STYLE GENERAL
EXTERNAL NAME 'TSTLIB/TSTSRVPGM(RPGPGM1)'
- In the RPG code, the number of parameters can be obtained by using the %PARMS built-in function.
Was this topic helpful?
Document Information
Modified date:
13 January 2020
UID
ibm11116573