Receiving Information From A Subroutine - IBM TSO/E REXX User Manual

Table of Contents

Advertisement

The following exec sends information to an internal subroutine that computes the
perimeter of a rectangle. The subroutine returns a value in the variable perim that is
specified after the RETURN instruction. The main exec receives the value in the
special variable "RESULT".
Notice the positional relationships between long and length, and wide and width.
Also notice how information is received from variable perim in the special variable
RESULT.
Using the ARG Built-in Function: Another way for a subroutine to receive
arguments is with the ARG built-in function. This function returns the value of a
particular argument specified by a number that represents the argument position.
For instance, in the previous example, instead of the ARG instruction,
ARG length, width
you can use the ARG function as follows:
length = ARG(1)
width = ARG(2)
More information about the ARG function appears in z/OS TSO/E REXX Reference.

Receiving Information from a Subroutine

Although a subroutine can receive up to 20 arguments, it can specify only one
expression on the RETURN instruction. That expression can be:
v A number
v One or more variables whose values are substituted or when no values were
v A literal string
v An arithmetic, comparison, or logical expression whose value is substituted.
Example of Passing Arguments on the CALL Instruction
/******************************** REXX ********************************/
/* This exec receives as arguments the length and width of a
/* rectangle and passes that information to an internal subroutine. */
/* The subroutine then calculates the perimeter of the rectangle.
/**********************************************************************/
PARSE ARG long wide
CALL perimeter long, wide
SAY 'The perimeter is' RESULT 'inches.'
EXIT
perimeter:
ARG length, width
perim = 2 * length + 2 * width
RETURN perim
RETURN 55
assigned, return their names
RETURN value1 value2 value3
RETURN 'Work complete.'
RETURN 5 * number
/* puts the first argument into length */
/* puts the second argument into width */
Chapter 6. Writing Subroutines and Functions
Writing a Subroutine;
*/
*/
75

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents