SELECTINDEX statement
Syntax
SELECTINDEX index [ ,alt.key] FROM file.variable [TO
list.number]
Description
Use the SELECTINDEX statement to create select lists from secondary indexes.
file.variable specifies an open file.
index is an expression that evaluates to the name of an indexed field in the file. index must be the name of the field that was used in the CREATE.INDEX command when the index was built.
list.number is an expression that evaluates to the select list number. It can be a number from 0 through 10. The default list number is 0.
alt.key is an expression that evaluates to an alternate key value contained in the index. If alt.key is specified, a select list is created of the record IDs referenced by alt.key. If alt.key is not specified, a select list is created of all of the index's alternate keys.
If the field is not indexed, the select list is empty, and the value of the STATUS function is 1; otherwise the STATUS function is 0. If index, alt.key, or file.variable evaluates to the null value, the SELECTINDEX statement fails and the program terminates with a run-time error message.
PIOPEN Flavor
In a PIOPEN flavor account, the SELECTINDEX statement creates a select list from the secondary indexes without duplicate keys. To implement this functionality in other flavors, use the PIOPEN.SELIDX option with the $OPTIONS statement.
Example
In the following example, the first SELECTINDEX selects all data values to list 1. The second SELECTINDEX selects record IDs referenced by STOREDVAL to list 2.
OPEN "", "DB" TO FV ELSE STOP "OPEN FAILED"
SELECTINDEX "F1" FROM FV TO 1
EOV = 0
LOOP
SELECTINDEX "F1" FROM FV TO 1
UNTIL EOV DO
SELECTINDEX "F1", STOREDVAL FROM FV TO 2
EOK = 0
LOOP
READNEXT KEY FROM 2 ELSE EOK=1
UNTIL EOK DO
PRINT "KEY IS ":KEY:" STOREDVAL IS ":STOREDVAL
REPEAT
REPEAT
END