Find

See Also: Understanding File Buffers and DDO Field Buffers, Found indicator, Clear, Constrained_Clear, Constrained_Find, Open, VFind

Purpose

To retrieve a record from a database table on disk, and place it in the record buffer. The DataDictionary class provides superior functionality that replaces the need for this command.

Syntax 1

Find LT | LE | EQ | GE | GT  {table} By  Recnum | {IndexNumber}

Syntax 2

Find LT | LE | EQ | GE | GT  {table.column}

Where

What It Does

The Find command locates a record in {table} based on the data in the record buffer, the index selected, and the find mode (LT, LE, EQ, GE, or GT) specified.

If the Find command is successful (see below), the found record is read from the disk into the record buffer, the record buffer becomes "Active" (it contains a valid record from the database). Subsequent calls to the Boolean expression Found will return TRUE.

If the Find command is not successful, the Boolean expression Found will return FALSE and the record buffer remains as it was prior to the find.

The Find command uses one of 5 modes for the relationship between the data in the buffer and the data in the found record:

LT record data LESS THAN buffer data

LE record data LESS THAN OR EQUAL TO buffer data

EQ record data EQUAL TO buffer data

GE record data GREATER THAN OR EQUAL TO buffer data

GT record data GREATER THAN buffer data

Index comparisons take into account the sorting order of the index segments (ascending or descending) when calculating which value is greater. Consider a database table "Scientists" where index 1 is sorted on a Name column in ascending order and index 2 is sorted on the same column, but in descending order.

Example

Suppose there are five names in the database: "Cindy", "Marcia", "Oscar", "Sean", and "Scott". The example below illustrates how the order of the index affects the behavior of the Find Command.

Open Scientists

Move "Oscar" to Scientists.Name

Find Gt Scientists By 1

// The record just found will be the record with "Sean"

Move "Oscar" to Scientists.Name

Find LT Scientists By 1

// The record just found will be the record with a name column of "Marcia"

Move "Oscar" to Scientists.Name

Find Gt Scientists By 2

// The record just found will be the record with a name column of "Marcia"

Move "Oscar" to Scientists.Name

Find LT Scientists By 2

// The record just found will be the record with a name column of "Sean"

Close Scientists

Find GT on a clear buffer will find the first record of the table for the given index. Find LT will return the last record in the index.

There are two forms of the Find command:

1. Naming the index explicitly, by number:

Find GE customer By 3

In this example, Index 3  is used to find a record in Database File customer. The first record will be found according to Index 3 whose value(s) in the column(s) which make up Index 3 is greater than or equal to (GE) the value(s) previously put into the record buffer for the column(s).

2. Naming the column whose main index is to be used:

Find GE customer.name

The main index for the column "name" of the database table customer is used for the Find command.

Notes

For example

Move 999999 to Customer.Customer_number

// Index 1 is on customer_number

Find GE Customer by 1

In the above example code, if the highest customer number is less than 999999, the last customer record in index 1 will be found.