%PARMNUM (Return Parameter Number)
%PARMNUM (Return Parameter Number)
%PARMNUM (Return Parameter Number)
%PARMNUM returns the number of the parameter in the parameter list. The operand for %PARMNUM is the name of a parameter defined as part of a procedure interface.
Note:
- A parameter defined using a *ENTRY PLIST cannot be specified as the operand for %PARMNUM.
- The parameter must be specified the same way it appears in the procedure interface parameter list. If the parameter is an array, an index cannot be specified. If the parameter is a data structure, a subfield cannot be specified. If the parameter is a file, a record format cannot be specified.
- If the RTNPARM keyword is coded for a procedure, the return value is handled as an additional first parameter. The other parameters have a number one higher than the apparent number. For example, if a procedure defined with RTNPARM has two parameters P1 and P2, %PARMNUM(P1) will return 2 and %PARMNUM(P2) will return 3.
For more information, see Built-in Functions.
Figure 1. Example of %PARMNUM
In the following example, %PARMNUM is used with APIs or other built-in functions that work with the true parameter number.
- The CEEDOD API is used to find the length of the
companyNameparameter, which is defined with OPTIONS(*VARSIZE). - If the parameter length is less than 25, the passed parameter is shorter than the defined length of the parameter.
- The CEETSTA API is used to determine whether *OMIT
was passed for the
errorCodeparameter, which is defined with OPTIONS(*OMIT). - The API sets variable
isPresentto *ON if *OMIT was not passed for the parameter, so theerrorCodeparameter can be used. - Built-in function %PASSED
can also be used to determine whether the procedure can use the
errorCode, which is defined with OPTIONS(*NOPASS). - If the number of parameters passed (%PARMS() is greater than
or equal to the parameter number of the
cityNameparameter, the parameter was passed. - Built-in function %PASSED
can also be used to determine whether the
cityNameparameter can be used.
D myProc pi 10A RTNPARM OPDESC
D companyName 25A OPTIONS(*VARSIZE)
D errorCode 1A OPTIONS(*OMIT)
D cityName 25A OPTIONS(*NOPASS)
CEEDOD(%PARMNUM(companyName) : more parameters ... // 1
: parmlen : *omit);
if parmlen < %SIZE(companyName); // 2
...
endif;
CEETSTA(isPresent : %PARMNUM(errorCode) : *omit); // 3
if isPresent = 1; // 4
...
endif;
if %PASSED(errorCode); // 5
...
endif;
if %PARMS >= %PARMNUM(cityName); // 6
...
endif;
if %PASSED(cityName); // 7
...
endif;