I want to call a job from a routine with a number of parameters. I want to then write the values of the job parameter to a seq file.
How do i create a job to run with just a sequetial file writing the parameter values to a seq stage?
Calling a job from a routine
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 27
- Joined: Sun Mar 20, 2005 4:23 am
- Location: Brisbane, Australia
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
You're building another millstone for performance. To be brutal, I don't think you really want to do this, particularly if you're planning to invoke this routine for every row processed in some other job.
Use DSGetParamInfo with DSJ.ME as the first argument to interrogate the values of parameters. Use OpenSeq, possible WeofSeq, WriteSeq and CloseSeq to write stuff to a file from a routine.
To invoke a job from a routine you have at least three alternatives:
But I still think you're adding too much indirection (and job startup overhead). Why not create an after-job subroutine (or after-stage subroutine) to write the parameter values into a text file?
Search the forum for recently posted OpenSequentialFile routine and call it OpenTextFile. A DSX is downloadable from Ascential Developer Net
Use DSGetParamInfo with DSJ.ME as the first argument to interrogate the values of parameters. Use OpenSeq, possible WeofSeq, WriteSeq and CloseSeq to write stuff to a file from a routine.
To invoke a job from a routine you have at least three alternatives:
- invoke routine UtilityRunJob
invoke dsjob via DSExecute
properly, code invoking the job (DSAttachJob, DSSetParam, DSRunJob, DSWaitForJob, DSGetJobInfo, DSDetachJob, etc.)
But I still think you're adding too much indirection (and job startup overhead). Why not create an after-job subroutine (or after-stage subroutine) to write the parameter values into a text file?
Code: Select all
SUBROUTINE WriteParams(InputArgs, ErrorCode)
* InputArgs contains file pathname
DEFFUN OpenTextFile(Name, OpenMode, WriteMode, Logging) Calling "DSU.OpenTextFile"
$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF
$INCLUDE UNIVERSE.INCLUDE FILEINFO.H
ErrorCode = 0
hFile = OpenTextFile((InputArgs), "W", "O", "Y")
If FileInfo(hFile, FINFO$IS.FILEVAR)
Then
ParamList = DSGetJobInfo(DSJ.ME, DSJ.PARAMLIST)
Convert "," To @FM In ParamList
Loop
Remove ParamName From ParamList Setting MoreParams
ParamValue = DSGetParamInfo(DSJ.ME, ParamName, DSJ.PARAMVALUE)
WriteSeq ParamName : " = " : ParamValue To hFile
Else
Call DSLogWarn('Unable to write to file', DSJobName)
ErrorCode = -2 ; * stop job on return
Exit ; * exit from loop
End
While MoreParams
Repeat
CloseSeq hFile
End
Else
ErrorCode = -1 ; * stop job: routine has logged reason
End
RETURN
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 27
- Joined: Sun Mar 20, 2005 4:23 am
- Location: Brisbane, Australia
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
The routine itself has to return the file handle.
But you could use the system variable @USER.RETURN.CODE, or one of the system variables @USER0 through @USER4, or the invoking job's user status area, as ways in which to return the flag you require. You could also return the flag through one of the four arguments (all arguments are passed by reference). If you take this road, make sure to document the fact that you are relying upon a side-effect.
You would also need to either accede to the assumption needed in the routine. If the file is opened successfully but does not exist, it has not been written to at that point so still does not exist. The way that the routine works assumes that if the file will not be written to it will not be brought into existence. You could, of course, place a CREATE statement in the ELSE clause of OPENSEQ to force the file to come into existence, albeit empty.
If the file already exists, the THEN clause is taken. What happens in that case is determined by the WriteMode argument; the file is either truncated or appended to.
But you could use the system variable @USER.RETURN.CODE, or one of the system variables @USER0 through @USER4, or the invoking job's user status area, as ways in which to return the flag you require. You could also return the flag through one of the four arguments (all arguments are passed by reference). If you take this road, make sure to document the fact that you are relying upon a side-effect.
You would also need to either accede to the assumption needed in the routine. If the file is opened successfully but does not exist, it has not been written to at that point so still does not exist. The way that the routine works assumes that if the file will not be written to it will not be brought into existence. You could, of course, place a CREATE statement in the ELSE clause of OPENSEQ to force the file to come into existence, albeit empty.
If the file already exists, the THEN clause is taken. What happens in that case is determined by the WriteMode argument; the file is either truncated or appended to.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.