Procedures can be terminated in several different ways:
with the EXIT-PROCEDURE command
with the END-PROCEDURE command
with the CANCEL-PROCEDURE command
The END-PROCEDURE command at the end of the procedure is supported only for reasons of compatibility with non-S procedures. When a procedure is terminated with END-PROCEDURE, error information cannot be transferred or a program cannot be resumed.
The CANCEL-PROCEDURE command can be used to cancel procedure execution entirely. SYSCMD is reset to the primary allocation. If CANCEL-PROCEDURE is called in a subordinate procedure, all superordinate procedures are likewise canceled.
If a procedure does not contain a termination command, it is automatically terminated after the last command is executed. In the event of an error, the error code is returned to the caller.
Exiting with EXIT-PROCEDURE
S procedures are always terminated by the EXIT-PROCEDURE command. EXIT-PROCEDURE terminates procedure execution, supplies error information to the caller and also causes a program to be resumed, if appropriate.
EXIT-PROCEDURE is executed only if the procedure has been executed correctly up to this command call, i.e. if it has not been canceled by an error or the CANCEL-PROCEDURE command.
The RESUME-PROGRAM operand can be used to resume a program that is loaded when the procedure is terminated.
Because the caller’s SYSFILE environment can be amended in foreground procedures, (SYSTEM-FILE-CONTEXT=*SAME-AS-CALLER) the caller must ensure, after the procedure has terminated, that the correct SYSFILE environment is in effect.
For information on how error information is supplied to the caller, see section “Error transfer”.