Kilowatt Software L.L.C.
Classic Rexx Tutorial
Language Level 4.00 (TRL-2)

Procedure instruction

The procedure instruction begins an internal procedure. The instruction is preceded by a label, which is the name of the internal procedure. Multiple labels can precede the procedure. It is not necessary to specify a procedure instruction, as will be described below.

Warning: if execution inadvertently flows into a procedure instruction, this will cause error code 17 (unexpected procedure) to be raised. This problem is generally corrected by preceding the procedure instruction's label(s) by an return or exit instruction. This problem can also occur when a signal instruction transfers to an incorrect label.

When execution inadvertently flows into a procedure that lacks a procedure instruction an unexpected procedure WILL NOT be raised. This can lead to a variety of unexpected consequences. When this type of procedure is initially created you are strongly advised to precede the associated label(s) with an return or exit instruction.

The procedure instruction is not used in the initial program of an external procedure. Consequently, variables of the calling program are never exposed within external procedures.

Click here to review the structure of Rexx programs and procedures.

Exposure of calling program variables

You can use three different methods of exposing calling program variables in internal procedures. This is controlled by using the optional procedure instruction, which can be followed by an optional list of specific variables to expose.

Method 1 -- no variables exposed

If the procedure instruction is specified, without an exposed variable list, then none of the calling program's variables are exposed. Since variables aren't exposed, the internal procedure can only obtain arguments from the calling procedure, and return a result.

Hint: you will generally want to expose none of the calling program's variables, because this is the least problematic method.

Method 2 -- ALL variables exposed

When the procedure instruction is omitted, all of the calling program's variables are exposed.

Hint: you should generally AVOID the exposure of all variables, because it is VERY problematic. When this type of procedure is initially created you are strongly advised to precede the associated label(s) with an return or exit instruction.

When the internal procedure is merely referencing the values of the calling program's variables, then no problems should ensue. However, if the internal procedure m-o-d-i-f-i-e-s a variable, it might be revising a calling program's variable, even if it looks like the variable is local to the procedure.

The following shows how the absence of a procedure instruction can lead to an infinite loop.

Method 3 -- specific variables exposed

Fortunately there is another option -- to expose a specific set of the calling program's variables. This is done by using the expose clause after the procedure keyword. The specific variables that are exposed are identified after the expose keyword. The same variable(s) can be exposed through multiple procedure levels.

There are three types of variables that can be exposed.

Hint: you should expose specific variables cautiously, because it is somewhat problematic.
  


The following shows how the the misuse of an exposed variable can lead to an infinite loop.

Variable reference

Within the list of variables that follows the expose keyword, one additional capability can be used. A variable name can be enclosed in parentheses. This exposes the specific variable, and addition its value is used as a subsidiary list. The list consists of a series of variable names separated by spaces. These are exposed in sequence left to right. The names that are exposed follow the same rules as the original exposure list -- i.e. how simple, compound, and stem variables are exposed.

Note: the variable reference capability was added in language level 4.0 (TRL-2). Thus, this capability may be absent in some Rexx implementations.

Here is a simple example of the use of a variable reference in a procedure instruction's expose clause.

A detailed example of exposed variables

Here is a detailed example of a program that uses exposed variables in various procedures


Kilowatt Software L.L.C. -- Classic Rexx Tutorial -- Back to top
Click here if you have any comments or questions regarding this tutorial

Last updated on: 11 Apr 2006