Condividi tramite


SEEK Command

Searches a table for the first occurrence of a record whose index key matches a general expression, then moves the record pointer to the matching record.

SEEK eExpression   [ORDER nIndexNumber | IDXIndexFileName
    | [TAG] TagName [OF CDXFileName]    [ASCENDING | DESCENDING]]
   [IN nWorkArea | cTableAlias]

Parameters

  • eExpression
    Specifies the index key for which SEEK searches. eExpression can be null.

  • ORDER nIndexNumber
    Specifies the number of the index file or tag that is used to search for the index key. nIndexNumber refers to the index files as they are listed in USE or SET INDEX. Open .idx files are numbered first in the order in which they appear in USE or SET INDEX. Tags in the structural .cdx file (if one exists) are then numbered in the order in which they were created. Finally, tags in any open independent .cdx files are numbered in the order in which they were created. See SET ORDER for more information about index numbering.

  • ORDER IDXIndexFileName
    Specifies an .idx file that is used to search for the index key.

  • ORDER [TAG] TagName [OF CDXFileName]
    Specifies a tag of a .cdx file that is used to search for the index key. The tag name can be from a structural .cdx file or any open independent .cdx file.

    If identical tag names exist in open independent .cdx files, use OF CDXFileName to specify the .cdx file containing the tag.

    Note   The .idx file takes precedence if duplicate .idx file and tag names exist.

  • ASCENDING
    Specifies that the table is searched in ascending order.

  • DESCENDING
    Specifies that the table is searched in descending order.

  • IN nWorkArea
    Specifies the work area number of the table that is searched.

  • IN cTableAlias
    Specifies the alias of the table that is searched.

    If you omit IN nWorkArea and IN cTableAlias, the table in the currently selected work area is searched.

Remarks

You can use SEEK only with indexed tables, and you can search only on the index key. The match must be exact unless SET EXACT is set to OFF.

If SEEK finds a record with a matching index key, RECNO( ) returns the record number of the matching record, FOUND( ) returns true (.T.), and EOF( ) returns false (.F.).

If a matching key isn't found, RECNO( ) returns the number of records in the table plus 1, FOUND( ) returns false (.F.), and EOF( ) returns true (.T.).

If SET NEAR is on, the record pointer is positioned immediately after the record with the closest index key. If SET NEAR is off, the record pointer is positioned at the end of the file. In either case, RECNO() returns the record number of the closest record.

Example

In the following example, customer is opened and indexed on the company field. SEEK is used to find the index key expression that matches the value contained in the variable gcSeekVal.

CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'Data\testdata')
USE customer ORDER company  && Opens Customer table

SET EXACT OFF
STORE 'B' TO gcSeekVal
SEEK gcSeekVal

IF FOUND( )
   DISPLAY FIELDS company, contact
ENDIF

See Also

EOF( ) | FOUND( ) | INDEX | INDEXSEEK( ) | LOCATE | RECNO( ) | SEEK( ) | SET EXACT | SET NEAR