bdfp1m0gProgramming Concepts and Reference

Grouping LRECs Together Using the Unique Key Facility

Suppose you want to store a large quantity of data about customers by using different LREC types for different parts of the data.

For example, suppose the information is to be stored in a file using three different types of LRECs:

LREC ID
Information held

 X'80' 
Customer name, held in a variable-length field called zzzzNAM.

 X'90' 
Customer address.

 X'A0' 
Additional information, only applicable for certain customers.

You need some method of indicating that all the LRECs for a particular customer are related. You can implement this requirement in a variety of ways. A simple method is to repeat the name field (as a fixed-length field) in each LREC, but this can waste a lot of space. A better way is to use the unique keys.

Using Unique Keys

You can use unique keys to indicate that LRECs are related. To do this, define a unique key field in each LREC and call the DBUKY macro or dfuky function to provide you with a unique key to insert in this field in each LREC.

The process is as follows:

  1. Before adding a new customer name LREC to the file, call the DBUKY macro or dfuky function to get a new unique key. The TPFDF product places this 4-byte key in a field in SW00SR slot SW00UKY.
  2. Store the unique key in a user field of each related LREC (for example, all the LRECs relating to a particular customer).
  3. Ensure the DSECT has the additional 18-byte header extension.

The result is shown in Figure 3. One 4-byte unique key field exists in each LREC. This example shows the unique keys in the same relative position in each LREC, but this is not necessary.

Figure 3. Example of LRECs Related by Unique Key Fields