Page 1 of 1

Readin the first item in a hash file

Posted: Fri Sep 15, 2006 1:58 pm
by DarioE
I need to write a basic routine which reads only the first record (item) from a hash file passed to it as a parameter.
The Read statement works fine when you have the item-id, but what if you don't, how do you get the first record only?

Thanx in advance!

Posted: Fri Sep 15, 2006 3:38 pm
by kduke
There is no first record in a hashed file. It is stored randomly. You can get a list of the item ids with a select list.

Code: Select all

open 'MyHashedFile' to FilePtr then
   SELECT FilePtr
   loop while readnext ItemId
   repeat
end
This will get you close.

Posted: Fri Sep 15, 2006 6:06 pm
by ray.wurlod
READNEXT gets the next key value; you will still need to issue a READ statement. If you only want the first record (and, remember, it is not predictable what the first record will be), then you don't need the LOOP in Kim's code. The following would work.

Code: Select all

Cmd = "SELECT * FROM MyHashedFile FIRST 1;"
Call DSExecute("UV", Cmd, Output, Code)
Result = Trim(Output, @FM)
Adapt the query to suit your particular requirements. If the hashed file was created in a directory, you will need to create a VOC pointer to it, possibly using a SETFILE command.

Posted: Sat Sep 16, 2006 3:39 am
by DarioE
Thanx kduke, thanx ray.
It works and is in production already :-))