Try OpenEdge Now
skip to main content
Programming Interfaces
Data Management : Database Access : Fetching records : FIND repositioning : Repositioning after FIND fetches
 
Repositioning after FIND fetches
The AVM uses index cursors to keep track of what record you last fetched. This is important if you use the FIND statement to fetch a record. For example, depending on what was the last record fetched, the following statement returns a different record:
FIND NEXT Customer.
If you had last fetched the first Customer record, this statement would fetch the second Customer record. If you had just fetched the fourth Customer record, this statement would fetch the fifth Customer record.
A table can have multiple indexes, and the cursor position in each index dictates what the next record is in that index. For example, the following code fragment fetches Customers 1 and 21:
FIND FIRST Customer NO-LOCK.
DISPLAY Customer.CustNum Customer.Name Customer.Country Customer.PostalCode.
PAUSE.
FIND NEXT Customer NO-LOCK USE-INDEX country-post.
DISPLAY Customer.CustNum Customer.Name Customer.Country Customer.PostalCode.
In the country–post index, the next record after Customer 1 is Customer 21. the AVM uses the index cursor to establish the correct context.
Sometimes cursor repositioning is tricky. For example, the following code fragment returns Customer 6 and Customer 7 (you might expect Customer 6 and Customer 2):
FIND FIRST Customer NO-LOCK WHERE Customer.CustNum > 5.
DISPLAY Customer.CustNum Customer.Name.
PAUSE.
FIND NEXT Customer NO-LOCK WHERE Customer.CustNum > 1.
DISPLAY Customer.CustNum Customer.Name.
The first FIND statement causes the AVM to reposition the CustNum index cursor to point to Customer 6. The second FIND statement begins the search from that location, not from the beginning of the CustNum index.