This topic describes the modes of a parameter. A parameter supports three modes: IN, OUT, and IN OUT.

The following characteristics of a formal parameter depend on its mode:

  • The 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 behavior of parameters are summarized based on the parameter mode:

  • 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 contains the same value all the time as it was set prior to the call.
  • An 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 that was last set in the formal parameter. If a handled exception occurs, the value of the actual parameter takes on the last value that was assigned to the formal parameter. If an unhandled exception occurs, the value of the actual parameter remains as it was prior to the call.
  • An IN OUT formal parameter is processed in the same way as an IN parameter. It is initialized to the actual parameter with which it is called. 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. This is the same as how an OUT parameter is processed. If a handled exception occurs, the value of the actual parameter takes on the last value that was assigned to the formal parameter. If an unhandled exception occurs, the value of the actual parameter remains as it was prior to the call.