Job within routine

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
peterh
Participant
Posts: 9
Joined: Thu Feb 13, 2003 2:34 am

Job within routine

Post by peterh »

Hello,

I would like to know if I can attach/run job within server routine.

Thanks in advance for any advice

Peter
MAT
Participant
Posts: 65
Joined: Wed Mar 05, 2003 8:44 am
Location: Montréal, Canada

Post by MAT »

Sure you can
Include the following at the top of your routine (jobcontrol library) :
$INCLUDE DSINCLUDE JOBCONTROL.H

And use the following functions:
* Attach
hjob = DSAttachJob(JobName,DSJ.ERRFATAL)
* Run
ErrCode = DSRunJob(hjob, DSJ.RUNNORMAL)
* Wait for termination
ErrCode = DSWaitForJob(hjob)
* Detach
ErrCode = DSDetachJob(hjob)

I suggest you check your status after important steps. Check the job handle:
If NOT(hjob) Then
* Error handling
End

Regards

MAT
peterh
Participant
Posts: 9
Joined: Thu Feb 13, 2003 2:34 am

Post by peterh »

Thanks, MAT. I did not check RunJob utility first...
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

A shortcut is to create a batch job, choose the server job from the combo box and add it to the batch job code. You can then cut and paste this code to your routine. Gives you all the commands such as attaching, setting job parameters and checking the return value. There are also run job routine examples in your sdk folder under routines.

Vincent McBurney
Data Integration Services
www.intramatix.com
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Executing a job from a Routine that is a Transform Function is, as a general rule, a Bad Idea. The job will have to be executed (started, run, finish) for every row processed in the job from which the Transform Function is called. That job will not be fast!
But, if that's what you want to do, DataStage will permit it, just don't come back complaining about performance.

As an aside, the documentation for DSAttachJob() function states that one should not assume that the job handle variable returned by the function is an integer. On this basis, the test Not(hJob) is invalid. Better is to perform some innocuous task then test whether the handle was valid. For example:
hJob = DSAttachJob("MyJob", DSJ.ERRNONE)
JobName = DSGetJobInfo(hJob, DSJ.JOBNAME)
If JobName = DSJE.BADHANDLE
Then
GoSub FailedToAttach
End


Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518
peterh
Participant
Posts: 9
Joined: Thu Feb 13, 2003 2:34 am

Post by peterh »

Thanks for responses. I realize that job in routine will be very slow with row processing. I would like to use it by different way. I'm going to design very complex sequencer with several jobs and lot of OS commands. Since I would like to have some overall statistics for jobs monitoring (in the db table) I'm going to pass these information over simple routine/job in the sequencer. These routine will be called on the start of sequencer, end and in case of errors.

Any other idea?

Thanks a lot

Peter
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

Adding parallel execution of jobs will be tricky. If you just do run jobs followed by DSWaitforJob then you will only get one job running at any one time. To get parallel jobs running you will need extra fields into your table to indicate which jobs run in parallel and when the parallel streams need to join up. Then you need to avoid the DSWaitforJob command for those parallel jobs and use another routine to loop and trap when these jobs finish.

You may find it far easier to order your jobs within a Sequence job and write the results out to a table.

It is not difficult to get jobs and sequence jobs to write statistics out to a table as they finish. You can use before job/after job routines, or sequence stages, or run the jobs from a central run job routine.

Vincent McBurney
Data Integration Services
www.intramatix.com
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Try not to "design very complex sequencer".
Try, instead, to design something that is easy to maintain into the future.
A Job Activity can start another job sequencer, rather than a server job, so it's possible to build a hierarchy of control.


Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518
Post Reply