4 Programming Considerations
Turn off all possible IN DATA SETs (via the FREE option) before doing a FIND or QFIND. If a particular IN DATA SET is active for some data set in the thread and no values from that set are needed to evaluate the selection expression, FREEing that IN DATA SET stops FIND/QFIND from reading information from that set.
Specifying the conditional expression in a QFIND statement reduces overhead against QFIND/FIND sequence, because records are only processed once.
QFIND works by appending, i.e. adding entries. This is particularly useful if data conditions are diferent.
If an item occurs in more than one set in the thread (normally because it is a search item), it should be selected to come from the set closest to the start of the thread. For FIND it is very important to notice all appropriate sets (ones with IN DATA SETs active) have been read. Thus, if the needed set can be restricted to those near the head of the thread, the expression can be evaluated sooner.
If the FIND condition is a series of conditions separated by ANDs, it may be beneficial to break them up into separate FINDs. In general, if some of the clauses pertain only to the first set in the thread and they will select significantly less than all the data available, then it is best to construct two FIND statements (the first one pertaining only to the set at the head of the thread). Remember when doing this to deactivate and reactivate the IN DATA SET relations (via FREE) to maximize effect.
In the case of FIND the same things as mentioned for SORT BY also apply. However, breaking up a complex FIND separated by ANDs into several FINDs may increase speed if (and only if) some of the clauses separated by the ANDs do not involve the same sets or involve fewer sets than the other clauses. If this is the case, the clauses which have the fewest sets involved and the lowest probability of being true should be executed first. Remember, again, that the only way FIND knows which sets are involved is by which IN DATA SETs are active. Clearly, most of these rules assume the programmer has a good understanding of the form the data will take (in terms of probable events). When in doubt, perform tests.
REC =0 | ||
---|---|---|
(no previous QFIND, FIND, SORT BY or PRINT ) | (previous FIND, SORT BY or PRINT #) | |
FIND | Keep thread lenght short. Make sure the last set with an IN DATA SET active on it is as close to the start of the thread as possible | Make sure IN DATA SET are active on only those sets from which information must be retrieved |
SORT BY | Keep thread lenght short. | Make sure sort keys come from as few sets as possible. |
ALWAYS:
1) Minimize thread length.
2) Minimize complexity of the FIND selection expression.
3) Minimize total sort key.