Running an Exec from a CLIST
A CLIST can invoke an exec with the EXEC command explicitly or implicitly. If it
invokes an exec implicitly, the exec must be in a PDS allocated to SYSEXEC or
SYSPROC. The CLIST that invokes the exec does not have to be allocated to
SYSPROC. After the invoked exec and other programs it might call complete,
control returns to the CLIST instruction following the invocation.
Similarly, an exec can invoke a CLIST with the EXEC command explicitly or
implicitly. If it invokes a CLIST implicitly, the CLIST must be in a PDS allocated to
SYSPROC, yet the exec does not have to be in a PDS allocated to a system file.
Note: Execs and CLISTs cannot access each other’s variables and GLOBAL
variables cannot be declared in a CLIST that is invoked from an exec.
The following examples demonstrate how a CLIST invokes an exec and how a
number is returned to the invoking CLIST. The CLIST named TEST explicitly
executes an exec named EXEC1. EXEC1 calls EXEC2, which returns the result "A
OK". EXEC1 then returns to the CLIST with a numeric return code of 100 if
information was passed correctly and 50 if information was not passed correctly.
The results from this series of programs is as follows:
USERID.MY.CLIST(TEST)
EXEC MYREXX.EXEC(EXEC1) EXEC
WRITE THE RESULT FROM THE EXECS IS &LASTCC.
END
USERID.MYREXX.EXEC(EXEC1)
SAY 'We are now in Exec1.'
CALL Exec2
SAY 'The result from Exec2 is' RESULT
IF RESULT = 'A OK' THEN
DO
SAY 'The result is 100% correct.'
EXIT 100
END
ELSE
DO
SAY 'The result is less than perfect.'
EXIT 50
END
USERID.MYREXX.EXEC(EXEC2)
SAY 'Exec2 speaking.'
var = 'A OK'
RETURN var
Running Execs in a TSO/E Address Space
Chapter 13. Using REXX in TSO/E and Other MVS Address Spaces 175