Using Indexes

Indexes on a file are set up by using the TCL commands DEFINE-INDEX and CREATE-INDEX in turn. The definition of an index is based on English select and/or selection criteria. Other associated TCL commands are DELETE-INDEX, SELECT-INDEX and VERIFY-INDEX. For more details of these, and for general information about file indexing and its advantages, refer to the User's Reference: General.

An index containing all items in a file (one defined using sort criteria but without selection criteria) is used automatically when suitable English commands are executed (at TCL or via PERFORM or from a Proc). See User's Reference: General for more details.

To use an index directly from DataBasic, you first OPEN the file on which the index is based in the usual way. Then use SELECT to attach a variable to the index.

You can then use READNEXT, READPREV, and POSITION statements (respectively) to read the next item-id, read the previous item-id, or re-position the index pointer. You can also also read the key value associated with the item-id from the index. This consists of the current values within the item of any attributes comprising the selection criteria used to define the index.