IBM SC34-5764-01 Server User Manual


 
In the two preceding examples, notice the positional relationships between long and length, and wide and
width. Also notice how information is received from variable perim. Both programs include perim on a
RETURN instruction. For the program with a subroutine, the language processor assigns the value in
perim to the special variable RESULT. For the program using a function, the language processor replaces
the function call perimeter(long,wide) with the value in perim.
Using the ARG Built-in Function: Another way for a subroutine or function to receive arguments is with
the ARG built-in function. This function returns the value of a particular argument. A number 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) /* puts the first argument into length */
width = ARG(2) /* puts the second argument into width */
For more information about the ARG function see section “ARG” on page 134.
Receiving Information from a Subroutine or Function
Although a subroutine or function can receive up to 20 arguments, it can specify only one expression on
the RETURN instruction. That expression can be:
v A number
RETURN 55
v One or more variables whose values are substituted (or their names if no values have been assigned).
RETURN value1 value2 value3
v A literal string
RETURN 'Work complete.'
v An arithmetic, comparison, or logical expression whose value is substituted.
RETURN 5 * number
This program receives as arguments the length and width of a
rectangle and passes that information to an internal function,
named perimeter. The function then calculates the perimeter of
the rectangle.
/***********************************REXX***********************************/
/* */
/* */
/* */
/* */
/*****************************************************************************/
PARSE ARG long wide
SAY ‘The perimeter is’ perimeter (long,wide) ‘inches.’
EXIT
perimeter:
ARG length, width
perim = 2 * length + 2 * width
RETURN perim
Figure 40. Example of Passing Arguments on the Call to an Internal Routine
Writing Subroutines and Functions
66
CICS TS for VSE/ESA: REXX Guide