Previous topic |
Next topic |
Contact z/OS |
z/OS TSO/E REXX Reference
.-,--------------. V | >>-CALL--+-name---+------------+-+-----------+--;-------------->< | '-expression-' | +-OFF-+-ERROR---+-------------------+ | +-FAILURE-+ | | '-HALT----' | '-ON-+-ERROR---+-+----------------+-' +-FAILURE-+ '-NAME--trapname-' '-HALT----'
CALL calls a routine (if you specify name) or controls the trapping of certain conditions (if you specify ON or OFF).
To control trapping, you specify OFF or ON and the condition you want to trap. OFF turns off the specified condition trap. ON turns on the specified condition trap. All information about condition traps is contained in Conditions and condition traps.
To call a routine, specify name, a literal string or symbol that is taken as a constant. The name must be a symbol, which is treated literally, or a literal string. The routine called can be:
If name is a string (that is, you specify name in quotation marks), the search for internal routines is bypassed, and only a built-in function or an external routine is called. Note that the names of built-in functions (and generally the names of external routines, too) are in uppercase; therefore, you should uppercase the name in the literal string.
The called routine can optionally return a result, and when it does, the CALL instruction is functionally identical with the clause:
.-,--------------. V | >>-result=name(----+------------+-+--)--;---------------------->< '-expression-'
If the called routine does not return a result, then you will get an error if you call it as a function (as previously shown).
If the subroutine returns a result, the result is stored in the REXX special variable RESULT, not the special variable RC. The REXX special variable RC is set when you enter host commands from a REXX program (see Host commands and host command environments), but RC is not set when you use the CALL instruction. See Reserved keywords, special variables, and command names for descriptions of the three REXX special variables RESULT, RC, and SIGL.
TSO/E supports specifying up to 20 expressions, separated by commas. The expressions are evaluated in order from left to right and form the argument strings during execution of the routine. Any ARG or PARSE ARG instruction or ARG built-in function in the called routine accesses these strings rather than any previously active in the calling program, until control returns to the CALL instruction. You can omit expressions, if appropriate, by including extra commas.
The CALL then causes a branch to the routine called name, using exactly the same mechanism as function calls. (See Functions.) The search order is in the section on functions (see Search order) but briefly is as follows:
During execution of an internal routine, all variables previously known are generally accessible. However, the PROCEDURE instruction can set up a local variables environment to protect the subroutine and caller from each other. The EXPOSE option on the PROCEDURE instruction can expose selected variables to a routine.
Calling an external program as a subroutine is similar to calling an internal routine. The external routine, however, is an implicit PROCEDURE in that all the caller's variables are always hidden. The status of internal values (NUMERIC settings, and so forth) start with their defaults (rather than inheriting those of the caller). In addition, you can use EXIT to return from the routine.
When control reaches an internal routine the line number of the CALL instruction is available in the variable SIGL (in the caller's variable environment). This may be used as a debug aid, as it is, therefore, possible to find out how control reached a routine. Note that if the internal routine uses the PROCEDURE instruction, then it needs to EXPOSE SIGL to get access to the line number of the CALL.
Eventually the subroutine should process a RETURN instruction, and at that point control returns to the clause following the original CALL. If the RETURN instruction specified an expression, the variable RESULT is set to the value of that expression. Otherwise, the variable RESULT is dropped (becomes uninitialized).
An internal routine can include calls to other internal routines, as well as recursive calls to itself.
During internal subroutine (and function) execution, all important pieces of information are automatically saved and are then restored upon return from the routine. These are:
Implementation maximum: The total nesting of control structures, which includes internal routine calls, may not exceed a depth of 250.
Copyright IBM Corporation 1990, 2014