Page 1 of 1

Writing parameters to Hashed file

Posted: Tue Mar 07, 2006 5:06 pm
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

Posted: Tue Mar 07, 2006 6:54 pm
by kduke
You could replace every job activity with this as a routine activity.

Posted: Tue Mar 07, 2006 7:17 pm
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.

Posted: Wed Mar 08, 2006 6:27 am
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.

Posted: Wed Mar 08, 2006 8:20 am
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.

Posted: Wed Mar 08, 2006 8:42 am
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().

Posted: Wed Mar 08, 2006 8:55 am
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]

Posted: Wed Mar 08, 2006 9:11 am
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.

Posted: Wed Mar 08, 2006 11:05 am
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

Re: Writing parameters to Hashed file

Posted: Thu Mar 09, 2006 7:25 am
by gateleys
Anyone!! to help me with the above error??

Posted: Thu Mar 09, 2006 7:29 am
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.

Posted: Thu Mar 09, 2006 7:42 am
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)

Posted: Thu Mar 09, 2006 11:50 am
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