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!
Readin the first item in a hash file
Moderators: chulett, rschirm, roy
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.
This will get you close.
Code: Select all
open 'MyHashedFile' to FilePtr then
SELECT FilePtr
loop while readnext ItemId
repeat
end
Mamu Kim
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
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.
Code: Select all
Cmd = "SELECT * FROM MyHashedFile FIRST 1;"
Call DSExecute("UV", Cmd, Output, Code)
Result = Trim(Output, @FM)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.