Can we get only job status???

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

ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

DSJS.JOBSTATUS does not exist. The -1 you're getting is an error code meaning "bad handle", that is you have not attached the job to the current process. DSJ.JOBSTATUS is a DataStage constant, it is one of the possible arguments to DSGetJobInfo().

You can not use this in a job design to achieve your aim. Nor can you use a DataStage macro (DSJobStatus) or DSGetJobInfo with DSJ.ME as the first argument, since these will always report the currently-executing job.

You need to create a routine (type is "transform function") which, given a name, returns that job's status. Since the current job is always "running" you can omit this from consideration.

Code: Select all

FUNCTION GetJobStatus(JobName)
$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF

hJob = DSAttachJob((JobName), DSJ.ERRNONE)
JobName = DSGetJobInfo(hJob, DSJ.JOBNAME)
If JobName Matches "'-'1N0N"
Then

   * Unable to attach job
   Ans = -1

End
Else

   * Attached job, now ensure it's not this job
   If JobName = DSGetJobInfo(DSJ.ME, DSJ.JOBNAME)
   Then
      Ans = 0
   End
   Else
      * Otherwise get the job's status
      Ans = DSGetJobInfo(hJob, DSJ.JOBSTATUS)
   End

   ErrCode = DSDetachJob(hJob)  ; * this is a vital step!

End

RETURN(Ans)
If required, decode the numeric values listed earlier. When selecting names from the DS_JOBS table, make sure you only process keys whose names begin with an alphabetic character.
Last edited by ray.wurlod on Mon Dec 05, 2005 7:55 pm, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ICE
Participant
Posts: 249
Joined: Tue Oct 25, 2005 12:15 am

Post by ICE »

Dear Ray,

Thank u so much 4 ur help.
It's working now.


Thanks in advance,

ICE
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

Hi,

When iam passing the JobName as Trim(JobName), the job is aborting. When iam passing the JobName as JobName,The job is running but it gives the status as -1.

Any clues please.

Thanks.

ray.wurlod wrote:DSJS.JOBSTATUS does not exist. The -1 you're getting is an error code meaning "bad handle", that is you have not attached the job to the current process. DSJ.JOBSTATUS is a DataStage constant, it is one of the possible arguments to DSGetJobInfo().

You can not use this in a job design to achieve your aim. Nor can you use a DataStage macro (DSJobStatus) or DSGetJobInfo with DSJ.ME as the first argument, since these will always report the currently-executing job.

You need to create a routine (type is "transform function") which, given a name, returns that job's status. Since the current job is always "running" you can omit this from consideration.

Code: Select all

FUNCTION GetJobStatus(JobName)
$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF

hJob = DSAttachJob((JobName), DSJ.ERRNONE)
JobName = DSGetJobInfo(hJob)
If JobName Matches "'-'1N0N"
Then

   * Unable to attach job
   Ans = -1

End
Else

   * Attached job, now ensure it's not this job
   If JobName = DSGetJobInfo(DSJ.ME, DSJ.JOBNAME)
   Then
      Ans = 0
   End
   Else
      * Otherwise get the job's status
      Ans = DSGetJobInfo(hJob, DSJ.JOBSTATUS)
   End

   ErrCode = DSDetachJob(hJob)  ; * this is a vital step!

End

RETURN(Ans)
If required, decode the numeric values listed earlier. When selecting names from the DS_JOBS table, make sure you only process keys whose names begin with an alphabetic character.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Look at the code. It returns -1 if the job can not be attached - that is, if the job name can not be found. The routine works as documented. The problem is somewhere with your job name. Job names must not only be correctly spelled they must also be correctly cased.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

In the above code

hJob = DSAttachJob((JobName), DSJ.ERRNONE)
JobName = DSGetJobInfo(hJob)

Is this the correct

or

JobName = DSGetJobInfo(hJob,DSJ.JOBNAME)

Thanks,

ray.wurlod wrote:Look at the code. It returns -1 if the job can not be attached - that is, if the job name can not be found. The routine works as documented. The problem is somewhere with your job name. Job names must not only be correctly spelled they must also be correctly cased.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Good catch. I've edited the original code.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

