Function DbSetIndex() Foundation

Opens an index file in a work area.

Syntax
DbSetIndex( <cIndexFile> ) --> NIL
Parameters
<cIndexFile>
<cIndexFile> is a character string containing the file name of the index file to open. The file name can be specified without the path or file extension.
Return

The return value of DbSetIndex() is always NIL.

Description

The function DbSetIndex() exists for compatibility reasons. The function OrdListAdd() should be used instead of DbSetIndex().

The index function DbSetIndex() opens an index file in a work area. When the function is used without the alias operator, DbSetIndex() opens the index file in the current work area. If no index file is open in the work area, the newly opened index becomes the controlling index for the database file in the work area. If other index files are already open, the controlling index remains unchanged. The record pointer is always positioned on the first logical record of the controlling index by DbSetIndex().

When an index file is opened in a work area, the records of the database file are logically sorted in the order specified in the index file.

The command SET INDEX or the option INDEX in the USE command can be used instead of DbSetIndex(). These commands are effective only in the current work area. The command SET INDEX closes all open files in the work area before the new one is opened.

Examples
DbSetIndex()
// In the example, two index files are created for 
// a customer file and then closed. The effect of the 
// function DbSetIndex() is illustrated. 

PROCEDURE Main 

   USE Customer NEW EXCLUSIVE 
   INDEX ON CustNo                    TO CustA 
   INDEX ON Upper(LastName+FirstName) TO CustB 

   DbClearIndex() 
   DbGoTop() 
                             // ** no index 
   ? RecNo()                 // result: 1 
   ? IndexKey(IndexOrd())    // result:   null string ("") 
   ? LastName                // result: King 

   DbSetIndex("CustB")       // ** CustB becomes controlling 
                             // ** index, record pointer changes 

   ? RecNo()                 // result: 13 
   ? IndexKey(IndexOrd())    // result: Upper(LastName+FirstName) 
   ? LastName                // result: Anderson 

   SKIP 20 
   ? RecNo()                 // result: 21 
   ? LastName                // result: Leiffer 

   DbSetIndex("CustA")       // ** CustA is opened, 
                             // ** controlling index remains 
                             // ** record pointer changes 

   ? RecNo()                 // result: 13 
   ? IndexKey(IndexOrd())    // result: Upper(LastName+FirstName) 
   ? LastName                // result: Anderson 

   CLOSE Customer 

RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.