Try OpenEdge Now
skip to main content
ABL Essentials
Procedure Blocks and Data Access : Language statements that define blocks : Data access without looping: the FIND statement : Using a USE-INDEX phrase to force index selection
Using a USE-INDEX phrase to force index selection
You can also force a retrieval sequence with the USE-INDEX phrase. For instance, if you want to find the next set of Customers based on the Customer name, you can use the Name index, which contains just that one field:
FIND FIRST Customer NO-LOCK WHERE Customer.Country = "USA".
DISPLAY Customer.CustNum Customer.Name Customer.Country.
  FIND NEXT Customer WHERE Customer.Country = "USA" USE-INDEX NAME NO-ERROR.
    DISPLAY Customer.CustNum Customer.Name FORMAT "x(20)"
      Customer.Country Customer.PostalCode.
The output shown in the following figure confirms that the AVM is walking through the records in Name order, starting with the name of the first Customer in the USA.
Figure 21. Result of forcing index selection
This technique can be very valuable in expressing your business logic in your procedures. You might need to identify a record based on one characteristic and then retrieve all other records (or perhaps just one additional record) based on some other characteristic of the record you first retrieved. This is one of the most powerful ways in which ABL lets you define your business logic without the overhead and cumbersome syntax required to deal with all data access in terms of sets.