JobControl

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
Jay
Participant
Posts: 105
Joined: Tue Nov 11, 2003 8:28 pm

JobControl

Post by Jay »

Hi All

I am in a fix...my job control is waiting infinitely while doing DSWaitForJob().

I am reading a text file which has a list of files, which are to be processed by JobXXXX, sequentially.

Here is the code.

*********************************************************************************
* Open file list, pass name of the file as a parameter to the file validation job
*********************************************************************************
Call DSLogInfo("Job info: This is the beginning", "JobControl")
SeqFile = InputFilePath:"/":"IPY004File.txt"
Call DSLogInfo (SeqFile, "IPY004 File list:")
OpenSeq SeqFile to FileVar
Else
GoTo FileErr
End

Loop
ReadSeq FileRec from FileVar
On Error
Call DSLogWarn("Error from ":SeqFile:" status=":status(),"Bonus Lump Sum file validation")
goto errorexit
end
then
FileName = trim(FileRec)
Call DSLogInfo (FileName, "IPY004 File verification in process:")
Call DSLogInfo("About to start file validation", "JobControl")

* Setup JobXXXX, Reset it,If job status = Aborted or Stopped,wait for it to finish
hJob1 = DSAttachJob("JobXXXX", DSJ.ERRFATAL)

If NOT(hJob1) Then
Call DSLogFatal("Job Attach Failed: JobXXXX", "JobControl")
Abort
End

JStat = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
If JStat = 3 or JStat = 96 or JStat = 97 Then
ErrCode = DSRunJob(hJob1, DSJ.RUNRESET)
ErrCode = DSWaitForJob(hJob1)
JStat = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
If JStat <> DSJS.RESET Then
* Fatal Error - No Return
Call DSLogFatal("Job Reset Failed: JobXXXX", "JobControl")
Exit
End
end

Call DSLogInfo("Validation done", "JobControl")

* Setup JobXXXX, run it, wait for it to finish, and test for success
hJob2 = DSAttachJob("JobXXXX", DSJ.ERRFATAL)
hJob2 = DSAttachJob("JobXXXX", DSJ.ERRWARN)
If NOT(hJob2) Then
Call DSLogFatal("Job Attach Failed: JobXXXX", "JobControl")
Abort
End
ErrCode = DSSetParam(hJob2, "StgFilePath", StgFilePath)
ErrCode = DSSetParam(hJob2, "InputFilePath", InputFilePath)
ErrCode = DSSetParam(hJob2, "FileName", FileName)
ErrCode = DSSetParam(hJob2, "StgSchema", StgSchema)
ErrCode = DSSetParam(hJob2, "StgDB", StgDB)
ErrCode = DSSetParam(hJob2, "StgUser", StgUser)
ErrCode = DSSetParam(hJob2, "StgPwd", StgPwd)
ErrCode = DSSetParam(hJob2, "StgHashFilePath", StgHashFilePath)

ErrCode = DSRunJob(hJob2, DSJ.RUNNORMAL)
ErrCode = DSWaitForJob(hJob2)

*********** CONTROL WAITS HERE FOREVER**************

Status = DSGetJobInfo(hJob2, DSJ.JOBSTATUS)
Call DSLogInfo(DSJ.JOBSTATUS, "JobControl")

If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED Then
Call DSLogInfo("Job Failed: ", "JobControl")
End
End Else
Exit ; * at end-of-file
End
until Status() = 1
Repeat

Close FileVar

goto TheEnd

errorexit:
Close FileVar
Call DSLogFatal("IPY004File.txt file error"," Job Aborted, ")

FileErr:
Close FileVar
Call DSLogFatal("IPY004File.txt file not found in the specified directory"," Job Aborted, ")

NothingToProcess:
Close FileVar
Call DSLogWarn ("No IPY004files found to process", "* End of Batch")

TheEnd:
Close FileVar
Call DSLogInfo (DSJ.JOBNAME, "* IPY004 file verification job finished successfully:")

********************************************************
If i comment the DSWaitForJob() line:

Job control works for 1 file (1 row in the IPY004File.txt)

But does not for >1 files. It is processing the first file and not waiting for it to finish before the next iteration.

I think i am missing something....

Thanks for your time,
Jay
Jay
Participant
Posts: 105
Joined: Tue Nov 11, 2003 8:28 pm

Got it

Post by Jay »

Hi All,

Got the sucka fixed....

this batch was opening a text file..IPY004File.txt

Jobxxxx was also opening the same file to get the file name and extract the date for version...here the job was hanging...

