Hi All,
How can I read Hash File using script and how to assign values after reading it.
Thanks
hash file
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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
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
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.
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.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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
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
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
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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
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