Job control routine

You can also implement a job sequence by specifying a job control routine on the Job control page of the Job Properties window.

A job control routine provides the means of controlling other jobs from the current job. A set of one or more jobs can be validated, run, reset, stopped, and scheduled in much the same way as the current job can be. You can, if required, set up a job whose only function is to control a set of other jobs. The graphical job sequence editor produces a job control routine when you compile a job sequence (you can view this in the Job Sequence properties), but you can set up you own control job by entering your own routine on the Job control page of the Job Properties dialog box. The routine uses a set of BASIC functions provided for the purpose. The Job control page provides a basic editor to let you construct a job control routine using the functions.

The toolbar contains buttons for cutting, copying, pasting, and formatting code, and for activating Find (and Replace). The main part of this page consists of a multiline text box with scroll bars. The Add Job button provides a drop-down list box of all the server and parallel jobs in the current project. When you select a compiled job from the list and click Add, the Job Run Options dialog box appears, allowing you to specify any parameters or run-time limits to apply when the selected job is run. The job will also be added to the list of dependencies. When you click OK in the Job Run Options dialog box, you return to theJob control page, where you will find that IBM® InfoSphere® DataStage® has added job control code for the selected job. The code sets any required job parameters or limits, runs the job, waits for it to finish, then tests for success.

Alternatively, you can type your routine directly into the text box on the Job control page, specifying jobs, parameters, and any runtime limits directly in the code.

The following is an example of a job control routine. It schedules two jobs, waits for them to finish running, tests their status, and then schedules another one. After the third job has finished, the routine gets its finishing status.


* get a handle for the first job
Hjob1 = DSAttachJob("DailyJob1",DSJ.ERRFATAL)
* set the job's parameters
Dummy = DSSetParam(Hjob1,"Param1","Value1")
* run the first job
Dummy = DSRunJob(Hjob1,DSJ.RUNNORMAL)
* get a handle for the second job
Hjob2 = DSAttachJob("DailyJob2",DSJ.ERRFATAL)
* set the job's parameters
Dummy = DSSetParam(Hjob2,"Param2","Value2")
* run the second job
Dummy = DSRunJob(Hjob2,DSJ.RUNNORMAL)
* Now wait for both jobs to finish before scheduling the third job
Dummy = DSWaitForJob(Hjob1)
Dummy = DSWaitForJob(Hjob2)
* Test the status of the first job (failure causes routine to exit)
J1stat = DSGetJobInfo(Hjob1, DSJ.JOBSTATUS)
If J1stat = DSJS.RUNFAILED
   Then Call DSLogFatal("Job DailyJob1 failed","JobControl")
End
* Test the status of the second job (failure causes routine to
* exit)
J2stat = DSGetJobInfo(Hjob2, DSJ.JOBSTATUS)
If J2stat = DSJS.RUNFAILED
   Then Call DSLogFatal("Job DailyJob2 failed","JobControl")
End

* Now get a handle for the third job
Hjob3 = DSAttachJob("DailyJob3",DSJ.ERRFATAL)
* and run it
Dummy = DSRunJob(Hjob3,DSJ.RUNNORMAL)
* then wait for it to finish
Dummy = DSWaitForJob(Hjob3)
* Finally, get the finishing status for the third job and test it
J3stat = DSGetJobInfo(Hjob3, DSJ.JOBSTATUS)
If J3stat = DSJS.RUNFAILED
   Then Call DSLogFatal("Job DailyJob3 failed","JobControl")
End

Possible status conditions returned for a job are as follows.

A job that is in progress is identified by:

  • DSJS.RUNNING - Job running; this is the only status that means the job is actually running.

Jobs that are not running might have the following statuses:

  • DSJS.RUNOK - Job finished a normal run with no warnings.
  • DSJS.RUNWARN - Job finished a normal run with warnings.
  • DSJS.RUNFAILED - Job finished a normal run with a fatal error.
  • DSJS.VALOK - Job finished a validation run with no warnings.
  • DSJS.VALWARN - Job finished a validation run with warnings.
  • DSJS.VALFAILED - Job failed a validation run.
  • DSJS.RESET - Job finished a reset run.
  • DSJS.STOPPED - Job was stopped by operator intervention (cannot tell run type).

    If a job has an active select list, but then calls another job, the second job will effectively wipe out the select list.