Error handling in server routines

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
DSRajesh
Premium Member
Premium Member
Posts: 297
Joined: Mon Feb 05, 2007 10:37 pm

Error handling in server routines

Post by DSRajesh »

Dear All,

I am using the below code for job statistics in server routine


If the job name which we are not passing is invalid or not avaialable then how to handle the error which occur with the routine.

Can any one suggest me how to handle this case with failing the routine.
RD
DSRajesh
Premium Member
Premium Member
Posts: 297
Joined: Mon Feb 05, 2007 10:37 pm

Post by DSRajesh »

sorry missed out to give the code which i am using

below is the code

Code: Select all

SINCLUDE JOBCONTROL.H 

      Equate RoutineName To 'GetJobInfo' 
 
            JobHandle = '' 

          Int = DSGetJobInfo(JobHandle, DSJ.JOBSTATUS) 

         Begin Case 
            Case Int = DSJS.RUNFAILED 
               Info = 'Aborted' 
            Case Int = DSJS.RUNOK 
               Info = 'Completed' 
            Case Int = DSJS.RUNWARN 
               Info = 'Warning' 
            Case Int = DSJS.RUNNING 
               Count = DSGetJobInfo(JobHandle, DSJ.DSJ.JOBEOTCOUNT) 
               Info = 'Running' : 'Count of Rows Complete' : Count 
            Case @True                   ; * all other values 
               Info = 'Not Defined' 
         End Case 

         StartTime = DSGetJobInfo(JobHandle, DSJ.JOBSTARTTIMESTAMP) 
         EndTime = DSGetJobInfo(JobHandle, DSJ.JO
RD
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

the routine as posted won't work correctly, since nowhere do you assign "JobHandle" - this should be done with DSJ.ME or DSAttachJob().

What is the variable you are passing in as your job parameter?
DSRajesh
Premium Member
Premium Member
Posts: 297
Joined: Mon Feb 05, 2007 10:37 pm

Post by DSRajesh »

sorry,below is the code:

Code: Select all

$INCLUDE DSINCLUDE JOBCONTROL.H 

      Equate RoutineName To 'GetJobInfo' 

      JobHandle = '' 

      JobHandle = DSAttachJob(JobName, DSJ.ERRNONE) 

      Int = DSGetJobInfo(JobHandle, DSJ.JOBSTATUS) 

         Begin Case 
            Case Int = DSJS.RUNFAILED 
               Job_Status = 'Aborted' 
            Case Int = DSJS.RUNOK 
               Job_Status = 'Finished' 
            Case Int = DSJS.RUNWARN 
               Job_Status = 'Finished with  Warnings' 
            Case @True; * all other values 
               Info = 'UnKnown' 
         End Case 

         StartTime = DSGetJobInfo(JobHandle, DSJ.JOBSTARTTIMESTAMP) 
         EndTime = DSGetJobInfo(JobHandle, DSJ.JOBLASTTIMESTAMP)         

	Ans = Job_Status : '|' : StartTime : '|' : EndTime


The input variable which i am using is JobName
RD
DSRajesh
Premium Member
Premium Member
Posts: 297
Joined: Mon Feb 05, 2007 10:37 pm

Post by DSRajesh »

Arndw,

Could you please suggest me on this.
RD
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

It is important not to try to DSAttachJob() your own job, that can cause a hang situation, so you should add:

Code: Select all

IF (JobName <> DSGetJobInfo(DSJ.ME,DSJ.JOBNAME) )
THEN
 ... your code
END
ELSE 
   Job_Status = 'Running'
END
Note you forget DSJS.RUNNING in your list.

Generally if the DSAttachJob() call fails, the return value will be 0. While this is not explicitly documented, it does work that way and that is what I use to determine if a DSAttachJob() call was succesfull or not.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Make this the first option within your CASE construct.

Code: Select all

Case Int = DSJE.BADHANDLE
   Job_Status = 'Error'
   Call DSLogWarn("Unable to attach job " : DQuote(JobName) : ".", RoutineName)
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 »

Good one, I hadn't used DSJE.BADHANDLE. You still need to ensure that you don't inadvertantly try to do a DSAttachJob() to your own job but that CASE option is more elegant than an if-then-else construct.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Basically, you need to decide what needs to happen when a 'failure' is detected. Do you pass back something as the 'Ans'wer that will indicate a problem that is then handled by the caller or will you abort the routine itself?
-craig

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