Readin the first item in a hash file

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
DarioE
Participant
Posts: 4
Joined: Thu Sep 14, 2006 9:56 am

Readin the first item in a hash file

Post 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!
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post 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.
Mamu Kim
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DarioE
Participant
Posts: 4
Joined: Thu Sep 14, 2006 9:56 am

Post by DarioE »

Thanx kduke, thanx ray.
It works and is in production already :-))
Post Reply