As previously discussed, a parameter has one of three possible modes - IN, OUT, or IN OUT. The following characteristics of a formal parameter are dependent upon 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 based on their mode.

Mode property IN IN OUT OUT
Formal parameter initialized to: Actual parameter value Actual parameter value Actual parameter value
Formal parameter modifiable by the called program? No Yes Yes
Actual parameter contains: (after normal called program termination) Original actual parameter value prior to the call Last value of the formal parameter Last value of the formal parameter
Actual parameter contains: (after a handled exception in the called program) Original actual parameter value prior to the call Last value of the formal parameter Last value of the formal parameter
Actual parameter contains: (after an unhandled exception in the called program) Original actual parameter value prior to the call Original actual parameter value prior to the call Original 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 is called unless it was explicitly initialized with a default value. The IN parameter may be referenced within the called program. However, the called program may not assign a new value to the IN parameter. After control returns to the calling program, the actual parameter always contains the same value as it was set to prior to the call.

The OUT formal parameter is initialized to the actual parameter with which it is called. The called program may reference and assign new values to the formal parameter. If the called program terminates 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 is called. Like an OUT parameter, an IN OUT formal parameter is modifiable by the called program and the last value in the formal parameter is passed to the actual parameter of the calling program if the called program terminates 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.