Writing parameters to Hashed file

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
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Writing parameters to Hashed file

Post by gateleys »

I have my parameters in a hashed file. The key is the paramName. In plaintext, it was in the format below-
paramName1=paramValue1
paramName2=paramValue2
and so on....

I have tried to use Kim's routine to assign parameters to my job. Following is the code:

Code: Select all

* ------------------------------------------------------------ 
* ParamFunc(JobName, WarnFlag, ParamFile) 
$INCLUDE DSINCLUDE JOBCONTROL.H 
      Deffun DSRTimestamp Calling "DSR_TIMESTAMP" 
      * WarnFlag = @FALSE 
* ------------------------------------------------------------ 
      Ans = @FALSE 
      RoutineName = 'ParamFunc' 
      JobStartTime = DSRTimestamp() 
      JobHandle = DSAttachJob(JobName, DSJ.ERRFATAL) 
* ------------------------------------------------------------ 
      open ParamFile to ParamFilePtr else 
         Message = "Error: Unable to open hash file: " : ParamFile 
         Call DSLogInfo(Message, RoutineName) 
         goto TheEnd 
      end 
* ------------------------------------------------------------ 
      DsErrCode = DSPrepareJob(JobHandle) 
      RowLimit = 0 
      WarnLimit = 0 
      DsErrCode = DSSetJobLimit(JobHandle, DSJ.LIMITROWS, RowLimit) 
      DsErrCode = DSSetJobLimit(JobHandle, DSJ.LIMITWARN, WarnLimit) 
      ParamNameList = DSGetJobInfo(JobHandle, DSJ.ParamNameList) 
      ParamCount = Dcount(ParamNameList, ',') 
      For ParamNum = 1 To ParamCount 
         ParamName = field(ParamNameList, ",", ParamNum) 
         Read ParamValueRec From ParamFilePtr, ParamName Then 
            ParamValue = ParamValueRec<1> 
            Message = "Setting: " : ParamName :" = ": ParamValue 
            Call DSLogInfo(Message, RoutineName) 
            DsErrCode = DSSetParam(JobHandle, ParamName, ParamValue) 
         End 
      Next ParamNum 

      DsErrCode = DSRunJob(JobHandle, DSJ.RUNNORMAL) 
      DsErrCode = DSWaitForJob(JobHandle) 
      JobStatus = DSGetJobInfo(JobHandle, DSJ.JOBSTATUS) 
      JobEndTime = DSRTimestamp() 
      Begin Case 
         Case JobStatus = DSJS.RUNFAILED 
            Message = "Job Failed: " : JobName 
            Call DSLogWarn(Message, RoutineName) 
         Case JobStatus = DSJS.RUNWARN and WarnFlag 
            Message = "Job had warnings: " : JobName 
            Call DSLogWarn(Message, RoutineName) 
         Case JobStatus = DSJS.RUNOK 
            Ans = @TRUE 
      End Case 
I have used job parameters. My sequence has a number of jobs. How can I modify the above so that each job in the sequence has its parameters set. I have tried to change the code so that it behaves as a function that returns all the parameter names and values as a concatenated string. However, the next step would be to have a job that would parse the string and extract the param values that I could assign to the subsequent jobs. But, I don't know how that can be done. I know there are many solutions posted here, but I have only been successful when there is only a single parameter required in the entire sequence. Please show me some relatively simpler methods to do this.

THanks
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

You could replace every job activity with this as a routine activity.
Mamu Kim
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Post by gateleys »

kduke wrote:You could replace every job activity with this as a routine activity.
Hi Kim, I will try that. I dont have access to DS right now. While we are at this, I want to put another question across. Like I mentioned above, that the parameters in the sequential file were of the format-
paramName=paramValue
While pushing them into a hashed file, I used '=' as the delimiter, and hence used paramName as the key in the hashed file, and the paramValue as the return field. Is that what you meant in your earlier post about reading parameters from hashed file? If the method is incorrect, can you please give me some pointers?

Thanks again.
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

