Use FOR FIRST versus FIND
- Last Updated: October 5, 2023
- 1 minute read
- OpenEdge
- Version 13.0
- Documentation
The FIND statement retrieves a single record in a single statement. It has its
limitations, however, when compared to a FOR block. A
FIND statement always uses only one index and does not allow use of
field lists or word indexes. By contrast, a FOR block can use multiple
indexes to evaluate a complex WHERE clause that involves fields not
found in a single index. A FOR block can also use a word index and the
CONTAINS keyword to locate records, and supports the use of a field
list to retrieve only a subset of the fields from the selected records. Both word
indexes and field lists are briefly described in Use indexes properly and
Define efficient queries and FOR EACH statements. You can use the form FOR FIRST
when fetching just a single record, if any of the conditions apply that would give it a
performance advantage. Of course, the FOR FIRST construct involves
creating a block, which has an overhead of its own that the FIND
statement does not have. Therefore, it is good practice not to use FOR
FIRST in all cases unless you have a specific reason.
Another possible advantage of the FOR FIRST (and FOR
LAST) construct is that the data in the record buffer is still available
after leaving the block. Note that this is different from a FOR EACH
construct in which the buffer is released for the next record that satisfies the
WHERE clause.