I am using the UV stage as source with SELECT NAME FROM DS_JOBS WHERE NAME NOT LIKE '%\%'.I have written a TransformFunction with the above code.I am passing the NAME as parameter to the Function.It works fine,but takes lot time.(It has only 15 names, it took 25 min).

what could be the reason?.

Thanks.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The job might've gotten hung up trying to process itself.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

There is a bug in 7.x which causes a process that attempts a DSAttachJob() to itself will "hang" on a semaphore for 30 minutes before returning an error. I've changed all my code to check for JobName = DSGetJobInfo(DSJ.ME,DSJ.JOBNAME) before attempting a DSAttachJob(). This might have been your problem.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I agree. I've seen the same issue in 6.x from what I recall as well.
-craig

"You can never have too many knives" -- Logan Nine Fingers
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

Now its working fine after changing the SQL. Iam not taking the current job name.

with the above code, when i compile the routine it gives one warning message:

WARNING: Assignment to variable JobName on line 7 will modify an input argument. If input link column variables are used as arguments to this routine then DataStage runtime may fail.
Compiled with no errors

Shall i change the parameter name?. Or is that OK.

Thanks.
ray.wurlod wrote:The job might've gotten hung up trying to process itself.
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

Hi Arnd,
As per your suggession i have changed the code to

Function GetStatus(JobName)
$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF


If JobName = DSGetJobInfo(DSJ.ME, DSJ.JOBNAME) Then
End
Else
hJob = DSAttachJob((JobName), DSJ.ERRNONE)
JName = DSGetJobInfo(hJob, DSJ.JOBNAME)
End

If JName Matches "'-'1N0N"
Then

* Unable to attach job
Ans = -1

End
Else

* Attached job, now ensure it's not this job
If JName = DSGetJobInfo(DSJ.ME, DSJ.JOBNAME)
Then
Ans = 0
End
Else
* Otherwise get the job's status
Ans = DSGetJobInfo(hJob, DSJ.JOBSTATUS)
End

ErrCode = DSDetachJob(hJob) ; * this is a vital step!

End
Return(Ans)

and it works fine.

Thanks.
ArndW wrote:There is a bug in 7.x which causes a process that attempts a DSAttachJob() to itself will "hang" on a semaphore for 30 minutes before returning an error. I've changed all my code to check for JobName = DSGetJobInfo(DSJ.ME,DSJ.JOBNAME) before attempting a DSAttachJob(). This might have been your problem.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Instead of
If JobName = DSGetJobInfo(DSJ.ME, DSJ.JOBNAME) Then
End
Else
hJob = DSAttachJob((JobName), DSJ.ERRNONE)
JName = DSGetJobInfo(hJob, DSJ.JOBNAME)
End
I would just use:

Code: Select all

   If JobName = DSGetJobInfo(DSJ.ME, DSJ.JOBNAME) Then hJob = DSJ.ME
   ELSE hJob = DSAttachJob(JobName, DSJ.ERRNONE) 
You don't need the duplicate variable jName and don't need the second query, since you now have a valid job handle.
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

Function GetStatus(JobName)
$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF

If JobName = DSGetJobInfo(DSJ.ME, DSJ.JOBNAME) Then hJob = DSJ.ME

Else hJob = DSAttachJob(JobName,DSJ.ERRNONE)

Ans = DSGetJobInfo(hJob, DSJ.JOBSTATUS)

ErrCode = DSDetachJob(hJob) ; * this is a vital step!

Return(Ans)

Is that enough.

ArndW wrote:Instead of
If JobName = DSGetJobInfo(DSJ.ME, DSJ.JOBNAME) Then
End
Else
hJob = DSAttachJob((JobName), DSJ.ERRNONE)
JName = DSGetJobInfo(hJob, DSJ.JOBNAME)
End
I would just use:

Code: Select all

   If JobName = DSGetJobInfo(DSJ.ME, DSJ.JOBNAME) Then hJob = DSJ.ME
   ELSE hJob = DSAttachJob(JobName, DSJ.ERRNONE) 
You don't need the duplicate variable jName and don't need the second query, since you now have a valid job handle.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Just bypass processing if it's the current job. The status of the current job is always "Running".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply