How to declare & use parameter in Routines

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
Devyani Sarkar
Participant
Posts: 26
Joined: Thu Apr 15, 2004 12:54 am

How to declare & use parameter in Routines

Post by Devyani Sarkar »

My routine refers to some values like directory path, file names as parameter values read from a file so how do I declare such parameters and use them in the routine code? In jobs I am able to read from a file and the parameters when I declare the parameters. No idea how to implement in routines.
Thanks
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Hello Devyani,

there is a difference in how you do this depending upon whether you are writing a DataStage function or a before/after Routine.

With functions you can declare any number of arguments and one function return value. So you could declare an input parameter for each of the values that you require, i.e.

Code: Select all

x = MyRoutine(Path,FileName)
and pass them into the function from the job.

A Routine is limited, DataStage requires that it have 2 parameters and one of them is the return code that DataStage then uses. In this case you use the one parameter available to you and build your own string, i.e.

Code: Select all

CALL MyRoutine(Path:';':FileName)
and inside your routine you parse the input string back into it's distinct components.
Devyani Sarkar
Participant
Posts: 26
Joined: Thu Apr 15, 2004 12:54 am

Post by Devyani Sarkar »

Thanks, could you pls explain more, Scenario is:
1) All jobs/routine must read froma parameter file all the paravales as much possible.
2) So I have written a routine which read from these parameter file. Say readfromParameterfile
3) I know now(thanks to you all) how to call this routines from the jobs/routines.

A) NOW what I wanted to know how to define the parameters and get the values using the routine readfromParameterfile in mynewroutine?
When I pass parameter to the routines from jobs I send one single parameter and break it. like ArgList = Trims(Convert(',',@FM,InputArg))
or
How do I mention in routine to read the variable vlaues from a file?
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Devyani,

If your function works like ParamValue = ReadFromParameterFile(ParameterName) then in your case you would write a DataStage sequence with a routine stage that retrieves the parameter value you want to use, then in your Job stage you would use that variable to pass in the parameter value.

The reason you have to use this 2 stage approach is that you are not allowed to change the value of a parameter from inside the job itself.

Or is your question on how to call your routine from another routine?[/b]
dsxdev
Participant
Posts: 92
Joined: Mon Sep 20, 2004 8:37 am

Post by dsxdev »

Hi Devyani,

Can you be more specific about your requirement, do you have a file which has parameter and values. These parameter s and values are used in job and in the sme job you have a routine which reads this file to access the parameters and values.

In case you need to access the parameters from a file you can use teh following code

DSGetParamInfo(JobHandle, ParamName, InfoType)

Code: Select all

 
hJob = DSAttachJob (JobName, DSJ.ERRFATAL) -- Get job handle
strDatasetDir = DSGetParamInfo(hJob, DatasetDir, DSJ.PARAMVALUE) -- get job parameter [b]DatasetDir[/b] value into strDatasetDir variable.
This way you can read values of variables / parameters used inthe job in a routine.

If you have to directly read from a file then use

OpenSeq function to read the parameter values.

Code: Select all

OpenSeq strFile to objFileVar
         Else Create objFileVar Else ErrorCode = 1
      WeofSeq objFileVar
      Call DSLogInfo(strFile,DSJ.ME)
To open a file

Then read from file

Code: Select all

ReadSeq paramValue From objFileVar
Thus you can either read frmteh job or directly from file and uses these parameters.
Happy DataStaging
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

:idea: :!:
Don't use WeofSeq if you're planning to read from the file. WeofSeq writes an end-of-file mark at the current location, which is beginning of file if the file has just been opened. This truncates the file to 0 bytes.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Devyani Sarkar
Participant
Posts: 26
Joined: Thu Apr 15, 2004 12:54 am

Post by Devyani Sarkar »

Thanks dsxdev,
Yes I have a file which has parameter and values as
ParamName1=ParamValue1
ParamName2=ParamValue2
..
ParamNameN=ParamValueN

We have written a routine to read the values and assign to the parameters used in the DStage Jobs.
and we call this routine as before job subroutine call, which solves our requirement.

Now I came across a situation where I need to read the parameters in a routine say new_routine for
some processing for instance which directory to copy a file and rename is mentioned in the parameter
file and this new_routine is not called by any job , but in the routine stage in sequencer. Could I get some help?
Devyani Sarkar
Participant
Posts: 26
Joined: Thu Apr 15, 2004 12:54 am

Post by Devyani Sarkar »

Thanks dsxdev,
Yes I have a file which has parameter and values as
ParamName1=ParamValue1
ParamName2=ParamValue2
..
ParamNameN=ParamValueN

We have written a routine to read the values and assign to the parameters used in the DStage Jobs, and we call this routine as before job subroutine call, which solves our requirement.

