Using the PARM operation
The PARM operation is used to identify the parameters which are passed from or received by a procedure. Each parameter is defined in a separate PARM operation. You specify the name of the parameter in the Result field; the name need not be the same as in the calling/called procedure.
The Factor 1 and factor 2 entries are optional and indicate variables or literals whose value is transferred to or received from the Result Field entry depending on whether these entries are in the calling program/procedure or the called program/procedure. Table 1 shows how factor 1 and factor 2 are used.
| Status | Factor 1 | Factor 2 |
|---|---|---|
| In calling |
Value transferred from Result Field entry upon return. | Value placed in Result Field entry when call occurs. |
| In called |
Value transferred from Result Field entry when call occurs. | Value placed in Result Field entry upon return. |
Note: The moves to either the factor 1 entry or the result-field entry
occur only when the called procedure returns normally to its caller.
If an error occurs while attempting to move data to either entry,
then the move is not completed.
If insufficient parameters are specified when calling a procedure,
an error occurs when an unresolved parameter is used by the called
procedure. To avoid the error, you can either:
- Check %PARMS to determine the number of parameters passed. For an example using %PARMS, see Checking for the Number of Passed Parameters.
- Specify *OMIT in the result field of the PARM operations of the unpassed parameters. The called procedure can then check to see if the parameter has been omitted by checking to see if the parameter has value of *NULL, using %ADDR(parameter) = *NULL. For more information, refer to Omitting Parameters.
Keep in mind the following when specifying a PARM operation:
- One or more PARM operations must immediately follow a PLIST operation.
- One or more PARM operations can immediately follow a CALL or CALLB operation.
- When a multiple occurrence data structure is specified in the Result field of a PARM operation, all occurrences of the data structure are passed as a single field.
- Factor 1 and the Result field of a PARM operation cannot contain a literal, a look-ahead field, a named constant, or a user-date reserved word.
- The following rules apply to *OMIT for non-prototyped parameters:
- *OMIT is only allowed in PARM operations that immediately follows a CALLB operation or in a PLIST used with a CALLB.
- Factor 1 and Factor 2 of a PARM operation must be blank, if *OMIT is specified.
- *OMIT is not allowed in a PARM operation that is part of a *ENTRY PLIST.
- There are other restrictions that apply when using the PARM operation code. For a detailed description of these restrictions, see the IBM® Rational® Development Studio for i: ILE RPG Reference.