2 Sort Statements and Functions

The FIND Statement

The FIND statement selects a subset of records from the data base thread or the current workfile if the workfile is non-empty.

The parameter is:

condition
Any numeric expression used to test variables (or any attribute) for certain conditions. If these conditions are met, the expression has a non-zero (true) result and the record pointers are stored in the workfile. Otherwise, the result is 0 and the record pointers are not stored.
If the workfile has not been used with any previous FIND or SORT BY operation, FIND examines the data base associated with the current workfile. The condition parameter is evaluated to determine whether the group of data entries just read should have their pointers put in the workfile. If the condition is met, the pointers are stored and the next group of entries are processed. Otherwise, the pointers are not stored and processing continued. Note that FIND must actually read each record and trigger the IN DATA SET for each set in the thread to establish the variable values it needs to evaluate the condition expression.

If the workfile already contains pointers (indicated by REC greater than 0), only the data entries specified by the pointers in the workfile are checked by the condition parameter. Pointers to data entries that meet the condition criteria are retained in the workfile; all other pointers are deleted.

Since FIND handles record pointers in the data base, and since other users may be modifying the data base, care should be taken when using FIND while the data base is opened in mode 1.

Specifying FIND ALL is the same as FIND 1=1, and is useful to get all records in unsorted order. If a subsequent FIND or SORT BY is used, however, the FIND ALL is not needed and only wastes time. If a FIND, SORT BY, or PRINT # has previously been done, FIND ALL has no effect except to reset the record pointer to record 1.

There are two miscellaneous items concerning FIND. The first is that executing a FIND resets the workfile pointer (as determined by REC) to 1. The second is that if FIND is reading the data base via pointers in the workfile and deletions have occurred in sets involved in the FIND, then FIND will delete the logical workfile records containing pointers to empty data set records.

NOTE: If the condition parameter does not use values from a particular set in the thread (via an IN DATA SET statement), execution time can be improved by deacticating the IN DATA SET statement using the FREE option.

Some examples sequences using FIND are:

    FIND TRIM$(Order_no$)>"1000"
    FIND (Vendor_no>250) AND (Invoice_no>10000)
    FIND ALL

Eloquence Sort Manual - 19 DEC 2002