LJobName = 'MyJob'
LStageName = 'MyStage'
LLinkName = 'MyLink'
JobHandle = DSAttachJob(LJobName,DSJ.ERRFATAL)
IF NOT(JobHandle) OR JobHandle=DSJE.BADHANDLE THEN CALL DSLogFatal('Bad attach to job "':LJobName:'".','MyFunction')
Ans = DSGetLinkInfo(JobHandle,LStageName,LLinkName,DSJ.LINKROWCOUNT)
IF (Ans<0)
THEN
CALL DSLogWarn('Unable to retrieve rows through link "':LLinkName:'" in stage "':LStageName:'" for Job "':LJobName:'".',ProgramName)
Ans = 0
END ;** of if-then something went wrong
Dummy = DSDetachJob(JobHandle) ;** close up the job
This is where I think I went wrong earlier on today when my Job Sequence wouldn't die.
My Job Sequence was running (called job_seq1) and I tried to do a DSAttachJob("job_seq1"). Obviously that was wrong as discussed earlier.
Should the Job Name in the DSAttachJob be the underlying Server Job that I am calling ?
The name of the job that you are going to open is that which contains the stage & link that you are trying to get information for. If your function is called as an after-job subroutine then you would use DSJ.ME as the JobHandle.
If you want to avoid the hang and also use multi-instanciation then you can code:
MyJobName = DSGetJobInfo(DSJ.ME,DSJ.JOBNAME)
MyJobInstance = DSGetJobInfo(DSJ.ME,DSJ.JOBINVOCATIONID)
IF (MyJobInstance) THEN MyJobName := '.':MyJobInstance ;** make a full jobname if a multi-instance call
IF (MyJobName=LJobName) THEN Ans = DSJ.ME ;** return the DSJ.ME mnemonic code to the caller
ELSE
Ans = DSAttachJob(LJobName,LErrorMode)
END ;** of if-then-else trying to open own job
to work around the potential problem of hanging while trying to attach to yourself.
Couldn't get this to work unfortunately - despite being able to return the job name, short/long description, stageName and LinkName the rowcount returned was always 0. Have given up just now and just gone for a 'wc -l' and an awk statement.