Page 1 of 2

How to abort a job in Afterjob sub routine

Posted: Mon Feb 05, 2007 1:06 am
by nvuradi
Hi All i have a requirement in which i have to abort the job
if the reject link count is greater than 0 i.e i have to abort the job if the job has some reject records.

this i have to take care in the after job sub routine ....for this i am using DSStopJob as..

if intNoRecRejected > 0 Then

iErrorCode=DSStopJob(DSJ.ME)
Call DSLogInfo("Stop error Code ":iErrorCode,DSJ.ME)

END

but it is returning the error code as -1.

is there any other way to abort the job for the above mentioned condition?

thanks,
Naru

Re: How to abort a job in Afterjob sub routine

Posted: Mon Feb 05, 2007 1:16 am
by sud
nvuradi wrote:...

is there any other way to abort the job for the above mentioned condition?
The question is where are you catching the rejections ? If from a transformer, the transformer has this option in the 'constraints'. Check it out.

Posted: Mon Feb 05, 2007 1:49 am
by ArndW
I'm not on a system where I have DS installed, but I seem to recall that DSStopJob() function can only be used from the controlling job. If you need to abort a job from the job itself you need to call DSLogFatal().
Better is to set the number of links output down a link to 0 so that the job aborts in the correct place and not after completing all processing.

Posted: Mon Feb 05, 2007 2:53 am
by kumar_s
Or Call 'Abort' in the routine. Or use 'Abort after n row' option for the reject link.

Posted: Mon Feb 05, 2007 3:13 am
by nvuradi
kumar_s wrote:Or Call 'Abort' in the routine. Or use 'Abort after n row' option for the reject link. ...
hi i have to abort the job in Afterjob sub routine .....
can this be done??....

how can i use this ???..
Or use 'Abort after n row' option for the reject link. ...

Posted: Mon Feb 05, 2007 3:15 am
by nvuradi
nvuradi wrote:
kumar_s wrote:Or Call 'Abort' in the routine. Or use 'Abort after n row' option for the reject link. ...
hi i have to abort the job in Afterjob sub routine .....
can this be done??....

how can i use this ???..
Or use 'Abort after n row' option for the reject link. ...
one more thing i dont have a transformer in my Job... :(

Posted: Mon Feb 05, 2007 3:35 am
by ArndW
If you have no transform stage and don't want to put one in, then you should use the reject link as your abort trigger as mentioned twice above.

Posted: Mon Feb 05, 2007 5:28 am
by nvuradi
ArndW wrote:If you have no transform stage and don't want to put one in, then you should use the reject link as your abort trigger as mentioned twice above. ...
using ErrorCode = 1 will work???

Posted: Mon Feb 05, 2007 5:31 am
by ArndW
You have a reject link somewhere in your job as you specified in your original post. From which stage is this link coming from? Also, look at "Linking" in the DataStage Designer Guide starting at page 4-14.

Posted: Mon Feb 05, 2007 5:52 am
by nvuradi
ArndW wrote:You have a reject link somewhere in your job as you specified in your original post. From which stage is this link coming from? Also, look at "Linking" in the DataStage Designer Guide starting at page 4-14.
this link is coming from an Oracle insert stage.

Posted: Mon Feb 05, 2007 7:13 am
by ArndW
I see - I saw that this was posted in the Server forum and that changes things. Put your reject link to a transform stage, then onto to whatever file output stage (or a PEEK stage) you want. In the Transform output details tell the job to abort after 1 rows down that link.

Posted: Mon Feb 05, 2007 7:29 am
by DSguru2B
nvuradi wrote: one more thing i dont have a transformer in my Job... :(
Get one. Abort "after n rows" is a functionality present inside the px transformer.

Posted: Mon Feb 05, 2007 1:19 pm
by ray.wurlod
nvuradi wrote:i have to abort the job in Afterjob sub routine .....
can this be done??....

how can i use this ???..
1. Why? All rows that have been sent to the database have been committed by the time an after job subroutine is being executed. Aborting a job in an after job subroutine makes as much sense as buying a lottery ticket after the lottery has been drawn.

2. Yes it can be done. Make a call to DSLogFatal() within the after job subroutine.

3. Because of my point #1, this question is moot.

Posted: Mon Feb 05, 2007 9:08 pm
by nvuradi
ray.wurlod wrote:[quote="nvuradi]i have to abort the job in Afterjob sub routine .....
can this be done??....

how can i use this ???..
1. Why? All rows that have been sent to the database have been com ...[/quote]

i have to abort the job if table already has a record.......
still unable to solve it :oops:

Posted: Tue Feb 06, 2007 1:42 am
by ray.wurlod
Your requirement to abort the job is unnecessary. A far better design would be to check that the row (or key value) in question does not already exit in the target table before attempting to insert it. Any row that does already exist can be captured in a different ("reject"?) stream and processed accordingly. There is still no need to abort the job. Maintain control at all time.