What is a REXX Program?

A REXX program consists of REXX language instructions that the REXX interpreter interprets directly. A program can also contain commands that the host environment executes, such as CICS commands (see page ***).

One advantage of the REXX language is its similarity to ordinary English. This similarity makes it easy to read and write a REXX program. For example, to write a line of output, you use the REXX instruction SAY followed by the text you want written.

Figure 1. Example of a Simple 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 */. More about comments and why you might need a REXX program identifier appears later on page ***.

When you run the program, the SAY instruction sends to the terminal output device:

Hello world!

Even in a longer program, the instructions are similar to ordinary English and are easy to understand. For example, you could use the following to call the program ADDTWO, which adds two numbers: From a CICS terminal you would clear the screen and enter:

REXX addtwo

For this example, the first number you will enter is 42, and the second number is 21. Here is the ADDTWO program:

Figure 2. Example of a Longer 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.

Before you try any examples, please read the next two sections, Syntax of REXX Instructions and Typing in a Program.