
Example of a Problem Caused by Passing Information in a Variable
/******************************* REXX ******************************/
/* NOTE: This exec contains an error.
*/
/* It uses a DO loop to call an internal subroutine and the
*/
/* subroutine also uses a DO loop with 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
CALL subroutine
SAY answer
/* Displays 105 */
END
EXIT
subroutine:
DO i = 1 TO 5
answer = n number2
number1 = number2
number2 = answer
END
RETURN
To avoid this kind of problem in an internal subroutine, you can use:
v
The PROCEDURE instruction as described in the next topic.
v
Different variable names in a subroutine and pass arguments on the CALL
instruction as described in “Passing Information by Using Arguments” on page 74.
Protecting Variables with the PROCEDURE Instruction:
When you use the
PROCEDURE instruction immediately after the subroutine label, all variables used
in the subroutine become local to the subroutine 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.
The following two examples show the differing results when a subroutine uses the
PROCEDURE instruction and when it doesn’t.
Example Using the PROCEDURE Instruction
/******************************* REXX ******************************/
/* This exec uses a PROCEDURE instruction to protect the variables */
/* within its subroutine.
*/
/*******************************************************************/
number1 = 10
CALL subroutine
SAY number1 number2
/* displays 10 NUMBER2 */
EXIT
subroutine: PROCEDURE
number1 = 7
number2 = 5
RETURN
Writing a Subroutine;
Chapter 6. Writing Subroutines and Functions
73
Содержание TSO/E REXX
Страница 1: ...z OS TSO E REXX User s Guide SA22 7791 00 ...
Страница 2: ......
Страница 3: ...z OS TSO E REXX User s Guide SA22 7791 00 ...
Страница 10: ...viii z OS V1R1 0 TSO E REXX User s Guide ...
Страница 12: ...x z OS V1R1 0 TSO E REXX User s Guide ...
Страница 14: ...xii z OS V1R1 0 TSO E REXX User s Guide ...
Страница 18: ...xvi z OS V1R1 0 TSO E REXX User s Guide ...
Страница 20: ...2 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 58: ...Tracing Expressions with the TRACE Instruction 40 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 78: ...60 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 86: ...Built In Functions 68 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 128: ...Issuing Other Types of Commands from an Exec 110 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 136: ...Debugging Execs 118 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 170: ...Protecting Elements in the Data Stack 152 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 201: ...Part 3 Appendixes Copyright IBM Corp 1988 2001 183 ...
Страница 202: ...184 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 222: ...Using Variables 204 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 226: ...208 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 238: ...220 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 241: ......