Returning from a Subprocedure

This section applies to ordinary subprocedures and to linear-main procedures.

A subprocedure returns normally when a RETURN operation is performed successfully or when the last statement in the procedure (not a RETURN operation) is processed. If the subprocedure has any local files in automatic storage, they will be closed when the subprocedure ends. Otherwise, other than the removal of the subprocedure from the call stack no termination actions are performed until the cycle-main procedure, if any, of the program ends. In other words, all the actions listed for the normal end of a cycle-main procedure take place only for the main procedure.

A subprocedure ends abnormally and control returns to the calling procedure when an unhandled exception occurs. Any local files in automatic storage are closed. Other than that, no further actions occur until the cycle-main procedure ends.

If the module is a cycle module, and the main procedure is never called (and therefore cannot end) then any files, data areas, etcetera, will not be closed. If you think this might arise for a subprocedure, you should code a termination procedure that gets called when the subprocedure ends. This is especially true if the subprocedure is in a module with NOMAIN specified on the control specification.



[ Top of Page | Previous Page | Next Page | Contents | Index ]