Page 1 of 1

hash file

Posted: Wed Jan 29, 2003 2:22 am
by kamalraaj
Hi All,

How can I read Hash File using script and how to assign values after reading it.

Thanks

Posted: Wed Jan 29, 2003 5:12 am
by ray.wurlod
Are you talking about a UNIX shell script (or Windows DOS script), or some other kind of script?
As a general rule, hashed files are the preserve of the DataStage Repository database. The question you have asked is akin to "how do I read an Oracle table using script and assign values after reading it?".
It can be done, but it's indirect. From your script, which must have all relevant environment variables correctly set (for example from dsenv on a UNIX platform) your script must invoke the DataStage environment and pass to it (on the command line is OK) the command that you wish to use. Like Oracle, this is likely to be an SQL statement - remember that hashed files are actually DataStage database tables.
Beware, too, that you can cause damage by imprudent use of UPDATE and DELETE statements.

But why not use DataStage to do this for you? The GUI is much easier to use and to maintain than script files.



Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518

Posted: Wed Jan 29, 2003 9:19 pm
by kamalraaj
Thanks for your reply Ray,

What i need exactly is to use a hash file to store all my user names, passwords etc. and to read it in the control file before starting the job and assing it to the default parameters. I had made it worked with text file but i want this to use hash files. It will be useful if you can say how to Open and saved hash file and read the fields and assign it to the variables.

Thanks
Kamal.

Posted: Wed Jan 29, 2003 11:20 pm
by ray.wurlod
This "solution" assumes you have a hashed file whose key is the parameter name, the value for which is in field number 1.

Open "hashedfilename" To filevariable
Then
ParamName = "UserName"
Key = "UserName"
ReadV ParamValue From filevariable, Key, 1
Then
ErrStatus = DSSetParam(hJob1, ParamName, ParamValue)
End
* Repeat for as many parameters as you need to load
End
Close filevariable ; * hashed file no longer needed

You can overwrite a hashed file record with a Write statement.
You can overwrite a field in a hashed file record with WriteV.
Check these out in Help or in the BASIC manual.

Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518

Posted: Thu Jan 30, 2003 6:05 am
by kamalraaj
Hi following is the statement i used to assing values after reading from hash file. There is no error in the job but the parameter passed is empty.

Thanks
Kamal


Open "C:dataDSLink2" To filevar Then
ParamName = "User_Name"
Key = "User_Name"
ReadV ParamValue From filevar, Key, 1
Then
tofile_name = ParamValue

End
* Repeat for as many parameters as you need to load
End
Close filevar ; * hashed file no longer needed

hJob1 = DSAttachJob("prodtest", DSJ.ERRFATAL)
If NOT(hJob1) Then
Call DSLogFatal("Job Attach Failed: AccessProduct", "JobControl")
Abort
End
ErrCode = DSSetParam(hJob1, "user_name", tofile_name)
ErrCode = DSRunJob(hJob1, DSJ.RUNNORMAL)
ErrCode = DSWaitForJob(hJob1)
Status = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
If Status = DSJS.RUNFAILED Then
* Fatal Error - No Return
Call DSLogFatal("Job Failed: DSCCSDS", "JobControl")
End

Posted: Thu Jan 30, 2003 4:14 pm
by ray.wurlod
If you're going to open a hashed file by pathname, you must use OpenPath rather than Open.
Please provide a listing of the record "User_Name" from this hashed file.
Please verify that the name of the parameter in the job is "user_name" (all lower case) and/or the value returned from the DSSetParam call.


Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518

Posted: Fri Jan 31, 2003 2:23 am
by kamalraaj
Hi Ray,

I tried inthat way only but it's not working. Any other alternate for this problem ?
Thanks,

Kamal

Posted: Fri Jan 31, 2003 5:01 pm
by ray.wurlod
This code is the best solution, and works happily here.
You need to insert some diagnostic statements (DSLogInfo) to reveal "why" it's not working.
(1) is the file opened?
(2) is the record/field successfully read?
(3) is the variable successfully assigned?
(4) does DSSetParam return an error code?
and so on.
I would also like to see the record layout from your hashed file, as asked earlier.


Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518