Page 1 of 1

Pass value between jobs

Posted: Wed Mar 03, 2004 6:38 pm
by sim
Hi:
I have two jobs (Job1 and Job2). I want to pass a value from Job1 to Job2 using parameter. Job1 finds a max(column1) and this max value has to be passed to Job2's parameter. How do I do this? Thanks for your help.

Posted: Wed Mar 03, 2004 7:32 pm
by ray.wurlod
Job0 is a controlling job (or job sequence) that runs Job1 then Job2. Job1 puts the value somewhere, perhaps its user status area, perhaps a text file. Job0 reads that value and uses it to set the parameter value for Job2 before running Job2.

Posted: Wed Mar 03, 2004 8:48 pm
by kcbland
If the first job has only the responsibility of getting that max value and writing it somewhere, why not encapsulate that SQL logic into a shell script call or a DS routine wrapped to that shell script call? Then, you could fetch that value either in job control and pass it as a value, or, during a stage variable initialization perform that function call wrapped around the shell script executing a SQL script.

Posted: Fri Mar 05, 2004 3:06 pm
by sim
Thanks for your help. I'll try both of your approach (I have lot of time!). I tried Ray's way and I have job control code like this:[code]
MyVariable = 10

* Setup job1, run it, wait for it to finish, and test for success
hJob1 = DSAttachJob("job1", DSJ.ERRFATAL)
If NOT(hJob1) Then
Call DSLogFatal("Job Attach Failed: job1", "JobControl")
Abort
End
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: job1", "JobControl")
End

MyVariable = DSGetVarInfo(hJob1, "Transformer9", "maxvalue", DSJ.Varvalue)

* Setup job2, run it, wait for it to finish, and test for success
hJob2 = DSAttachJob("job2", DSJ.ERRFATAL)
If NOT(hJob2) Then
Call DSLogFatal("Job Attach Failed: job2", "JobControl")
Abort
End
ErrCode = DSSetParam(hJob2, "MaximumVal", MyVariable)
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: job2", "JobControl")
End
[/code]
job1 only is executed and job2 is never run. It just stops. I am new to Basic, so please correct me where I am doing mistake.
Thanks

Posted: Sat Mar 06, 2004 3:07 am
by ray.wurlod
The code looks OK. Put in some extra logging statements to diagnose what path is being taken through the code. In particular, determine why job2 isn't starting.
Are any abort messages (red icons) logged in any of the three jobs?

Posted: Mon Mar 08, 2004 12:39 pm
by sim
There is no abort messages...job1 is finished with status OK. job2 is not executed at all and job0 'is running'. Even if I stop job0, it's not stopping. job0 is reset when I compile it again. How would I put logging statements to check errors? Is there any command like 'printout', or 'cout (C++'s)' to print output to logfile? Help me...I am lost.
Thanks

Posted: Mon Mar 08, 2004 12:58 pm
by chulett
sim wrote:Is there any command like 'printout', or 'cout (C++'s)' to print output to logfile? Help me...I am lost.
DSLogInfo
DSLogWarn
DSLogFatal

Check the online help. You want the first one.

Posted: Mon Mar 08, 2004 3:34 pm
by ray.wurlod
You can also use DSLogEntry to put an entry into an attached job's log. In your case, you could log entries into Job1 and/or Job2 log from the code in Job0 using this function.