Types of REXX clauses
REXX clauses can be instructions, null clauses, and labels. Instructions can be keyword instructions, assignments, or commands.
/* QUOTA REXX program. Two car dealerships are competing to */
/* sell the most cars in 30 days. Who will win? */
store_a=0; store_b=0
DO 30
CALL sub
END
IF store_a>store_b THEN SAY "Store_a wins!"
ELSE IF store_b>store_a THEN SAY "Store_b wins!"
ELSE SAY "It's a tie!"
EXIT
sub:
store_a=store_a+RANDOM(0,20) /* RANDOM returns a random number in */
store_b=store_b+RANDOM(0,20) /* in specified range, here 0 to 20 */
RETURN
Keyword instructions
A keyword instruction tells the language processor to do something. It begins with a REXX keyword that identifies what the language processor is to do. For example, DO can group instructions and execute them repetitively, and IF tests whether a condition is met. SAY writes to the current terminal output device.
IF, THEN and ELSE are three keywords that work together in one instruction. Each keyword forms a clause, which is a subset of an instruction. If the expression that follows the IF keyword is true, the instruction that follows the THEN keyword is processed. Otherwise, the instruction that follows the ELSE keyword is processed. (Note that a semicolon is needed before the ELSE if you are putting an ELSE clause on the same line with a THEN.) If you want to put more than one instruction after a THEN or ELSE, use a DO before the group of instructions and an END after them. More information about the IF instruction appears in Conditional instructions.
The
EXIT keyword tells the language processor to end the program. Using
EXIT in the preceding example is necessary because, otherwise, the
language processor would execute the code in the subroutine after
the label
sub:
. EXIT is not necessary in some programs
(such as those without subroutines), but it is good programming practice
to include it. More about EXIT appears in
EXIT instructions.
Assignment
number = 4
store_a=0
.
The left side of the assignment (before the equal sign) contains the
name of the variable to receive a value from the right side (after
the equal sign). The right side can be an actual value (such as
4
)
or an expression. An expression is something that needs to be
evaluated,
such as an arithmetic expression. The expression can contain numbers,
variables, or both.
number = 4 + 4
number = number + 4
In the first example, the value of number
is 8
. If the
second example directly followed the first in a program, the value of number
would
become 12
. More about expressions is in Expressions.
Label
A label, such as sub:
, is a symbolic name followed by a colon. A label can
contain either single- or double-byte characters or a combination of single- and double-byte
characters. (Double-byte characters are valid only if OPTIONS ETMODE is the first instruction in
your program.) A label identifies a portion of the program and is commonly used in subroutines and
functions, and with the SIGNAL instruction. (Note that you need to include a RETURN instruction at
the end of a subroutine to transfer control back to the main program.) More about the use of labels
appears in Subroutines and functions and SIGNAL instructions.
Null clause
- Comments
- A comment begins with
/*
and ends with*/
. Comments can be on one or more lines, or on part of a line. You can put information in a comment that might not be obvious to a person reading the REXX instructions. Comments at the beginning of a program can describe the overall purpose of the program and, perhaps, list special considerations. A comment next to an individual instruction can clarify its purpose.Note: REXX/CICS does not require that a REXX program begins with a comment. However, for portability reasons, you may want to start each REXX program with a comment that includes the wordREXX
. Not every language processor requires this program identifier. However, to run the same exec on MVS™ TSO and CICS, you should include the/* REXX */
program identifier to satisfy TSO requirements. - Blank lines
- Blank lines separate groups of instructions and aid readability. The more readable a program is, the easier it is to understand and maintain.
Commands
/* REXX program including a command */
ADDRESS REXXCICS 'DIR'
ADDRESS is a
keyword instruction. When you specify an environment and a command on an ADDRESS instruction, a
single command is sent to the environment you specify. In this case, the environment is
REXXCICS
. The command is the expression that follows the environment: 'DIR'
The DIR command lists the files in your current file system
directory. For more details about changing the host command environment, see Changing the host command environment. For more information about issuing commands, see Using commands from a program.