Calling a job from a routine

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
mickboland
Participant
Posts: 27
Joined: Sun Mar 20, 2005 4:23 am
Location: Brisbane, Australia

Calling a job from a routine

Post by mickboland »

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?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

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:
  • invoke routine UtilityRunJob

    invoke dsjob via DSExecute

    properly, code invoking the job (DSAttachJob, DSSetParam, DSRunJob, DSWaitForJob, DSGetJobInfo, DSDetachJob, etc.)
Now, a job that only writes its own parameter values to a file is very easy. The job design consists of a Transformer stage, with as many output columns as you need. Each can be derived from a job parameter. Also create a stage variable; evaluating this will generate rows. Constrain the output using @INROWNUM = 1, and direct the output to a Sequential File stage.

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
Search the forum for recently posted OpenSequentialFile routine and call it OpenTextFile. A DSX is downloadable from Ascential Developer Net
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
mickboland
Participant
Posts: 27
Joined: Sun Mar 20, 2005 4:23 am
Location: Brisbane, Australia

Post by mickboland »

Thanks ray - I created a routine that uses your opensequential file function to write the data to a seq file.

Is there a way of returning a flag from the opensequential file to identify if a new file was created or that we are just appending records?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

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.
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