Logical files do not contain data. They are nothing but a file of pointers that represent a different view of your data. More concisely, each pointer contains the address of a record in a physical file that contains the data. Logical files most often are used to create a new access path over existing data. For example, you can create a logical file to define a different key and/or to omit records from a file.
Logical files also can be used to join two or more files together. This technique is explained in the join logical files section.
The DDS for a logical file is entered in a source file member (type LF). When you are done coding it, you can compile the source (creating the file) using the Create Logical File (CRTLF) command.
Go back to the VNDMST physical file defined in the section on physical files. You might need to process its records, not by the vendor number (the physical file key), but by the zip code, if you are doing a massive mailing campaign to your vendors. For example, suppose you want to send holiday cards to your vendors. You choose a zip code sequence to take advantage of discounts offered by the postal service. Figure 22.4 represents the DDS for a logical file, keyed by zip code.
Figure 22.4: Defining alternate keys with a logical file.
The record-level keyword PFILE names the physical file (VNDMST in this case) over which you are building this logical file. Following that, you name the new key field (or fields) to the file.
If you need to process the vendor records by reverse zip code order (beginning with 99999 and ending with 00000), add the DESCEND keyword on the line that defines the key field, as shown in Figure 22.5.
Figure 22.5: Defining alternate key sequences with DDS.
In both cases, the file will allow duplicate keys because nounique keyword exists. Most logical files use duplicate keys, because they provide a key that is different from the physical file key, which usually identifies a record.
Logical files also can select and omit records from the access path. If you wanted to send holiday cards to all vendors to whom you owe $5,000 or more, code the DDS as shown in Figure 22.6.
Figure 22.6: Selecting and omitting records with a logical file.
The ‘S’ in 17 defines a select specification. It defines which records to include in the access path of the logical file. The records included will be those whose VNDUE field is greater than or equal to 5000.00. The COMP keyword compares the field value against the literal included within.
Note that the comparison operator is GE, not *GE as it would be in CL (i.e., there is no asterisk)
If you wanted to include vendors to whom you owe $5,000 or more, but not more than $10,000, code the DDS as shown in Figure 22.7.
Figure 22.7: Selecting and omitting records with DDS.
In this case, two selection specifications are present. The absence of an ‘S’ on the second one means that the two comparisons are combined with an AND. Therefore, the selection means "select records with VNDUE greater than or equal to 5000, and less than or equal to 10000." If you had placed an ‘S’ on the second line, the two lines would have been connected with an or operator.
Because you are describing a range of values you want to consider valid for VNDUE, you can shorten the code by usings the RANGE keyword instead, as shown in Figure 22.8.
Figure 22.8: Selecting and omitting records using the RANGE keyword in DDS.
Now, suppose you still want this selection, but you don't want to include vendors in California, Oregon, and Washington (state codes CA, OR, and WA). You can code as shown in Figure 22.9.
Figure 22.9: Selecting and omitting records using the VALUES keyword in DDS.
The ‘O’ (the letter, not a zero) in 17 describes an omission specification. All records having CA, OR, or WA in VNSTE will be omitted.