Parameter modes v16
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 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:
The
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 theIN
parameter in the called program. However, the called program can't assign a new value to theIN
parameter. After control returns to the calling program, the actual parameter always contains the same value that it had prior to the call.Like an
IN
parameter, anIN OUT
formal parameter is initialized to the actual parameter with which it's called. Like anOUT
parameter, anIN 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.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.