Task Control

Several WFL statements are available to control the execution of a task. These statements determine

  • When a task is run

  • When a task is terminated

  • How a task responds to error conditions

  • What usercode a task runs under

These statements are referred to broadly as task control statements.

Task Control Statements

Task control statements include the following:

  • ABORT

  • STOP

  • WAIT

  • ON

  • USER

The ABORT and STOP statements are available for terminating a job or task prematurely. The difference between the two statements is that the ABORT statement displays messages indicating that the job or task was terminated abnormally, while the STOP statement indicates a normal termination. Generally these statements are used as part of an IF statement or CASE statement, so that the job or task is terminated only if the specified conditions are met.

The WAIT statement suspends job execution until some specified condition is met. The uses of the WAIT statement include the following:

  • To cause the job to wait for an asynchronous task to complete, or to wait until the asynchronous task achieves a specified state

  • To cause the job to wait until a file becomes resident

  • To cause the job to wait for an OK message from the user

Examples

This example illustrates a use of the ABORT statement:

?BEGIN JOB WFLTEST; 
  TASK COMPOK; 
  COMPILE (WALLY)OBJECT/MENU/PLAN WITH PASCAL [COMPOK] LIBRARY; 
    COMPILER FILE CARD(TITLE=MENU/PLAN ON MUNCHPACK); 
  IF COMPOK IS COMPILEDOK THEN 
    RUN (WALLY)OBJECT/MENU/PLAN 
  ELSE 
    ABORT "UNSUCCESSFUL COMPILE"; 
?END JOB. 

This job first attempts to compile the source file MENU/PLAN. If the compile was successful, the job will run the object code file that was the result of the compilation. If the compile was not successful, the job is terminated abnormally by the ABORT statement and the message “UNSUCCESSFUL COMPILE” is displayed.

The following example illustrates a use of the WAIT statement:

?BEGIN JOB WFLTEST; 
  TASK TEST1, TEST2; 
  PROCESS RUN (WALLY)OBJECT/SORTIT [TEST1]; 
  PROCESS RUN (WALLY)OBJECT/SORT2 [TEST2]; 
  DO 
     WAIT 
  UNTIL TEST1 IS COMPLETED AND TEST2 IS COMPLETED; 
  RUN (WALLY)OBJECT/COLLATE; 
?END JOB. 

In this example, two asynchronous tasks are started by PROCESS statements. A DO‑UNTIL loop follows, instructing the job to wait until both asynchronous tasks are completed before continuing.

The USER statement provides another form of task control. This statement changes the usercode the WFL job is running under to the specified usercode. The tasks initiated by the WFL job will then inherit the new usercode, and its associated privileges.

The following is an example of the USER statement in a job:

?BEGIN JOB RECEIVABLE; 
  RUN OBJECT/INTEREST; 
  USER=SCROOGE/CALC; 
  RUN OBJECT/PENALTIES; 
  RUN (CRATCHIT)OBJECT/CREDIT; 
?END JOB.

In this example, the first RUN statement runs the program OBJECT/INTEREST under the job's original usercode, which was determined at the time of job initiation. The USER statement then changes the job's usercode to usercode SCROOGE, which has CALC as its password. The remaining two programs that the job initiates are then run under usercode SCROOGE, even though the object code file for the last one resides under usercode CRATCHIT.

The usercode of the job can also be set by specifying the USERCODE task attribute as a job attribute, and the usercode for an individual task can be set by specifying the USERCODE for that task.