Now I came across a situation where I need to read the parameters in a routine say new_routine for some processing for instance which directory to copy a file and rename is mentioned in the parameter file and this new_routine is not called by any job , but in the routine stage in sequencer. Could I get some help?
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Devyani,

is your question about how to call your parameter function from a routine stage in a sequencer? If that is the case, the Sequencer takes care of all the details such as parameter definitions for you.

If this is not the case, perhaps you could explain your requirements in a little bit more detail.
Devyani Sarkar
Participant
Posts: 26
Joined: Thu Apr 15, 2004 12:54 am

Post by Devyani Sarkar »

I do not want to mention the parameters in Sequencer since the DB login and other such info vary from env to env and we wish to avoid editing this way. Hence we call a routine in general for jobs which read from a parmeter file.
Now I have another routine which will use parameter so how do i set parameters for this job?
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Devyani,

I'd really like to help you, but I feel that I just can't understand what you are asking. Could you give a small pseudocode or similar example?

If I understood your text correctly, you have a function that gives you parameter runtime values. Let's say it is called GetParamValue(<parametername>) and it returns the value. What then is your question?
Devyani Sarkar
Participant
Posts: 26
Joined: Thu Apr 15, 2004 12:54 am

Post by Devyani Sarkar »

:-) Thanks.
Now I can use this in a job. :-)
I get struck when I have few variable in a routine. Say RoutineTwo which has variables and for these varible I read values from the same parameter file which has set of Parameters as I mentioned earlier and out of them I wish to use ParamName2=ParamValue2.
---------------------------------------------------------
ArgList = Trims(Convert(',',@FM,Arg1))
CigmaLogMessage = ArgList<2>
CigmaMsgQueueMgr = ArgList<3>

?????

JobName1 = 'PocPh2LogMsgJob4Four'

Hjob1 = DSAttachJob(JobName1,DSJ.ERRFATAL)
* set the job's parameters
Dummy = DSSetParam(Hjob1, 'CigmaProcess_Str_Param',CigmaProcess)
Dummy = DSSetParam(Hjob1, 'CigmaLogMessage_Str_Param',CigmaLogMessage)

* run the first job
Dummy = DSRunJob(Hjob1,DSJ.RUNNORMAL)

---------------------------------------------------------

At ????? I wish to improve my code by making it read from the file instead of reading from a string as inputarg which I am passing with all values to teh routine call.
I wish to instead send only the parameter file name, and the routine should read CigmaLogMessage and CigmaMsgQueueMgr from that file which I mentioned earlier.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Devyani,

slowly but surely I am seeing a bit direction in this thread. It seems that you don't have the read routine yet, but wish to get it from this forum, you want to create a Function:

Code: Select all

GetJobParameter(ParameterName)
EQUATE ProgramName TO 'GetJobParameter'
OPENSEQ 'ParameterFile' TO InFilePtr ELSE CALL DSLogFatal('Oh No, cannot open file',ProgramName)
Finished = 0
Ans      = ''
READNEXT InRecord FROM InFilePtr ELSE Finished = 1
LOOP UNTIL Finished
   FileParameterName = TRIM(FIELD(InRecord,'=',1))
   FileParameterValue = TRIM(FIELD(InRecord,'=',2,99))
   IF (FileParameterName=ParameterName)
   THEN
      Finished = 1
      Ans = FileParameterValue
   END
   READNEXT InRecord FROM InFilePtr ELSE Finished = 1
REPEAT
IF NOT(Ans) THEN CALL DSLogFatal('Could not find value for "':ParameterName:'".',ProgramName)
CLOSESEQ InFilePtr

This code is simple but incredibly inefficient. The method I have used here on this project uses the same format as you, {parametername} = {value}, but I read the file into a dynamic array once, put it into a common block and on subsequent calls I don't re-read the file but use the LOCATE command to do a quick lookup.

Does this help you?
Devyani Sarkar
Participant
Posts: 26
Joined: Thu Apr 15, 2004 12:54 am

Post by Devyani Sarkar »

Yeah looks like YOu could get a bit of my requirement :-)

I had a routine to read from the parameter file. From your code, I infer that I need to replicate similar code I wrote in my GetParamFromFile routine in the Newroutine2 to read the parameter and add one If condition to look for the parameter name which matched. I will try out and update you. Thanks a lot for the pointers. :-)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Pseudo-code ?

Post by ray.wurlod »

Code: Select all

For each parameter name in controlled job
   If parameter name=value exists in file
   Then
       load controlled job's parameter with value, check for errors
   Else
       do not load controlled job's parameter; issue "default used" message
   EndIf
End For
Is that the design? More bullet proofing could be added.
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