IBM SC34-5764-01 Manual page 84

Cics transaction server for vse/esa
Table of Contents

Advertisement

Writing Subroutines and Functions
/******************************* REXX ********************************/
/*
NOTE: This program contains an error.
/* It uses a DO loop to call an internal subroutine, and the
/* subroutine uses a DO loop with the same control variable as the
/* main program. The DO loop in the main program runs only once.
/*********************************************************************/
number1 = 5
number2 = 10
DO i = 1 TO 5
CALL subroutine
SAY answer
END
EXIT
subroutine:
DO i = 1 TO 5
answer = number1 + number2
number1 = number2
number2 = answer
END
RETURN
Figure 31. Example of a Problem Caused by Passing Information in a Variable Using a Subroutine
The next example is the same, except it passes information using a function instead of a subroutine.
/******************************* REXX ********************************/
/*
NOTE: This program contains an error.
/* It uses a DO loop to call an internal function, and the
/* function uses a DO loop with the same control variable as the
/* main program. The DO loop in the main program runs 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
Figure 32. Example of a Problem Caused by Passing Information in a Variable Using a Function
To avoid this kind of problem in an internal subroutine or function, you can use:
v The PROCEDURE instruction, as the next topic describes.
v Different variable names in a subroutine or function than in the main part of the program. For a
subroutine, you can pass arguments on the CALL instruction; section "Passing Information by Using
Arguments" on page 64 describes this.
Protecting Variables with the PROCEDURE Instruction: When you use the PROCEDURE instruction
immediately after the subroutine or function label, all variables in the subroutine or function become local
to the subroutine or function; they are shielded from the main part of the program. You can also use the
PROCEDURE EXPOSE instruction to protect all but a few specified variables.
62
CICS TS for VSE/ESA: REXX Guide
/* Produces 105 */
/* Produces 105 */
*/
*/
*/
*/
*/
*/
*/
*/

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Rexx

Table of Contents