To determine whether to make a function internal or external, you might consider
factors, such as:
v Size of the function. Very large functions often are external, whereas small
functions fit easily within the calling exec.
v How you want to pass information. It is quicker to pass information through
variables in an internal function. This method is described in the next topic under
“Passing Information by Using Variables”.
v Whether the function might be of value to more than one exec or user. If so, an
external function is preferable.
v Performance. The language processor searches for an internal function before it
searches for an external function. For the complete search order of functions,
see “Search Order for Functions” on page 134.
Passing Information to a Function
When an exec and its internal function share the same variables, you can use
commonly shared variables to pass information between caller and internal function.
The function does not need to pass arguments within the parentheses that follow
the function call. However, all functions, both internal and external, must return a
value.
Passing Information by Using Variables
When an exec and its internal function share the same variables, the value of a
variable is what was last assigned, regardless of whether the assignment was in the
main part of the exec or in the function. In the following example, the value of
answer is assigned in the function and displayed in the main part of the exec. The
variables number1, number2, and answer are shared. In addition, the value of answer
replaces the function call because answer follows the RETURN instruction.
REXX.EXEC(MAIN)
instruction(s)
x=func2(arg1)
instruction(s)
.
.
.
exit
REXX.EXEC(FUNC2)
ARG var1
instruction(s)
RETURN value
Writing a Function
Chapter 6. Writing Subroutines and Functions 79