IBM SC34-5764-01 Server User Manual


 
The CALL then causes a branch to the routine called name, using exactly the same mechanism as
function calls, see Chapter 14, “Functions,” on page 171. The search order is in the section on functions
but briefly is as follows:
Internal routines:
These are sequences of instructions inside the same program, starting at the label that matches
name in the CALL instruction. If you specify the routine name in quotation marks, then an internal
routine is not considered for that search order. You can use SIGNAL and CALL together to call an
internal routine whose name was determined at the time of execution; this is known as a multi-way
call (see page 165). The RETURN instruction completes the execution of an internal routine.
Built-in routines:
These are routines built into the language processor for providing various functions. They always
return a string that is the result of the routine. (See page 174.)
External routines:
Users can write or use routines that are external to the language processor and the calling
program. External routines must be coded in REXX. If the CALL instruction calls an external
routine written in REXX as a subroutine, you can retrieve any argument strings with the ARG or
PARSE ARG instructions or the ARG built-in function.
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.
Example:
/* Recursive subroutine execution... */
arg z
call factorial z
say z'! =' result
exit
factorial: procedure /* Calculate factorial by */
arg n /* recursive invocation. */
if n=0 then return 1
call factorial n-1
return result * n
During internal subroutine (and function) execution, all important pieces of information are automatically
saved and then restored upon return from the routine. These are:
CALL
136
CICS TS for VSE/ESA: REXX Guide