Passing Information To A Subroutine; Passing Information By Using Variables - IBM TSO/E REXX User Manual

Table of Contents

Advertisement

Writing a Subroutine;

Passing Information to a Subroutine

An internal subroutine can share variables with its caller. Therefore you can use
commonly shared variables to pass information between caller and internal
subroutine. You can also use arguments to pass information to and from an internal
subroutine. External subroutines, however, cannot share the same variables, and
information must pass between them through arguments or some other external
way, such as the data stack.

Passing Information by Using Variables

When an exec and its internal subroutine share the same variables, the value of a
variable is what was last assigned, regardless of whether the assignment was in the
main part of the exec or in the subroutine. In the following example, the value of
answer is assigned in the subroutine and displayed in the main part of the exec.
The variables number1, number2, and answer are shared.
Using the same variables in an exec and its internal subroutine can sometimes
create problems. In the following example, the main part of the exec and the
subroutine 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 subroutine returns to the main
exec with i = 6.
72
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
/* subroutine and displays that value.
/*******************************************************************/
number1 = 5
number2 = 10
CALL subroutine
SAY answer
EXIT
subroutine:
answer = number1 + number2
RETURN
*/
*/
/* Displays 15 */

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents