── ON ─┬─ TASKFAULT ─┬─┬────────────────────┬──────────────┤ └─ RESTART ───┘ └─ , ── <statement> ─┘
Explanation
The ON statement causes the job to execute the specified statement when a task is abnormally terminated (ON TASKFAULT), or when the job is restarted after a halt/load (ON RESTART). The statement specified can be a compound statement if multiple actions are desired.
Only one ON TASKFAULT statement and one ON RESTART statement can be enabled at a time. Thus, any ON TASKFAULT statement disables any previous ON TASKFAULT statement, and any ON RESTART statement disables any previous ON RESTART statement.
If a subroutine executes an ON statement, the ON statement disables any previous ON statement of the same type until the subroutine is finished or the subroutine ON condition is disabled.
The ON TASKFAULT, statement; form enables the condition TASKFAULT. If any task is subsequently terminated abnormally or if a compilation is terminated for syntax errors, the statement is executed. These termination conditions include operator or programmatic discontinuation as well as program faults. If any asynchronous tasks are active when the end of a subroutine or job is reached, the WFL job will automatically wait for them to complete before continuing. If one of the asynchronous tasks terminates abnormally while the WFL job is waiting for all of them to complete, the statement specified with the TASKFAULT option will not be executed until all of the asynchronous tasks are completed.
If a GO TO out of the ON TASKFAULT statement is not performed, the following actions occur:
-
Any task fault interrupt that occurs during the execution of the ON TASKFAULT statement is queued.
-
When execution of the ON TASKFAULT statement is completed, action is taken on any task faults that were queued. A task fault is selected, and a new invocation of the ON TASKFAULT statement is initiated.
-
The ON TASKFAULT statement is invoked for each task fault that becomes queued. Therefore, the ON TASKFAULT statement continues execution until no task faults remain in the queue and either a GO TO out of the ON TASKFAULT statement is executed or the end of the ON TASKFAULT statement is reached.
The statement ON TASKFAULT; disables the condition TASKFAULT. While this statement is in effect, an abnormal task termination has no effect on the job.
Similarly, the RESTART condition can be enabled and disabled by using the following statements:
ON RESTART, <statement>; ON RESTART;
Exiting the subroutine returns the RESTART condition to the condition before the subroutine was called.
If the enabled ON statement does not execute a GO TO statement, the job resumes execution at the point where it would have continued if the statement had been disabled. The enabled ON statement can only be disabled within the same procedure.
If the system is halt/loaded during the execution of a job, the system first checks to determine if there is a RESTART condition that is enabled. If one is enabled, the statement specified in the condition is executed when the job is restarted. If one is not enabled, the job restarts at the most recent point at which no tasks were running. If there are no asynchronous tasks, this point is just prior to the last task initiation.
One typical use of the ON RESTART statement is to reassign values to the task and file variables in the job. These variables do not retain their values after a halt/load. Refer to Job Restart After a Halt/Load for further details.
Examples
This first example illustrates the use of the ON TASKFAULT statement:
?BEGIN JOB X; SUBROUTINE SUB1; BEGIN ON TASKFAULT, BEGIN DISPLAY "SUB TASKFAULT TAKEN"; GO ERR; END; % End of ON statement RUN X; % If X aborts, "SUB TASKFAULT TAKEN" is % displayed by the ON TASKFAULT. ON TASKFAULT; RUN Y; % If Y aborts, "JOB TASKFAULT" is displayed. END SUB1; % End of subroutine SUB1 RUN A; % If A aborts, no TASKFAULT is executed. ON TASKFAULT, DISPLAY "JOB TASKFAULT"; RUN B; % If B aborts, "JOB TASKFAULT" is displayed. SUB1; ERR: ?END JOB.
In this example, program P2 is assumed to update a global file (G) created by P1. If a halt/load occurs while P2 is running, the job does not normally rerun P1 but reruns P2. In that case, P2 double updates any records that P2 had updated prior to the halt/load.
Therefore, an ON RESTART statement is executed to ensure that P1 is rerun and that the file is re-created.
?BEGIN JOB X; FILE G; ON RESTART, GO TO L; L: RUN P1; FILE F1:=G; RUN P2; FILE F2:=G; ?END JOB.
In this example, if a halt/load occurs while program P1 is running, the RESTART condition that contains the statement RUN R1 is invoked. If a halt/load occurs while program P2 is running, the RESTART in the outer block that contains the start statement RUN R2 is invoked. This is because at this point the RESTART condition in the subroutine is disabled, returning the RESTART condition to the condition before the subroutine was called.
?BEGIN JOB X; SUBROUTINE SUB1; BEGIN ON RESTART, RUN R1; RUN P1; ON RESTART; RUN P2; END; ON RESTART, RUN R2; SUB1; ?END JOB.
In this example, if a halt/load occurs while program P1 or program P2 is running, the RESTART condition that contains the statement RUN R1 is invoked. In the latter case (halt/load while program P2 is running), the disabled ON statement within subroutine SUB1 does not disable the RESTART condition outside of subroutine SUB1.
?BEGIN JOB X; SUBROUTINE SUB1; BEGIN RUN P1; ON RESTART; RUN P2; END; ON RESTART, RUN R1; SUB1; ?END JOB.