Routine Error Code

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
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

Routine Error Code

Post by parvathi »

Hi all,
In a server routine i am running a server job.
When the server job does not complete successfully then the routine has to return a non zero routine code.

I am calling this routine in after job sub routine in a server job.

When I start i set the ERROr code =0.

Is the routine code and ERROCode the same?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:? Wait... you wrote a routine that runs a job and you run that job in the 'After Job' area of another job? Why would you want to do that? Seems like a Sequence job would be more appropriate to run the two jobs in a serial fashion...

If you pursue this course, then yes - you'll need to detect errors in the job the routine runs and then set the error code to a non-zero value if you want the problem to be noticed.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Stick to the standards. Use a job sequence.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

What kind of routine - transform function or before/after subroutine?

Where (and how) are you invoking this routine?

Can you post the source code of the routine, so we can hopefully get a clearer idea of what you are trying to accomplish? Wrap the code in "Code" tags (select the source code, and click the Code button above).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

Post by parvathi »

chulett wrote::? Wait... you wrote a routine that runs a job and you run that job in the 'After Job' area of another job? .
Sorry it was

I am calling a routine in a job after the job runs .

what the routine does is it takes info from the job i am running and then it runs another job in the routine .

What i am supposed to do is if the job that i am running in the routine fails
then routne has to return a non zero routine code
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

Post by parvathi »

ray.wurlod wrote:What kind of routine - transform function or before/after subroutine?

Where (and how) are you invoking this routine?

...
It is a before/after subroutine

i am invoking the routine in a after job routine
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Right. We got that. As noted, you simply need to return a non-zero error code when the job fails. Post your code.
-craig

"You can never have too many knives" -- Logan Nine Fingers
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

Post by parvathi »

the code that i have used is

v_writeJobStatus = DSGetJobInfo(v_writeJobHandle, DSJ.JOBSTATUS)
If v_writeJobStatus <> DSJS.RUNOK Then
ErrorCode =3
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

What will happen is that if the last run of the job you are checking has warnings or error or hasn't run since compilation your current job will abort.
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

Post by parvathi »

I have seen that when the job has warnings the routine returns wwit error number 3 tha i have specified.

I this the correct coding?
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

I'm confused as to your goal. The code does what you ask of it; but we don't know if it makes sense to do so.

Personally I would use a sequence to do this and not make one job abort depending upon some status in another.
narasimha
Charter Member
Charter Member
Posts: 1236
Joined: Fri Oct 22, 2004 8:59 am
Location: Staten Island, NY

Post by narasimha »

parvathi,

Is there any specific reason why you want to go this route.
As suggested by others, Job sequence is the way to go.
Narasimha Kade

Finding answers is simple, all you need to do is come up with the correct questions.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Re: Routine Error Code

Post by ray.wurlod »

parvathi wrote:Hi all,
In a server routine i am running a server job.
When the server job does not complete successfully then the routine has to return a non zero routine code.

I am calling this routine in after job sub routine in a server job.

When I start i set the ERROr code =0.

Is the routine code and ERROCode the same?
That looks like a complete specification.

Code: Select all

SUBROUTINE MyRoutine(InputArg, ErrorCode)
$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF

ErrorCode = 0 ; * set to non-zero value to abort job

hJob = DSAttachJob(....)
JobName = DSGetJobInfo(hJob, DSJ.JOBNAME)
If JobName = DSJE.BADHANDLE
Then

   Call DSLogWarn("Failed to attach job.", "MyRoutine")
   ErrorCode = DSJE.BADHANDLE

End
Else

   SubmitStatus = DSRunJob(hJob, DSJ.RUNNORMAL)
   WaitStatus   = DSWaitForJob(hJob)
   ExitStatus   = DSGetJobInfo(hJob, DSJ.JOBSTATUS)
   DetachStatus = DSDetachJob(hJob)

   ErrorCode = (ExitStatus <> DSJS.RUNOK And ExitStatus <> DSJS.RUNWARN)

End

RETURN
However, running a job from a before/after subroutine is a really unusual thing to do. Have you thought this through? A job sequence gives you exactly the same functionality, without needing to write - and therefore to maintain - any code.

But perhaps that's not what you wanted to do. Maybe all you're seeking is a way to detect, in an after-job subroutine, the exit status of the job in which the after-job subroutine is invoked.

Code: Select all

SUBROUTINE CatchErrorStatus(InputArg, ErrorCode)
$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF

ErrorCode = 0 ; * set to non-zero value to abort job

* Use interim status; job itself is still "RUNNING".
ExitStatus = DSGetJobInfo(DSJ.ME, DSJ.INTERIMSTATUS)

ErrorCode = (ExitStatus <> DSJS.RUNOK And ExitStatus <> DSJS.RUNWARN)

RETURN
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