Using algorithms instead of indexing

This method of reducing I/O is especially useful where some parts of a file are more frequently accessed than others. For example, it may not be efficient to index every date in a flight file when only the earlier dates are being accessed frequently.

You can code a mathematical function to translate the index key (for example, date) and then use z/TPFDF algorithm #TPFDB05 to locate the ordinal directly. Alternatively, you could use the z/TPFDF user exit in segment ubd0.asm to define an algorithm of your own. See Create your own algorithm for more information about creating user-defined algorithms.

Figure 1 shows an index file with each date pointing to a separate detail subfile:
Figure 1. Subfiles accessed from an index file
Alternative text description not available.
In Figure 2, the index file is replaced by a calculated value, which is passed to the #TPFDB05 algorithm to locate the ordinal directly.
Figure 2. Subfiles accessed using algorithm #TPFDB05
Alternative text description not available.
Note: Where an uneven distribution of LRECs is likely, user-defined algorithms can generate a better distribution. For example, where passenger names are being distributed alphabetically, there are a greater number of names beginning with S than with X.

The distribution will probably be very uneven if you use algorithms #TPFDB01, #TPFDB02, or #TPFDB03. However, if you define your own algorithm, you can accommodate this difficulty by creating extra ordinals for the more common characters. See Create your own algorithm for more information about user-defined algorithms.