Hash File open/read/update in the server routine

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
sandy_thomas
Participant
Posts: 9
Joined: Tue Dec 09, 2003 2:20 pm

Hash File open/read/update in the server routine

Post by sandy_thomas »

I'm trying to write a server routine. in that i have to open a hash file which has like 6 columns. The key column is "NAME", Based on the input argument( Which is "NAME") i have to go to that perticular record in the hash file and update the other fields.
i'm trying to open the hash file using OPENPATH but it is picking up the ON ERROR/ ELSE statements. Also have problem in parsing the record, record has like varchar, numeric and varchar types. :(

Any help would be really appreciated...
Thanx,
San
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Please paste your logic and identify it with the code button. Please also paste the fully qualified path and filename.

Your problem could anything from bad logic, unqualified path to file, permissions in the directory, etc.

Data type is irrelevant in hash files. There is no difference between a varchar column and a numeric column, as there is no inherent data typing in hash files.

Please paste the logic you are trying to use to parse the hash file record content.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
sandy_thomas
Participant
Posts: 9
Joined: Tue Dec 09, 2003 2:20 pm

Post by sandy_thomas »

Code: Select all

OPENPATH '/open/devel/work/hash' to f.infile 
ELSE ABORT
QUIT=@FALSE
Loop
  read RCD from f.infile else QUIT=@TRUE
  UNTIL QUIT DO
   FileName = RCD[1,20]
   IF(FileName = InputArg )
      THEN RCD[21]=0 RCD[22] = 0
      QUIT=@True      
REPEAT
ErrorCode = 0
I'm in the root directory.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Okay, let's pretend your hash file is named FRED.

Code: Select all

      OPENPATH '/wherever/FRED' TO F.FRED Else
         Call DSLogFatal("Unable to open FRED", "YourFunction")
      End

      SELECT F.FRED

      Done = @FALSE
      Loop
         READNEXT KEY Else Done = @TRUE
      Until Done Do
         Read FredRow From F.FRED,KEY Then
             *  Do something
         End
      Repeat

      Call DSLogInfo("All Done", "YourFunction")
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Your internal logic makes no sense. There's no WRITE statement, so you are not writing back any data. Furthermore, you have no SELECT statement, so you are not putting any data into a selection list (queue). You also are not reading the content of the file, because you do not specify the READ command correctly. You basically are just doing substring manipulation, as opposed to column checking ( brackets are not array delimiter tokens).

Could you please describe the functional requirement as well as the data.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
sandy_thomas
Participant
Posts: 9
Joined: Tue Dec 09, 2003 2:20 pm

Post by sandy_thomas »

if i get a key match then i have to go to that particular record and update the fields following the key field in the record.
i dont understand the use of "KEY" in your code.

Thanx for all the help though. i never wrote a routine for File I/O.
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

San

A SELECT statement builds a list of KEYs or what are called item ids. A hash record is called an item. The readnext statement loops through this list of keys.

Kim.
Mamu Kim
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Sandy, a hash file is a binary file. Every row has a key that is unique, so you can call it the primary key. That key is ran through an algorithm to determine the placement of the row in the file. You need to know the key in order to find the row again in the file.

See here for a more thorough explanation of hash files:

Code: Select all

http://www.dsxchange.com/viewtopic.php?t=85364
There are 2 and only 2 ways to get a row out of a hash file. Either you know the key and can directly retrieve the row; or you dump the contents of the hash file. In the code sample I gave you, I setup a loop to cycle through the hash file. The BASIC statement

Code: Select all

      SELECT F.FRED
put into an active queue the list of all primary keys in the hash file. The READNEXT statement fetches the next key from that list. The READ statement retrieves the row from the hash file. The syntax

Code: Select all

         Read FredRow From F.FRED,KEY Then 
uses the KEY variable and gets the row located in that file pointer (F.FRED).

If you know the primary key, you do not need to setup a loop. You simply directly read the row! Ex:

Code: Select all

Read FredRow From F.FRED,"your key value" Then
   Do This
End Else
   Do that
End
"your key value" can be a literal as in this example, or a variable.

Again, please state your functional requirements. It is difficult to help people when we don't know what you need to do, we only see what you want to do. We have yet to address updating your row. We probably will tell you not to do what you're doing once we know what it is that needs to be done. This type of logic is exactly why the tool has a graphical metaphor, with stages designed to do this easily, without any knowledge of the underlying technology.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
sandy_thomas
Participant
Posts: 9
Joined: Tue Dec 09, 2003 2:20 pm

Post by sandy_thomas »

The requirement is like this. we have a hash file that is being shared by many jobs. It has information of all the web sites that the corporation track. This hash file is used as a reference further in the jobs. At any given time the hash file has the most recent information that's being processed for that perticular site. All the jobs are run in a batch and if any of the sites information is not available, it sends the information in the hash file which is wrong. if we are running the job for that particular site before we start processing, initialise the fields and then continue.

Thank you very much for all the help.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Okay, but why are you writing a BASIC subroutine to handle modification of data in this file? Why can't a regular old Server GUI metaphor transformation job do the work for you?
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
sandy_thomas
Participant
Posts: 9
Joined: Tue Dec 09, 2003 2:20 pm

Post by sandy_thomas »

I did that and I'm unsucessful. if there is data it does what it was supposed to do. But the problem comes when there is no data for that particular site.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

If you state your functional requirements, I'm sure we could tell you how to do it easily with a GUI job.

The Inner Circle members are here to help in these types of situations. Rather than teach BASIC file i/o, we'd rather people concentrate on using the tool. I'm pretty sure that what you're doing could/should be handled via a job design.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Post Reply