Reseting and Running a Job from 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
anupam
Participant
Posts: 172
Joined: Fri Apr 04, 2003 10:51 pm
Location: India

Reseting and Running a Job from Routine

Post by anupam »

Here is the piece of code

Code: Select all

$INCLUDE DSINCLUDE JOBCONTROL.H



      JobName=Trim(Arg1)

      JobHandle = DSAttachJob (JobName, DSJ.ERRWARN)


      Status = DSGetJobInfo (JobHandle, DSJ.JOBSTATUS)

      If Status= DSJS.RUNFAILED or Status= DSJS.CRASHED

      THEN
         ErrCode=DSRunJob(JobHandle , DSJ.RUNRESET )
         ErrCode=DSWaitForJob(JobHandle)
      END

      ErrCode=DSRunJob(JobHandle , DSJ.RUNNORMAL )
      ErrCode=DSWaitForJob(JobHandle)



      ErrCode=DSDetachJob(JobHandle)
      Ans=ErrCode

When the job is in runnable state, this routines works fine and run it. When the job is not in runnable state, it resets it but do not run the job.

My requirement is that it should reset as well run the job if the job is in not runnable state.

Pls advice where I am missing
----------------
Rgds,
Anupam
----------------
The future is not something we enter. The future is something we create.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Don't see anything obviously wrong. :?

Look into using DSPrepareJob instead of all that IF-THEN checking though, one stop shopping.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

This is a tricky issue, which I think leads back to how the JobHandle is returned on resetting the job. I would recommend adding a line

Code: Select all

JobHandle=DSPrepareJob(JobHandle)
as Craig suggested to replace your if-then-else construct. Note that DSPrepareJob() returns a different JobHandle when it resets the job, thus the assignment statement.

Code: Select all

$INCLUDE DSINCLUDE JOBCONTROL.H 
   JobName   = Trim(Arg1) 
   JobHandle = DSAttachJob(JobName, DSJ.ERRWARN) 
   Status    = DSGetJobInfo(JobHandle, DSJ.JOBSTATUS) 
   IF Status = DSJS.RUNFAILED or Status= DSJS.CRASHED THEN JobHandle = DSPrepareJob(JobHandle)
   Dummy     = DSRunJob(JobHandle , DSJ.RUNNORMAL ) 
   Dummy     = DSWaitForJob(JobHandle) 
   Ans       = DSGetJobInfo(JobHandle, DSJ.JOBSTATUS) 
   Dummy     = DSDetachJob(JobHandle) 
[/code]
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ah... was wondering about the job handle. Still better to leverage DSPrepareJob IMHO.

(hey, it was 6AM and the coffee hadn't kicked in yet) :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply