![]() ![]() |
|
SELECTINDEXThis 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.
COMMAND SYNTAXSELECTINDEX index-name{,index-key} FROM file-var {TO select-var}
SYNTAX ELEMENTSindex-name must correspond to the name of a valid index created on the
file that has been opened to the file descriptor file-var.
NOTESGiven an opened file descriptor 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. 13640) instead of the external representation (e.g. "05-MAY-2005").
EXAMPLE 1If 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
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.
EXAMPLE 2If you had an index on a date field, the following jBC code would be correct if you were looking for all records whose date is "23-July-1970".
|