now i am passing as parameter the file name for Jobxxxx to extract the date...

sorry for wasting your time
jay
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Jay

You did not waste our time. We just could not see anything wrong with your code. We should of told you that.
Mamu Kim
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Re: JobControl

Post by naren6876 »

Hi Jay,
couls you please pass the full code to process the multple files automatically.
I have multiple files in a sequential file and from the filename, i need to extrac the first 2 characters and based on that i need to call a job specific to that file.

Thanks in advance.
Jay wrote:Hi All

I am in a fix...my job control is waiting infinitely while doing DSWaitForJob().

I am reading a text file which has a list of files, which are to be processed by JobXXXX, sequentially.

Here is the code.

*********************************************************************************
* Open file list, pass name of the file as a parameter to the file validation job
*********************************************************************************
Call DSLogInfo("Job info: This is the beginning", "JobControl")
SeqFile = InputFilePath:"/":"IPY004File.txt"
Call DSLogInfo (SeqFile, "IPY004 File list:")
OpenSeq SeqFile to FileVar
Else
GoTo FileErr
End

Loop
ReadSeq FileRec from FileVar
On Error
Call DSLogWarn("Error from ":SeqFile:" status=":status(),"Bonus Lump Sum file validation")
goto errorexit
end
then
FileName = trim(FileRec)
Call DSLogInfo (FileName, "IPY004 File verification in process:")
Call DSLogInfo("About to start file validation", "JobControl")

* Setup JobXXXX, Reset it,If job status = Aborted or Stopped,wait for it to finish
hJob1 = DSAttachJob("JobXXXX", DSJ.ERRFATAL)

If NOT(hJob1) Then
Call DSLogFatal("Job Attach Failed: JobXXXX", "JobControl")
Abort
End

JStat = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
If JStat = 3 or JStat = 96 or JStat = 97 Then
ErrCode = DSRunJob(hJob1, DSJ.RUNRESET)
ErrCode = DSWaitForJob(hJob1)
JStat = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
If JStat <> DSJS.RESET Then
* Fatal Error - No Return
Call DSLogFatal("Job Reset Failed: JobXXXX", "JobControl")
Exit
End
end

Call DSLogInfo("Validation done", "JobControl")

* Setup JobXXXX, run it, wait for it to finish, and test for success
hJob2 = DSAttachJob("JobXXXX", DSJ.ERRFATAL)
hJob2 = DSAttachJob("JobXXXX", DSJ.ERRWARN)
If NOT(hJob2) Then
Call DSLogFatal("Job Attach Failed: JobXXXX", "JobControl")
Abort
End
ErrCode = DSSetParam(hJob2, "StgFilePath", StgFilePath)
ErrCode = DSSetParam(hJob2, "InputFilePath", InputFilePath)
ErrCode = DSSetParam(hJob2, "FileName", FileName)
ErrCode = DSSetParam(hJob2, "StgSchema", StgSchema)
ErrCode = DSSetParam(hJob2, "StgDB", StgDB)
ErrCode = DSSetParam(hJob2, "StgUser", StgUser)
ErrCode = DSSetParam(hJob2, "StgPwd", StgPwd)
ErrCode = DSSetParam(hJob2, "StgHashFilePath", StgHashFilePath)

ErrCode = DSRunJob(hJob2, DSJ.RUNNORMAL)
ErrCode = DSWaitForJob(hJob2)

*********** CONTROL WAITS HERE FOREVER**************

Status = DSGetJobInfo(hJob2, DSJ.JOBSTATUS)
Call DSLogInfo(DSJ.JOBSTATUS, "JobControl")

If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED Then
Call DSLogInfo("Job Failed: ", "JobControl")
End
End Else
Exit ; * at end-of-file
End
until Status() = 1
Repeat

Close FileVar

goto TheEnd

errorexit:
Close FileVar
Call DSLogFatal("IPY004File.txt file error"," Job Aborted, ")

FileErr:
Close FileVar
Call DSLogFatal("IPY004File.txt file not found in the specified directory"," Job Aborted, ")

NothingToProcess:
Close FileVar
Call DSLogWarn ("No IPY004files found to process", "* End of Batch")

TheEnd:
Close FileVar
Call DSLogInfo (DSJ.JOBNAME, "* IPY004 file verification job finished successfully:")

********************************************************
If i comment the DSWaitForJob() line:

Job control works for 1 file (1 row in the IPY004File.txt)

But does not for >1 files. It is processing the first file and not waiting for it to finish before the next iteration.

I think i am missing something....

Thanks for your time,
Jay
Post Reply