bdfp1m0pProgramming Concepts and Reference

Using Variable-Length Fields as Keys

You can use variable-length fields as key fields by indicating how much of the field must match. You can do this by specifying an L subparameter with a KEYn parameter or with field SW01LEN in a key list. However, using variable-length fields as keys can result in false matches. For example, if you use the string 'ADAMS' as a search key with a length of 5, the TPFDF product matches all the LRECs shown in Figure 7.

Figure 7. Key Fields in LRECs without a Terminating Character


One method of preventing false matches is to use a terminating character at the end of the variable-length field when each LREC is added to the file. If X'00' was used as the terminating character in our example, the entries shown in Figure 7 now become those shown in Figure 8.

Figure 8. Key Fields in LRECs with a Terminating Character


To find a match for ADAMS, you must add a X'00' character to the end of the search field.