Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

Previous sectionNext section


Reads the next key and item id from an index.


READNEXT KEY keyname,itemID FROM slist [THEN statements] [ELSE statements]


keyname A variable used to receive the key name from the select list.
itemID A variable used to receive the key item ID from the select list.
slist A select list to an existing index. A named select list specified as a variable name.


The READNEXT KEY statement reads successive key identifiers from a select list, one key identifier per invocation. READNEXT KEY returns both the key name and the key item ID. The key identifier is read from the slist select list into the itemID variable.

READNEXT KEY is used on a select list created by either a SELECT or a SELECT ATKEY.

You can optionally specify a THEN clause, an ELSE clause, or both a THEN and an ELSE clause. READNEXT KEY executes the THEN clause if the select list pointer has not reached the end of the select list. The THEN clause is executed even when a key identifier is the null string. READNEXT KEY executes the ELSE clause if the select list pointer has reached the end of the select list, or the select list does not exist. The statements argument can be the NULL keyword, a single statement, or a block of statements terminated by the END keyword. A block of statements has specific line break requirements: each statement must be on its own line and cannot follow a THEN, ELSE, or END keyword on that line.


The following example used OPENINDEX to open an index to VOC on the attribute F1. The SELECT selects this index to a select list. The READNEXT KEY reads an item from the select list:

SELECT Idx.Fp TO Idx.List
Copy code to clipboard

See Also