Using the Hash Iterator Object
About the Hash Iterator Object
Use the hash iterator object to store and search data based on lookup keys. The hash
iterator object enables you to retrieve the hash object data in either forward or reverse
key order.
Declaring and Instantiating a Hash Iterator Object
You declare a hash iterator object by using the DECLARE statement. After you declare
the new hash iterator object, use the _NEW_ operator to instantiate the object. Use the
hash object name as an argument tag. For example:
declare hiter myiter;
myiter = _new_ hiter('h');
The DECLARE statement tells the compiler that the object reference MyIter is of type
hash iterator. At this point, you have declared only the object reference MyIter. It has the
potential to hold a component object of type hash iterator. You should declare the hash
iterator object only once. The _NEW_ operator creates an instance of the hash iterator
object and assigns it to the object reference MyIter. The hash object, H, is passed as a
constructor argument. The hash object, not the hash object variable, is specifically
assigned to the hash iterator.
As an alternative to the two-step process of using the DECLARE statement and the
_NEW_ operator to declare and instantiate a component object, you can declare and
instantiate a hash iterator object in one step by using the DECLARE statement as a
constructor method. The syntax is as follows:
declare hiter object_name(hash_object_name);
In the above example, the hash object name must be enclosed in single or double
quotation marks.
For example:
declare hiter myiter('h');
The previous statement is equivalent to these:
declare hiter myiter;
myiter = _new_ hiter('h');
Note: You must declare and instantiate a hash object before you create a hash iterator
object. For more information, see “Declaring and Instantiating a Hash Object” on
page 519.
For example:
if _N_ = 1 then do;
length key $10;
declare hash myhash(dataset:"work.x", ordered: 'yes');
declare hiter myiter('myhash');
myhash.defineKey('key');
myhash.defineDone();
end;
Using the Hash Iterator Object 531