Checking for the Number of Passed Parameters

At times it may be necessary to check for the number of parameters that are passed on a call. Depending on how the procedure has been written, this number may allow you to avoid references to parameters that are not passed. For example, suppose that you want to write a procedure which will sometimes be passed three parameters and sometimes four parameters. This might arise when a new parameter is required. You can write the called procedure to process either number depending on the value that is returned by the built-in function %PARMS. New calls may pass the parameter. Old calls can remain unchanged.

%PARMS does not take any parameters. The value returned by %PARMS also includes any parameters for which *OMIT has been passed, and it also includes the additional first parameter that handles the return value for a procedure that has the RTNPARM keyword specified. For a cycle-main procedure, %PARMS returns the same value as contained in the *PARMS field in a PSDS, although to use the *PARMS field, you must also code the PSDS.

If you want to check whether a particular parameter was passed to a procedure, you can use the %PARMNUM built-in function to obtain the number of the parameter. The value returned by %PARMNUM reflects the true parameter number if the RTNPARM keyword was coded for the procedure.

For both *PARMS and %PARMS, if the number of passed parameters is not known, the value -1 is returned. (In order to determine the number of parameters passed, a minimal operational descriptor must be passed. ILE RPG always passes one on a call; however other ILE languages may not.) If the main procedure is not active, *PARMS is unreliable. It is not recommended to reference *PARMS from a subprocedure.



[ Top of Page | Previous Page | Next Page | Contents | Index ]