Find first

Command group Flag affected Reversible Execute on client Platform(s)
Finding data YES YES NO All

Syntax

Find first on field-name ([Use search][,Use sort])

Options

Use search If specified, the command uses the current search to select data
Use sort If specified, the command uses the current sort field(s) to order the data

Description

This command automatically locates the first record in a file using the index for the specified field. If no field is given, the record sequence number is used. The main and connected files are read into the CRB if a valid first record is found. The flag is set false if no record is found.

You use the Use search option in conjunction with the specified indexed field to select the first record which fulfils the search specification. If the search is a calculation, the optimizer will choose the best index if the index field is left blank.

You use the Use Sort option in conjunction with the current sort fields (see Set sort field) to create a table of entries from the data file which are sorted into an order set by up to nine sort fields.

The find table is cleared if:

If you use the Find first command within a reversible block, it is reversed when the method finishes, that is, the main and connected records are restored. However, if the data within the original record has been deleted or changed, it will not be possible to completely restore the buffer.

Example

# Find the first account with a negative balance, but restore
# the original record when this method finishes
Begin reversible block
  Set main file {fAccounts}
  Set search as calculation {fAccounts.Balance<0}
  Find first on fAccounts.Code (Use search)
End reversible block