IBM SC34-5764-01 Server User Manual


 
FUNC2
ARG var1
instruction(s)
RETURN value
MAIN
instruction(s)
z=func2(arg1)
instruction(s)
exit
When to Use Internal Versus External Subroutines or Functions
To determine whether to make a subroutine or function internal or external, you might consider factors,
such as:
v Size of the subroutine or function. Very large subroutines and functions often are external, whereas
small ones fit easily within the calling program.
v How you want to pass information. It is quicker to pass information through variables in an internal
subroutine or function. The next topic describes passing information this way.
v Whether the subroutine or function might be of value to more than one program or user. If so, an
external subroutine or function is preferable.
v Performance. For functions, the language processor searches for an internal function before it searches
for an external function.
Passing Information
A program and its internal subroutine or function can share the same variables. Therefore, you can use
commonly shared variables to pass information between caller and internal subroutine or function. You can
also use arguments to pass information to and from an internal subroutine or an internal function. External
subroutines, however, cannot share variables with the caller. To pass information to them, you need to use
arguments or some other external way, such as the data stack. (Remember: An internal 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 a program and its internal subroutine or function share the same variables, the value of a variable is
what was last assigned. This is regardless of whether the assignment was in the main part of the program
or in the subroutine or function.
The following example shows passing information to a subroutine. The variables number1, number2, and
answer are shared. The value of answer is assigned in the subroutine and used in the main part of the
program.
Writing Subroutines and Functions
60
CICS TS for VSE/ESA: REXX Guide