That is exactly what I meant. Very nice so far. I think you need to add DSPrepareJob. I would also get the row counts at the same time. I posted code to do that as well. If you can't find it then I will post it again if I need to.

You could post your code to go from the sequential file to the hash file. Others might want it. You could also store the values in a table then have a job populate the hash file. You could add a key for the project name so you could have a different set of values for DEV, TEST and PROD.
Mamu Kim
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Post by gateleys »

kduke wrote:I think you need to add DSPrepareJob.
Regarding including DSPrepareJob, it is part of the code you supplied. If you look at the code above, there is a line included-

Code: Select all

DsErrCode = DSPrepareJob(JobHandle)
Now, when I test the this function, I get the following message:

Code: Select all

Program "DSGetJobInfo": Line 98, Variable "InfoType" previously undefined.  Empty string used. Message to be logged is...
> Job Failed: TestJob

Result = 0

I can't figure out what the problem is. Further, when I check the log for the job, I see that it tries to use the parameters' default values (as set in job properties) instead of the values from the param file.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

That error message is telling you that the DSGetJobInfo() function requires two arguments, and that you have not provided an assigned value for the second (InfoType) argument. This occurs at (or near) line number 98 in your routine. It is unrelated to DSPrepareJob().
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Post by gateleys »

Ray,
I have supplied both the arguments to the DSGetJobInfo function-

Code: Select all

ParamNameList = DSGetJobInfo(JobHandle, DSJ.ParamNameList)
and also-

Code: Select all

JobStatus = DSGetJobInfo(JobHandle, DSJ.JOBSTATUS)
Is there a problem in DSJ.ParamNameList?
Further, if you have a look at my code, it only has about 50 lines, so how could there be an error at about line 98? I mean its just waayyy off. Please have a look at the code supplied by Kim (shown above) and suggest solution to where I could have gone wrong.

Thanks[/code]
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

gateleys wrote:...Is there a problem in DSJ.ParamNameList?
I don't know, since it is not a DataStage mnemonic.

By default variable and constant names are case sensitive, so you should use "DSJ.PARAMLIST", as the documentation specifies. The compiler can't know that the variable name you used is undefined in the function call, so it didn't complain and at runtime the engine uses an empty value.
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Post by gateleys »

ArndW wrote:you should use "DSJ.PARAMLIST", as the documentation specifies.
Hi Arnd, I did just that and I could test the function successfully. However, when I use the routine as RoutineActivity stage in a job sequence, and specify a jobname as one of the argument to the function, then it aborts with the following message:

Code: Select all

testSequence..JobControl (fatal error from DSAttachJob): Job control fatal error (0)
(DSCloseJob) Cannot refer to own job handle
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Re: Writing parameters to Hashed file

Post by gateleys »

Anyone!! to help me with the above error??
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

If you have a job named XYZ then you cannot DSAttach to XYZ. A job cannot run itself. It will not allow this.
Mamu Kim
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

You need to apply some rules to avoid this error, since you cannot attach to your own job.

Get your current job's name

Code: Select all

MyJobName = DSGetJobInfo(DSJ.ME,DSJ.JOBNAME)
and in your loop through all elements put in a line

Code: Select all

IF LoopJobName = MyJobName THEN Handle = DSJ.ME ELSE Handle = DSAttachJob(LoopJobName,DSJ.ERRNONE)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

A job is already attached to itself. Use DSJ.ME as the job handle in the DSGet... functions. Do NOT use DSAttachJob(), DSPrepareJob() or DSDetachJob().
Use a CONTINUE statement to bypass the remainder of the loop if the job name is the name of the current job. The following code fragment assumes DS_JOBS has been opened onto DSJobs.fvar.

Code: Select all

ThisJobName = DSGetJobInfo(DSJ.ME, DSJ.JOBNAME)

ClearSelect 10
Select DSJobs.fvar To 10
Loop While ReadNext JobName From 10

   * Bypass processing for the current job

   If JobName = ThisJobName Then Continue

   * Only process job names, which start with alphabetic character.
   * Do not process category names, which begin with "\\"

   If JobName Matches "1A0X"
   Then

      * code to process currently selected job name

   End

Repeat
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