Page 1 of 1

Job Control Error

Posted: Wed Oct 10, 2007 7:33 am
by sri75
HI,

I have routine to send an email when job gets aborted.
It is working fine so far.Now I wanted to reset the job after sending mail.I added few lines to that routine .I am getting following error

.AfterJob (DSAttachJob): Job control error (-12)
(DSOpenJob) Invalid job name '1'

I added
hJob = DSAttachJob(DSJ.ME, DSJ.ERRWARN)

hJob = DSPrepareJob(hJob)
these 2 lines to reset the job

this is the routine

Code: Select all

$INCLUDE DSINCLUDE JOBCONTROL.H 


ErrorCode = 0 ;* set this to non-zero to stop the stage/job 

JobHandle = DSJ.ME 
JobName = DSGetJobInfo(JobHandle,DSJ.JOBNAME) 

call DSLogInfo("Job Name":JobName, "DSSendMail");  
J1stat = DSGetJobInfo(DSJ.ME,DSJ.JOBINTERIMSTATUS);


Jobstat = DSGetJobInfo(DSJ.ME,DSJ.JOBSTATUS);


StartTimestamp = DSGetJobInfo(JobHandle,DSJ.JOBSTARTTIMESTAMP);
EndTimestamp = DSGetJobInfo(JobHandle,DSJ.JOBLASTTIMESTAMP);

SummaryArray = DSGetLogSummary (JobHandle, DSJ.LOGANY,StartTimestamp , EndTimestamp , 50)

hJob = DSAttachJob(DSJ.ME, DSJ.ERRWARN)


If  J1stat =2 or J1stat=3 Then

hJob = DSPrepareJob(hJob)

Line="Failed or completed with warnings" 
message=''
message=InputArg:"\nBody:"
message=message :JobName:J1stat:Line :"\n" :JobHandle :StartTimestamp : "\n" : SummaryArray

Reply = DSSendMail(message) 

End
Can you please help me in finding the problem

Thanks
Sri

Posted: Wed Oct 10, 2007 9:52 am
by Ronetlds
Did you try using JobHandle instead of DSJ.ME as jobname in the DSAttachJob function?

Posted: Wed Oct 10, 2007 11:18 am
by ds_developer
Read the help file about DSAttachJob - you should be using the jobname, not DSJ.ME or JobHandle. One thing the help file says is
A job cannot attach to itself.

which is what I believe you are currently doing.

John

Posted: Wed Oct 10, 2007 4:09 pm
by ray.wurlod
After obtaining the job name check that that value is not DSJE.BADHANDLE (which means that the attach failed).

Posted: Wed Oct 10, 2007 7:12 pm
by chulett
No, I think John has it right - don't attach to yourself. However, you have a bigger problem. After Job is really after the job, it hasn't actually finished yet, which means you can't "reset" it because it is still running.

This needs to happen outside the job in your job control, and I personally never 'auto reset' immediately after a job aborts, you lose information that way. I check and reset a job before it is run as part of the start-up processing.

Posted: Thu Oct 11, 2007 6:23 am
by sri75
Hello to All,


Thanks for your suggestions and help.

I tried to use JobName and also JobHandle, simply job hangs

Thanks
Sri

Posted: Thu Oct 11, 2007 6:26 am
by chulett
Because, as previously noted, you cannot attach to 'yourself'.