Functions and Directives

Function DbCreateIndex() Foundation

Creates an index file in a work area.

Syntax
DbCreateIndex( <cIndexFile> , ;
               <cIndexKey>  , ;
              [<bIndexKey>] , ;
              [<lUnique>]     ) --> NIL
Parameters
<cIndexFile>
<cIndexFile> is a character string containing the file name of the index file to be created. The file name can be specified without path or file extension.
<cIndexKey>
<cIndexKey> is an expression in the form of a character string specifying the value to be included in the index file for each data record in the work area.
<bIndexKey>
<bIndexKey> is a code block which is evaluated during the index generation for each record in the work area. The return value of the code block is included in the index file. If the code block is not specified, it is created from the character string <cIndexKey>using the macro operator.
<lUnique>
<lUnique> is a logical value specifying whether multiple data records having the same index key are each included in the index file. When the value is .T. (true), a unique index is created where each key value appears only once. If <lUnique> is not specified, the setting of Set(_SET_UNIQUE) is used.
Return

The return value of DbCreateIndex() is always NIL.

Description

The function DbCreateIndex() exists for compatibility reasons. The function OrdCreate() should be used instead of DbCreateIndex().

The index function DbCreateIndex() creates an index file in a work area. When the function is used without the alias operator, it generates the index file in the current work area. The function is similar to OrdCreate(), but can only create one index per index file. If index files are already open in the work area, they are closed prior to the generation of the new index. The new index becomes the controlling index and the record pointer is positioned on the first logical record of the new index.

Before the call of DbCreateIndex(), a database file must be exclusively opened in the work area.

The command INDEX ON can be used instead of DbCreateIndex(). INDEX ON is only effective in the current work area.

Examples
DbCreateIndex()
// The example generates two index files for a customer file. 
// The first index contains only unique records. 

PROCEDURE Main 

   USE Customer ALIAS Cust NEW EXCLUSIVE 
   DbCreateIndex("CUSTA", "CUSTNO", {|| CUSTNO }, .T. ) 

   DbCreateIndex("CUSTB", "Upper(LASTNAME+FIRSTNAME)" , ; 
                       {|| Upper(LASTNAME+FIRSTNAME) } ) 

   SET INDEX TO CUSTA, CUSTB 

   ? IndexOrd()                // result: 1 
   ? IndexKey( IndexOrd() )    // result: CUSTNO 

     DbSetOrder(2) 
   ? IndexOrd()                // result: 2 
   ? IndexKey( IndexOrd() )    // result: Upper(LASTNAME+FIRSTNAME) 

   CLOSE Cust 

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.