Invoking Another Exec with the EXEC Command

To explicitly invoke another exec from within an exec, issue the EXEC command as you would any other TSO/E command. The called exec 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 invoke an exec named MYREXX.EXEC(CALC) and pass it an argument of four numbers, you could include the following instructions:
"EXEC myrexx.exec(calc) '24 55 12 38' exec"
SAY 'The result is' RC
'Calc' might contain the following instructions:
ARG number1 number2 number3 number4
answer = number1 * (number2 + number3) - number4
RETURN answer

You might want to invoke an exec with the EXEC command rather than as an external routine when the exec is not within the same PDS as the calling exec, or when the PDSs of the two execs are not allocated to either SYSEXEC or SYSPROC.