RPG Call Operations - PARM (Identify Parameters)

PARM (Identify Parameters)

Description: Defines a parameter in a PLIST for CALL.

Code

Factor 1

Factor 2

Result Field

Indicators

PARM
Target field
Source field
Parameter
 
 

Syntax: Fixed-form: PARM value.

The declarative PARM operation defines the parameters that compose a parameter list (PLIST). PARM operations can appear anywhere in calculations as long as they immediately follow the PLIST, CALL, or CALLB operation they refer to. PARM statements must be in the order expected by the called program or procedure. One PARM statement, or as many as 255 for a CALL or 399 for a CALLB or PLIST are allowed.

The PARM operation can be specified anywhere within calculations, including total calculations. The control level entry (positions 7 and 8) can be blank or can contain an L1 through L9 indicator, an LR indicator, or an L0 entry to group the statement in the appropriate section of the program. Conditioning indicator entries (positions 9 through 11) are not allowed.

Legacy RPG400 Example:

Factor 1 and Factor 2 are optional fields. If used, they must match the type defined in the result field. For variable-length target fields, the length will be set to match the source field’s value. Factor 1 cannot be a literal or named constant, and both Factor 1 and Factor 2 must be left blank if the result field contains the name of a multiple-occurrence data structure or *OMIT.

The result field must contain the name of a variable.
A field name can be specified only once in an *ENTRY PLIST.

For all PARM statements:

  • Field
  • Data structure
  • Array

For non-*ENTRY PLIST PARM statements it can also contain:

  • Array element
  • *OMIT (CALLB only)

The Result-Field entry of a PARM operation cannot contain:

  • *IN, *INxx, *IN(xx)
  • A literal
  • A named constant
  • A table name

Also, the following items are not permitted in the Result-Field entry of a PARM operation within the *ENTRY PLIST:

  • *OMIT
  • A globally initialized data structure
  • A data structure with initialized subfields
  • A data structure with a compile time array as a subfield
  • Fields or data structures defined with the keywords BASED, IMPORT, or EXPORT
  • An array element
  • A data-area name
  • A data-area data structure name
  • A data-structure subfield
  • A compile-time array
  • A program status (PSDS) or file information data structure (INFDS)

If an array is specified in the result field, the space allocated for it is passed to the called program or procedure. For a data structure with multiple occurrences, all occurrences are passed together as one field. But if a subfield of such a data structure is specified in the result field, only the current occurrence of that subfield is passed to the called program or procedure.

Each parameter field has a single storage location, which exists in the calling program or procedure. During a PARM operation, the address of the result field’s storage location is sent to the called program or procedure. If the called program or procedure changes the parameter’s value, it directly updates that storage location. When control returns, the parameter in the calling program or procedure (the result field) reflects the change. Even if the called program or procedure ends with an error after modifying the parameter, the updated value remains. To keep the original information for later use, specify in factor 2 the field containing the data you want to pass. Factor 2 is copied into the result field, and the result field’s storage address is then passed to the called program or procedure.

Since parameter fields are accessed by address rather than by name, the calling and called parameters don’t need to use identical field names for the passed fields. However, the attributes of the corresponding fields in both the calling and called programs or procedures should match; otherwise, unexpected results can occur.

C         PARM Value

Modern RPGLE Example:

Free-Form Syntax(not allowed - use Prototypes and Parameters and CALLP)

Notes: *ENTRY for program entry.

dcl-pr Proc;
  Value char(10);
end-pr;

NOTE: When a CALL or CALLB operation runs, the following occurs:

  • In the calling procedure, the contents of the factor 2 field of a PARM operation are copied into the result field (receiver field) of the same PARM operation.
  • In the case of a CALLB when the result field is *OMIT, a null address will be passed to the called procedure.
  • In the called procedure, after it receives control and after any normal program initialization, the contents of the result field of a PARM operation are copied into the factor 1 field (receiver field) of the same PARM operation.
  • In the called procedure, when control is returned to the calling procedure, the contents of the factor 2 field of a PARM operation are copied into the result field (receiver field) of the same PARM operation. This move does not occur if the called procedure ends abnormally. The result of the move is unpredictable if an error occurs on the move.
  • Upon return to the calling procedure, the contents of the result field of a PARM operation in the calling procedure are copied into the factor 1 field (receiver field) of the same PARM operation. This move does not occur if the called procedure ends abnormally or if an error occurs on the call operation.
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>