Writing and running a REXX application

One advantage of the REXX language is its similarity to ordinary English. This similarity makes it easy to read and write a REXX program, as shown in the following examples.

Example of a simple program

To write a line of output, you use the REXX instruction SAY followed by the text you want written.

Figure 1. Example: Hello World program
/* Sample REXX Program */
SAY 'Hello world!'

This program starts with a comment line to identify it as a REXX program. A comment begins with /* and ends with */.

When you run the program, the SAY instruction sends the following output to the terminal device:
Hello world!

Example of a longer program

Even in a longer program, the instructions are similar to ordinary English and are easy to understand. In this example, you call the program ADDTWO, which adds two numbers.

  1. From a CICS terminal, clear the screen and enter the following command:
    REXX addtwo
  2. Enter two numbers.

Here is the ADDTWO program. The comment in the program code assumes that the first number entered is 42 and the second number is 21.

Figure 2. Example: ADDTWO program
/**************************** REXX *********************************/
/* This program adds two numbers and produces their sum.           */
/*******************************************************************/
say 'Enter first number.'
PULL number1                                /* Assigns: number1=42 */
say 'Enter second number.'
PULL number2                                /* Assigns: number2=21 */
sum = number1 + number2
SAY 'The sum of the two numbers is' sum'.'
When you run the example program, the first PULL instruction assigns the variable number1 the value 42. The second PULL instruction assigns the variable number2 the value 21. The next line contains an assignment. The language processor adds the values in number1 and number2 and assigns the result, 63, to sum . Finally, the SAY instruction displays the output line:
The sum of the two numbers is 63.