![]() ![]() |
|
READNEXTThe READNEXT statement is extended in two ways. Firstly it can accept an index variable create with an OPENINDEX statement. An example of this is given in the description for SELECT extensions. Secondly, you can use the KEY modifier.
SYNTAX ELEMENTSREADNEXT KEY index.key{,record.key{,vmcount}} {FROM select-def} THEN/ELSE
NOTESIn this second format the READNEXT KEY statement will return the actual index key. The select used use MUST have been created with the OPENINDEX statement. You can optionally return the associated record key and the multi-value number associated with it.
EXAMPLEThe following code shows a file and index being created, a simple index just on attribute 1. The index is defined as multi-valued. Then 3 records are written to the file. The file is then interrogated with the OPENINDEX and READNEXT KEY statements. As the index is defined as an ascending left justified sort on attribute 1, the values returned with the READNEXT will be in sorted order of attribute 1.
The output of this program will be as follows:
The index is built on sorted attribute 1 and so the index keys (the names of the customers) are sorted in alphabetical order. They are then sub-sorted by record key and finally by the multi-value number that they existed in. |