IBM TSO/E REXX User Manual page 98

Table of Contents

Advertisement

Writing a Function
Using the same variables in an exec and its internal function can sometimes create
problems. In the following example, the main part of the exec and the function use
the same control variable, "i", for their DO loops. As a result, the DO loop repeats
only once in the main exec because the function returns to the main exec with i =
6.
To avoid this kind of problem in an internal function, you can use:
v The PROCEDURE instruction as described in the next topic.
v Different variable names in a function.
Protecting Variables with the PROCEDURE Instruction: When you use the
PROCEDURE instruction immediately following the function label, all variables used
in the function become local to the function and are shielded from the main part of
the exec. You can also use the PROCEDURE EXPOSE instruction to protect all but
a few specified variables.
80
z/OS V1R1.0 TSO/E REXX User's Guide
Example of Passing Information in a Variable
/****************************** REXX *******************************/
/* This exec receives a calculated value from an internal
/* function and displays that value.
/*******************************************************************/
number1 = 5
number2 = 10
SAY add()
SAY answer
EXIT
add:
answer = number1 + number2
RETURN answer
Example of a Problem Caused by Passing Information in a Variable
/****************************** REXX *******************************/
/* This exec uses an instruction in a DO loop to call an internal */
/* function. A problem occurs because the function also uses a DO */
/* loop with the same control variable as the main exec. The DO
/* loop in the main exec repeats only once.
/*******************************************************************/
number1 = 5
number2 = 10
DO i = 1 TO 5
SAY add()
END
EXIT
add:
DO i = 1 TO 5
answer = number1 + number2
number1 = number2
number2 = answer
END
RETURN answer
*/
*/
/* Displays 15
*/
/* Also displays 15 */
*/
*/
/* Displays 105 */

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents