SEEK command

Searches an indexed character field for the first value that matches the specified character expression or character string.

Syntax

SEEK search_expression

Parameters

Name Description

search_expression

The character expression to search for.

You can use any valid character expression, character variable, or quoted string. search_expression is case-sensitive, and can include leading spaces, which are treated like characters.

Examples

Locate the first value in a field that matches a character variable

The Card_Number field has been defined as a character field and is indexed in ascending order.

The example below locates the first value in the field that exactly matches, or starts with, the value contained in the v_card_num variable.

INDEX ON Card_Number TO "CardNum" OPEN
SET INDEX TO "CardNum"
SEEK v_card_num

Locate the first value in a field that matches a character string

The Card_Number field has been defined as a character field and is indexed in ascending order.

The example below locates the first value in the field that exactly matches, or starts with, the character literal "AB-123":

INDEX ON Card_Number TO "CardNum" OPEN
SET INDEX TO "CardNum"
SEEK "AB-123"

Remarks

For more information about how this command works, see Selecting the first matching record.

How it works

Use the SEEK command to move directly to the first record in a table containing the specified search_expression in the indexed character field.

  • If the search_expression is found the first matching record in the table is selected.
  • If the search expression is not found the message "No index matched key" is displayed, and the table is positioned at the first record with a greater value than the search expression.

    If there are no values in the indexed field greater than the search expression, the table is positioned at the first record.

Index required

To use SEEK to search a character field, you must first index the field in ascending order. If multiple character fields are indexed in ascending order, only the first field specified in the index is searched.

SEEK cannot be used to search non-character index fields, or character fields indexed in descending order.

Partial matching supported

Partial matching is supported. The search expression can be contained by a longer value in the indexed field. However, the search expression must appear at the start of the field to constitute a match.

The SEEK command is not affected by the Exact Character Comparisons option (SET EXACT ON/OFF).