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.

The following examples show how results differ when a subroutine or function uses or does not use PROCEDURE.
Figure 1. Example of Subroutine Using the PROCEDURE Instruction
/******************************* REXX ********************************/
/* This program uses a PROCEDURE instruction to protect the          */
/* variables within its subroutine.                                  */
/*********************************************************************/
 number1 = 10
 CALL subroutine
 SAY number1 number2          /* Produces  10  NUMBER2 */
 EXIT

 subroutine: PROCEDURE
 number1 = 7
 number2 = 5
 RETURN
Figure 2. Example of Subroutine without the PROCEDURE Instruction
/******************************* REXX ********************************/
/* This program does not use a PROCEDURE instruction to protect the  */
/* variables within its subroutine.                                  */
/*********************************************************************/
 number1 = 10
 CALL subroutine
 SAY number1 number2          /* Produces 7  5  */
 EXIT

 subroutine:
 number1 = 7
 number2 = 5
 RETURN
The next two examples are the same, except they use functions rather than subroutines.
Figure 3. Example of Function Using the PROCEDURE Instruction
/******************************* REXX ********************************/
/*  This program uses a PROCEDURE instruction to protect the         */
/*  variables within its function.                                   */
/*********************************************************************/
 number1 = 10
 SAY pass() number2               /* Produces  7  NUMBER2 */
 EXIT

 pass: PROCEDURE
 number1 = 7
 number2 = 5
 RETURN number1
Figure 4. Example of Function without the PROCEDURE Instruction
/******************************* REXX ********************************/
/*  This program does not use a PROCEDURE instruction to protect the */
/*  variables within its function.                                   */
/*********************************************************************/
 number1 = 10
 SAY pass() number2                   /* Produces 7  5  */
 EXIT

 pass:
 number1 = 7
 number2 = 5
 RETURN number1

Reference Reference

Feedback


Timestamp icon Last updated: Tuesday, 7 January 2014


http://pic.dhe.ibm.com/infocenter/cicsts/v5r1/topic/com.ibm.cics.rexx.doc//dfhrx/dfhrx00053.html