IBM SC34-5764-01 Server User Manual


 
Calling Another REXX Program as a Command
Previously, this book discussed how to call another program as an external routine (Chapter 6, “Writing
Subroutines and Functions,” on page 57). 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.
Calling Another Program with the EXEC Command
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
Issuing Commands from a program
The following sections explain what a host command environment is, how commands are passed to host
command environments, and how to change the host command environment.
What is a Host Command Environment?
An environment for executing commands is called a host command environment. Before a program
runs, an active host command environment is defined to handle the commands. . When the language
processor encounters a command, it passes the command to the host command environment for
processing.
When a REXX program runs on a host system, there is at least one default environment available for
executing commands.
The host command environments are as follows:
REXXCICS
This is the default REXX/CICS command environment. All REXX/CICS, SQL, EDIT, RFS, or RLS
commands can be issued from this environment. However, CICS commands must be prefixed with
CICS, SQL statements with EXECSQL, EDIT commands with EDITSVR, RFS commands with
RFS, and RLS commands with RLS.
CICS This is an optional environment that only issues CICS commands. The first word of the host
command string is the command name (for example: SEND, RECEIVE).
EXECSQL
This is an optional environment that issues SQL statements (SELECT) to the CICS/DB2 interface.
EDITSVR
This is an optional environment that creates the edit session.
FLSTSVR
This is an optional environment that executes commands for the File List Utility.
Using Commands from a Program
82
CICS TS for VSE/ESA: REXX Guide