z/OS TSO/E REXX User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Writing a Function

z/OS TSO/E REXX User's Guide
SA32-0982-00

A function is a series of instructions that an exec invokes to perform a specific task and return a value. As was described in Using Functions, a function may be built-in or user-written. An exec invokes a user-written function the same way it invokes a built-in function — by the function name immediately followed by parentheses with no blanks in between. The parentheses can contain up to 20 arguments or no arguments at all.
function(argument1, argument2,...)
or
function()
A function requires a returned value because the function call generally appears in an expression.
x = function(arguments1, argument2,...)

When the function ends, it may use the RETURN instruction to send back a value to replace the function call.

IKJC3010

Functions may be internal and designated by a label, or external and designated by the data set member name that contains the function. The previous example illustrates an internal function named "func1".

IMPORTANT NOTE

Because internal functions generally appear after the main part of the exec, when you have an internal function, it is important to end the main part of the exec with the EXIT instruction.

The following illustrates an external function named "func2".

IKJC3011
To determine whether to make a function internal or external, you might consider factors, such as:
  • Size of the function. Very large functions often are external, whereas small functions fit easily within the calling exec.
  • 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.
  • Whether the function might be of value to more than one exec or user. If so, an external function is preferable.
  • 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.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014