Notes:
This statement will create a dynamic array of record keys based on a single selection of a single index key value. It is more efficient to use a combination of OPENINDEX and READNEXT statements rather than the SELECTINDEX, but this statement was included for compatibility with legacy applications.
Syntax:
SELECTINDEX index-name{,index-key} FROM file-var {TO select-var}
Description:
Given an opened file descriptor "file-var" this statement will select all the record keys in this file , sorted by the index definition "index-name".
An optional variable "index-key" can be used to restrict this selection to a single index key value. The value of "index-key" will be the raw value of the index data -- no lookup code processing will be done on this value. For example if the index was created as a numeric field with a D2 lookup code, the values in "index-key" would be the numeric date (e.g. 10471) instead of the extrernal representation (e.g. "20-FEB-1926").
Example:
If we assume a file called CUSTOMERS exists, and an index definition exists called NAME , then the following code will display all the record keys which have the name "SMITH". Note that the name must be exactly SMITH, a name such as SMITHY will not be included
filename = "CUSTOMERS" OPEN filename TO filevar ELSE STOP 201,filename SELECTINDEX "NAME","SMITH" FROM filevar TO smith.list LOOP WHILE READNEXT KEY index.value,record.key FROM smith.list DO CRT index.value,record.key REPEAT
In the above example the variable ‘index.value’ will always be returned as a "" string. This is because normal select lists only contain record keys and multi-value numbers. In the above example it would perhaps be more appropriate to use the following loop
LOOP WHILE READNEXT record.key FROM smith.list DO CRT record.key REPEAT
http://807199.827977/r5/knowledgebase/manuals/3.0/SecondaryIndexes/html/selectindex.htm last modified on 06/19/09 05:29 AM