xHarbour Reference Documentation > Command Reference xHarbour Developers Network  

SET INDEX

Opens one or more index files in the current work area.

Syntax

SET INDEX TO [<cIndexFile,...>] [ADDITIVE]

Arguments

TO <cIndexFile,...>
The names of the index files to open in the current work area can be specified as a comma separated list of literal file names or character expressions enclosed in parentheses. When this option is omitted, all index files open in the current work area are closed.
ADDITIVE
This option is only useful when <cIndexFile,...> is specified. In this case, the files are opened in addition to already open files. If ADDITIVE is omitted, all open index files are closed prior to opening new ones.

Description

The SET INDEX command opens index files in the current work area. The first index file specified becomes the controlling index. If the file contains multiple indexes, the first index in the multiple index file becomes the controlling index.

All open indexes are closed when SET INDEX is issued, unless the ADDITIVE option is used.

After the indexes are opened, the record pointer is positioned on the first logical record of the controlling index, unless the ADDITIVE option is used. ADDITIVE neither changes the controlling index nor the record pointer.

The command SET ORDER can later be used to change the controlling index.

Info

See also:CLOSE, DbClearIndex(), DbSetIndex(), INDEX, OrdListAdd(), REINDEX, SET ORDER, USE
Category: Database commands , Index commands
Source:rdd\dbcmd.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example creates three index files holding one index each.

   PROCEDURE Main
      USE Customer
      INDEX ON Upper(FirstName)           TAG FName TO Cust01
      INDEX ON Upper(LastName+Firstname)  TAG LName TO Cust02
      INDEX ON Upper(City)                TAG City  TO Cust03

      ? IndexOrd(), IndexKey()     // result: 1 Upper(City)

      SET INDEX TO Cust01, Cust02
      ? IndexOrd(), IndexKey()     // result: 1 Upper(FirstName)

      SET ORDER TO TAG LName
      ? IndexOrd(), IndexKey()     // result: 2 Upper(LastName+FirstName)

      SET INDEX TO Cust03 ADDITIVE
      ? IndexOrd(), IndexKey()     // result: 2 Upper(LastName+FirstName)

      SET ORDER TO 3
      ? IndexOrd(), IndexKey()     // result: 3 Upper(City)

      CLOSE Customer
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe