How to establish a connection to DB in Batch Jobs

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
laknar
Participant
Posts: 162
Joined: Thu Apr 26, 2007 5:59 am
Location: Chennai

How to establish a connection to DB in Batch Jobs

Post by laknar »

Hi,

I would like to establish a connection to DB2 Db in Batch job

Iam trying to insert (Jobstarttime,jobendtime , job elapsed time and current date) into Db in the Batch job.

How to execute a script in Batch Jobs
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Create a job the effects the insert, and run that job within the batch.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: How to establish a connection to DB in Batch Jobs

Post by chulett »

laknar wrote:How to execute a script in Batch Jobs
Or use DSExecute to run your script.
-craig

"You can never have too many knives" -- Logan Nine Fingers
laknar
Participant
Posts: 162
Joined: Thu Apr 26, 2007 5:59 am
Location: Chennai

I declared a variable in First job like jobstarttime etc

Post by laknar »

* Setup A, run it, wait for it to finish, and test for success
hJob1 = DSAttachJob("A", DSJ.ERRFATAL)
If NOT(hJob1) Then
Call DSLogFatal("Job Attach Failed: A", "JobControl")
Abort
End
ErrCode = DSSetDisableProjectHandler(hJob1, @FALSE)
ErrCode = DSSetDisableJobHandler(hJob1, @FALSE)
ErrCode = DSRunJob(hJob1, DSJ.RUNNORMAL)
ErrCode = DSWaitForJob(hJob1)
Status = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
Jobname= DSGetJobInfo(hJob1, DSJ.JOBNAME)
Jobstarttime = DSGetJobInfo(hJob1, DSJ.JOBSTARTTIMESTAMP)
Jobendtime = DSGetJobInfo(hJob1, DSJ.JOBLASTTIMESTAMP)
Jobelapsedtime = DSGetJobInfo(hJob1, DSJ.JOBELAPSED)
Jobstatus=DSGetJobInfo(hJob1,DSJ_JOBSTATUS)
If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED Then
* Fatal Error - No Return
Call DSLogFatal("Job Failed: A", "JobControl")
End
* Setup ReportJob, run it, wait for it to finish, and test for success
hJob2 = DSAttachJob("ReportJob", DSJ.ERRFATAL)
If NOT(hJob2) Then
Call DSLogFatal("Job Attach Failed: ReportJob", "JobControl")
Abort
End
ErrCode = DSSetDisableProjectHandler(hJob2, @FALSE)
ErrCode = DSSetDisableJobHandler(hJob2, @FALSE)
ErrCode = DSRunJob(hJob2, DSJ.RUNNORMAL)
ErrCode = DSWaitForJob(hJob2)
Status = DSGetJobInfo(hJob2, DSJ.JOBSTATUS)
If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED Then
* Fatal Error - No Return
Call DSLogFatal("Job Failed: ReportJob", "JobControl")
End

I declared a variable in First job like jobstarttime etc,.

I want to call the variables into the next job in DB2 insert script.

how to call and how to insert job(A) report into table.

The above Batch i have shown you example.

Please help regarding this.

And how to run the job parallely in Batch jobs.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Four calls to DSSetParam() will be needed before DSRunJob() is invoked to run ReportJob. DSJ_JOBSTATUS is not a valid DataStage constant; it needs to be DSJ.JOBSTATUS.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
laknar
Participant
Posts: 162
Joined: Thu Apr 26, 2007 5:59 am
Location: Chennai

Post by laknar »

i want to call all the variables in DB insert statement like

Jobstarttime
Joblasttime
Jobelapsedtime
Rundate

how to call that in batch jobs.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Create a job to insert the row. Pass the four values as job parameters. Generate one row.

Pass the parameters to the job from the batch, obtaining the values as described 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.
Post Reply