A REXX program can issue several types of commands. The main categories of commands are:
When a program issues a command, the REXX special variable RC is set to the return code. A program can use the return code to determine a course of action within the program. Every time a command is issued, RC is set. Therefore, RC contains the return code from the most recently issued command.
Generally, to differentiate commands from other types of instructions, you enclose the command within single or double quotation marks. If the command is not enclosed within quotation marks, it is processed as an expression and might end in error. For example, the language processor treats an asterisk (*) as a multiplication operator.
Many CICS commands use single quotation marks within the command. For this reason, it is recommended that, as a matter of course, you enclose CICS commands within double quotation marks.
The following example places the word test in the temporary storage queue ABC.
"CICS WRITEQ TS QUEUE('ABC') FROM('test')"
When a command contains a variable, the value of the variable is not substituted if the variable is within quotation marks. The language processor uses the value of a variable only for variables outside quotation marks.
Previously, this book discussed how to call another program as an external routine (Writing Subroutines and Functions). You can also call a program from another program explicitly with the EXEC command. Like an external routine, a program called explicitly or implicitly can return a value to the caller with the RETURN or EXIT instruction. Unlike an external routine, which passes a value to the special variable RESULT, the program that is called passes a value to the REXX special variable RC.
To explicitly call another program from within a program, use the EXEC command as you would any other REXX/CICS command. The called program should end with a RETURN or EXIT instruction, ensuring that control returns to the caller. The REXX special variable RC is set to the return code from the EXEC command. You can optionally return a value to the caller on the RETURN or EXIT instruction. When control passes back to the caller, the REXX special variable RC is set to the value of the expression returned on the RETURN or EXIT instruction.
For example, to call a program named CALC and pass it an argument of four numbers, you could include the following instructions:
"EXEC calc 24 55 12 38"
SAY 'The result is' RC
CALC might contain the following instructions:
ARG number1 number2 number3 number4
answer = number1 * (number2 + number3) - number4
RETURN answer