Try OpenEdge Now
skip to main content
ABL Essentials
Procedure Blocks and Data Access : Language statements that define blocks : FOR blocks : Using the USE-INDEX phrase to force a retrieval order
 
Using the USE-INDEX phrase to force a retrieval order
If you look at all the indexes for the Order table in the Data Dictionary, you can see that there is also an index called OrderDate that uses the Order field. You can select the index to use when the default choice is not the one you want. ABL does this by adding a USE-INDEX phrase to the record phrase. This form of the FOR EACH statement is guaranteed to return the earliest OrderDate, even if it's not the lowest OrderNum:
FOR EACH Customer NO-LOCK WHERE Customer.State = "NH",
  FIRST Order OF Customer NO-LOCK USE-INDEX OrderDate:
  DISPLAY Customer.CustNum Customer.Name Order.OrderNum Order.OrderDate.
END.
The result in the following figure shows that there is indeed an earlier Order for the first of your Customers that doesn't have the lowest OrderNum.
Figure 13. Earliest Customer Order