Parameter modes v14

A parameter has one of three possible modes: IN, OUT, or IN OUT. The following characteristics of a formal parameter depend on its mode:

  • Its initial value when the procedure or function is called
  • Whether the called procedure or function can modify the formal parameter
  • How the actual parameter value is passed from the calling program to the called program
  • What happens to the formal parameter value when an unhandled exception occurs in the called program

The following table summarizes the behavior of parameters according to their mode.

Mode propertyININ OUTOUT
Formal parameter initialized to:Actual parameter valueActual parameter valueActual parameter value
Formal parameter modifiable by the called program?NoYesYes
Actual parameter contains: (after normal called program termination)Original actual parameter value prior to the callLast value of the formal parameterLast value of the formal parameter
Actual parameter contains: (after a handled exception in the called program)Original actual parameter value prior to the callLast value of the formal parameterLast value of the formal parameter
Actual parameter contains: (after an unhandled exception in the called program)Original actual parameter value prior to the callOriginal actual parameter value prior to the callOriginal actual parameter value prior to the call

As shown by the table, an IN formal parameter is initialized to the actual parameter with which it's called unless it was explicitly initialized with a default value. You can reference the IN parameter in the called program. However, the called program can't assign a new value to the IN parameter. After control returns to the calling program, the actual parameter always contains the same value that it had prior to the call.

The OUT formal parameter is initialized to the actual parameter with which it's called. The called program can reference and assign new values to the formal parameter. If the called program ends without an exception, the actual parameter takes on the value last set in the formal parameter. If a handled exception occurs, the value of the actual parameter takes on the last value assigned to the formal parameter. If an unhandled exception occurs, the value of the actual parameter remains as it was prior to the call.

Like an IN parameter, an IN OUT formal parameter is initialized to the actual parameter with which it's called. Like an OUT parameter, an IN OUT formal parameter can be modifiwed by the called program. The last value in the formal parameter is passed to the calling program’s actual parameter if the called program ends without an exception. If a handled exception occurs, the value of the actual parameter takes on the last value assigned to the formal parameter. If an unhandled exception occurs, the value of the actual parameter remains as it was prior to the call.