Page 1 of 1

Job Control Error

Posted: Thu Dec 11, 2008 6:24 am
by mdbatra
Hi ,

I am running a job control as follows(for reading job names from a file & get the corresponding information in variables)

OPENSEQ 'C:\Project_Files\JobName.txt' TO OUTPUT ELSE ABORT

for i=1 to 18

READSEQ A FROM OUTPUT ELSE ABORT

inivar=DSAttachJob(A,DSJ.ERRWARN)
midvar=DSGetJobInfo(inivar,DSJ.JOBNAME)
finvar=DSGetJobInfo(inivar,DSJ.STAGELIST)



* Setup M_Ashish_Job_3, run it, wait for it to finish, and test for success
hJob1 = DSAttachJob("M_Ashish_Job_3", DSJ.ERRFATAL)
If NOT(hJob1) Then
Call DSLogFatal("Job Attach Failed: M_Ashish_Job_3", "JobControl")
Abort
End
ErrCode = DSSetParam(hJob1, "Job_Name",midvar)
ErrCode = DSSetParam(hJob1, "Stg_name",finvar)
ErrCode = DSSetDisableProjectHandler(hJob1, @FALSE)
ErrCode = DSSetDisableJobHandler(hJob1, @FALSE)
ErrCode = DSRunJob(hJob1, DSJ.RUNNORMAL)
ErrCode = DSWaitForJob(hJob1)
Status = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED Then
* Fatal Error - No Return
Call DSLogFatal("Job Failed: M_Ashish_Job_3", "JobControl")
End

NEXT i

CLOSESEQ OUTPUT

When i run this, the control goes on indefinite hold. So,
1) What can be the cause ? Any syntax problem or some additional thing to do?
2) How to stop a job which went on indefinite hold ?

Posted: Thu Dec 11, 2008 7:50 am
by mdbatra
i have searched the forum for ReadSeq & tried umptine times but still problem persists.

May i know the syntax for simply reading a single column of a file & file which has just 1 column , sequetially & then passing the column name to the variables.
Just want to cross-check what i have given above is fine or not!

Posted: Thu Dec 11, 2008 8:46 am
by Sainath.Srinivasan
Try logging messages to see where it goes into abyss

Posted: Thu Dec 11, 2008 2:25 pm
by ray.wurlod
Try detaching hJob1 when you're done with that job, so that you don't get a job locked situation.

Why are you executing the same job 18 times?

Posted: Thu Dec 11, 2008 10:57 pm
by mdbatra
ray.wurlod wrote:Try detaching hJob1 when you're done with that job, so that you don't get a job locked situation.

Why are you executing the same job 18 times? ...

The file i am reading has 18 enteries.
While initially learning for reading a file sequentially, i saw that i need to loop it for the number of enteries to be read.
I fear if this is the problem :(

If yes, please provide assistance !

Posted: Thu Dec 11, 2008 11:15 pm
by ray.wurlod
Write out IN ENGLISH what you want to do.

It is not clear from your code (a) because it is not indented (use Code tags) and (b) because you don't appear to have any clear idea of precisely what you want to accomplish.

Posted: Thu Dec 11, 2008 11:31 pm
by mdbatra
I have names of all the jobs in a file. In a job control, i need to read the name of the job from file, evaluate some information using DS functions & pass them to the parameters defined for the 'Controlled Job' .
& this needs to be repeated for all the jobs.

Posted: Fri Dec 12, 2008 3:49 am
by ray.wurlod
If I were the programmer I would not be at all happy with a specification like "extract some information". What I'm trying to get you to do is to create a proper technical specification against which cogent advice as to coding may be given.

Posted: Fri Dec 12, 2008 3:50 am
by LenGreenwood
Just as an aside, don't use the ABORT statement in job control. Use:

Code: Select all

Call DSLogFatal("Some meaningful reason for stopping", "Some context")
instead. That way the controlling job will stop gracefully, and log a message saying why it stopped. A Call to DSLogFatal never returns. So in the lines in your example that have:
If NOT(hJob1) Then
Call DSLogFatal("Job Attach Failed: M_Ashish_Job_3", "JobControl")
Abort
End
That particular Abort will never be executed. But the ABORTs higher up may well be, if the file does not exist or has more than 18 lines, for example.

Posted: Fri Dec 12, 2008 3:53 am
by ray.wurlod
Len, that's the code generated by DataStage. Try it some time - create a job control routine "the old way". I agree with you, even so. Indeed, what ever happened to "you must treat the handle variable as opaque"?

Posted: Fri Dec 12, 2008 6:31 am
by LenGreenwood
Agreed that's generated code, and it should never have inserted that Abort, because it makes it look as if that's the way the job gets stopped. Don't know why it got left in - the subsequent (also generated) call to DSLogFatal in the first post makes it clearer. Still need to emphasize that one should not call naked Aborts within job control.

Posted: Sat Dec 13, 2008 11:18 am
by mdbatra
LenGreenwood wrote:Just as an aside, don't use the ABORT statement in job control. Use:

Code: Select all

Call DSLogFatal("Some meaningful reason for stopping", "Some context")
instead. That way the controlling job will stop gracefully, and log a message saying why it stopped. A Call to DSLogFatal never returns. So in the lines in your example that have:
If NOT(hJob1) Then
Call DSLogFatal("Job Attach Failed: M_Ashish_Job_3", "JobControl")
Abort
End
That particular Abort will never be executed. But the ABORTs higher up may well be, if the file does not exist or has more than 18 lines, for example.
Thanks Len ! It worked. Not just job working perfectly , it recovered from falling into indefinite hold also which was happening earlier.