Specifying values when calling a program, Specifying too few values, Specifying too many values – IBM SC34-5764-01 User Manual

Page 37

Advertising
background image

The PULL instruction can extract more than one value at a time from the terminal by separating a line of
input. The following variation of the example shows this.

REXX addtwo 42 21

The PULL instruction extracts the numbers 42 and 21 from the terminal.

Specifying Values When Calling a program

Another way for a program to receive input is through values you specify when you call the program. For
example to pass the two numbers 42 and 21 to a program named ADD, you could use the CICS
command:

REXX add 42 21

The program ADD uses the ARG instruction to assign the input to variables as shown in the following
example.

ARG assigns the first number 42, to number1, and the second number 21, to number2.

If the number of values is fewer or more than the number of variable names after ARG or PULL, errors
can occur, as the following sections describe.

Specifying Too Few Values

If you specify fewer values than the number of variables after PULL or ARG, the extra variables are set to
the null string. Here is an example in which you pass only one number to the program:

REXX add 42

The language processor assigns the value 42 to number1, the first variable following ARG. It assigns the
null string to number2, the second variable. In this situation, the program ends with an error when it tries to
add the two variables. In other situations, the program might not end in error.

Specifying Too Many Values

When you specify more values than the number of variables following PULL or ARG, the last variable gets
the remaining values. For example, you pass three numbers to the program ADD:

/**************************** REXX ******************************/
/*

This program adds two numbers and produces their sum.

*/

/****************************************************************/

PULL number1
PULL number2
sum = number1 + number2
SAY 'The sum of the two numbers is' sum'.'

Figure 7. Example of a program That Uses PULL

/**************************** REXX ******************************/
/*

This program adds two numbers and says their sum

*/

/****************************************************************/

PULL number1 number2
sum = number1 + number2
SAY 'The sum of the two numbers is' sum'.'

Figure 8. Variation of an Example that Uses PULL

/**************************** REXX ******************************/
/*

This program receives two numbers as input, adds them, and

*/

/*

produces their sum.

*/

/****************************************************************/

ARG number1 number2
sum = number1 + number2
SAY 'The sum of the two numbers is' sum'.'

Figure 9. Example of a program That Uses the ARG Instruction

Writing and Running a REXX Program

Chapter 2. Writing and Running a REXX Program

15

Advertising