Progress
Programming
Handbook


FIND Repositioning

After executing FOR EACH statements or FIND statements, Progress might reposition subsequent FIND statements to the last record fetched (except for FIND statements occurring in PRESELECT blocks). For repositioning to occur, the same record buffer must be used. Also, repositioning after FOR EACH statements can differ between Version 8.0B and Versions 8.0A and earlier, depending on the options you use.

NOTE: Repositioning does not occur for a subsequent FIND if the FIND specifies a unique key (that is, the FIND does not use the NEXT or PREV options).

Repositioning After FIND Fetches

Progress 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. 
DISPLAY cust-num name country  postal-code. 
PAUSE. 
FIND NEXT customer USE-INDEX country-post. 
DISPLAY cust-num name country postal-code. 

In the country–post index, the next record after customer 1 is customer 21. Progress 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 WHERE cust-num > 5. 
DISPLAY cust-num name. 
PAUSE. 
FIND NEXT customer WHERE cust-num > 1. 
DISPLAY cust-num name. 

The first FIND statement causes Progress to reposition the cust–num index cursor to point to customer 6. The second FIND statement begins the search from that location, not from the beginning of the cust–num index.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095