1 Introduction
When a FIND is executed, pointers to some subset of the records in the hierarchy are put in the workfile. Only the pointers of records which meet the selection criteria are put in the workfile. If there are already pointers in the workfile from executing previous FINDs (or SORTs), the subset described by these pointers is used in successive FINDs and SORTs, rather than all the information present in the database.
Suppose, in the above example, you wanted to list only the orders for ABC Company. You could do this by inserting a FIND statement somewhere between line 100 and line 130 to select only those customers. Thus you could produce a report for just ABC Company by adding:
115 FIND TRIM$(Name$)="ABC Company"This line could also have gone after the SORT BY in line 120, since executing a FIND does not change the sequence produced by the last SORT BY. Note the use of TRIM$. This is necessary because FIND works like a direct-mode DBGET. The unpacking procedure performed by IN DATA SET will leave any trailing blanks on the string.
Suppose, now, that you want to put an additional restriction on the set of orders in the report. The report should contain only orders from ABC Company and those with a "2" somewhere in the order number. You can do this in either of two ways. You can add another FIND statement specifying the additional restriction between lines 100 and 130. Or you can change line 115. The first method might produce a line like:
125 FIND POS(Order_no$,"2")<>0NOTE: Now one of the FINDs is before the SORT BY and one is after it. Both could also appear before or both after the SORT BY.
The second method is a more efficient way. The fewer FIND statements executed the better, since then each data entry need be examined only once. (This is the usual case. More details on the best way to optimize FINDs are presented in Chapter 4.) This method might have produced a replacement for line 115 such as:
115 FIND (TRIM$(Name$)="ABC Company") AND (POS(Order_no$,"2")<>0)