%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:
  1. A parameter defined using a *ENTRY PLIST cannot be specified as the operand for %PARMNUM.
  2. 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.
  3. 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.
  1. The CEEDOD API is used to find the length of the companyName parameter, which is defined with OPTIONS(*VARSIZE).
  2. If the parameter length is less than 25, the passed parameter is shorter than the defined length of the parameter.
  3. The CEETSTA API is used to determine whether *OMIT was passed for the errorCode parameter, which is defined with OPTIONS(*OMIT).
  4. The API sets variable isPresent to *ON if *OMIT was not passed for the parameter, so the errorCode parameter can be used.
  5. Built-in function %PASSED can also be used to determine whether the procedure can use the errorCode, which is defined with OPTIONS(*NOPASS).
  6. If the number of parameters passed (%PARMS() is greater than or equal to the parameter number of the cityName parameter, the parameter was passed.
  7. Built-in function %PASSED can also be used to determine whether the cityName parameter 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;