Page 1 of 1

Before Job SubRoutine to set Job Parameter Values

Posted: Tue Sep 21, 2010 7:06 am
by rupeshg
Hi,

Requirement: Before job subroutine (BASIC) to provide value (come from a shell script) to the Job Parameter of the same Job.

Job Parameter <-- Before Job Subroutine <-- Shell script

Solution so far: I can call the shell script and get its output value in a variable.

Call DSExecute("Unix", command, Ans, SystemReturnCode)

Where
command = shell script name with full path with proper arguments (works fine)

However, I am not able to assign it to the Job Parameter.

ErrCode = DSSetParam(JobHandle, "pEtlJobRunId", Ans)

Where
JobHandle=DSJ.ME
pEtlJobRunId= job parameter name
Ans = output from a shell script


Here the ErrCode = -1
meaning DSJE.BADHANDLE Invalid JobHandle. So, I come to a conclusion that I cannot attach the same job to set the job parameters (not even using DSAttachJob, job hangs for 1800 seconds and than errors out saying same job cannot be attached).

Is there a work around to this? So I can Set the job parameter values from the before job subroutine (for the same job).

Thanks in advance.

Posted: Tue Sep 21, 2010 7:09 am
by chulett
Not possible "before job" as it's not really as "before" as you might think. The job is actually running at that point so it's too late to affect the job parameter values for that run.

You need to truly be "before" the job even starts to do anything like that. So that means job control code, a wrapper script or a Sequence job that gathers the required information, sets the parameter's value and then runs the job.

Posted: Tue Sep 21, 2010 7:51 am
by ArndW
As Craig has already intimated, the "Before Job" should actually be called "In the Job, but before the stages start executing".

It is a known (and irksome) limitation of DSAttachJob that one cannot attach to oneself. I tend to use something along the lines of the the following code in jobs where a job could conceivably attempt to attach to itself.

Code: Select all

IF DSGetJobInfo(DSJ.ME,DS.JOBNAME)='MyJobName' THEN JobHandle = DSJ.ME ELSE JobHandle = DSAttachJob('JobToAttach',DSJ.ERRNONE)

Posted: Tue Sep 21, 2010 9:13 am
by rupeshg
Thanks Craig and ArndW.

ArndW,

My jobname is "Test1" and I have added following code to my routine.

IF DSGetJobInfo(DSJ.ME,DS.JOBNAME)= 'MyJobName' THEN JobHandle = DSJ.ME ELSE JobHandle = DSAttachJob('Test1',DSJ.ERRNONE)

It still gets stuck for 1800 seconds before aborting.

Is there something wrong that I am doing?

Thanks in advance.

Posted: Tue Sep 21, 2010 9:18 am
by chulett
Arnd simply corrected your use of a routine attaching to the calling object. That doesn't change the fact that you cannot do what you are attempting to do... which it seems you are still attempting. Or are we just off in testing land? :?

Posted: Tue Sep 21, 2010 9:58 am
by rupeshg
Thanks Craig.

I established from your first reply itself that it's not possible to attach the same job. I was just trying any slightest hope to get it work as that will save lot of extra work for me.

Anyways, I'll go with Job Control or Sequencer Job.

Thanks once again.

Posted: Tue Sep 21, 2010 4:17 pm
by kduke
You can do the equivelent by using UtilityRunJob and modifying it to lookup the parameter values.

Posted: Wed Sep 22, 2010 10:33 am
by ArndW
rupeshg wrote:Thanks Craig and ArndW.

ArndW,

My jobname is "Test1" and I have added following code to my routine.

IF DSGetJobInfo(DSJ.ME,DS.JOBNAME)= 'MyJobName' THEN JobHandle = DSJ.ME ELSE JobHandle = DSAttachJob('Test1',DSJ.ERRNONE)

It still gets stuck for 1800 seconds before aborting.

Is there something wrong that I am doing?

Thanks in advance.
IF DSgetJobInfo(DSJ.ME,DSJ.JOBNAME)='Test1' THEN JobHandle = DSJ.ME ELSE JobHandle = DSAttachJob('Test1',DSJ.ERRNONE)

but, as stated, this won't get you be the restriction that job parameters cannot be modified from within the job itself.