Create 2 different Logical Files over a physical file

In only a few lines of source code, you can create a logical file. This is a way of reading the file with a different key. A logical file is a list of key values that point to the physical file. It does NOT contain copies of the data in the physical file.

To create a logical file, enter your source statements in a DDS source file member named something like "CUS01". Make sure the member type is "LF". Enter the source code in Figure 1.

The first line tells the compiler that this logical file will re-sequence the records in the physical file named in the "PFILE" specification. In this case it is the "CUST" file. Also, notice that here we are using the same record name as the physical file, "CUREC". The only remaining lines are like the last two lines of the physical file source. Then name the fields that you want to use as keys.

Compile the file by using option 14. This time, the AS/400 will execute the "CRTLF" (create logical file) command. You now can read the customer file in city / state sequence simply be reading the file "CUS01" in keyed sequence.

Now, create a logical file to select only certain records. The "S" type record will select only records that have customer status equal to "A", see Figure 2. Also, this logical file will read the records in customer name sequence. A record type of "O" could be used to omit certain records. So, a program reading this file in keyed sequence, will read the records alphabetically by customer name and will read only records of active customers.

Figure 1 - DDS for Logical File to Re-sequence Order of Records

     A          R CUREC                    PFILE(CUS)                
     A                                     TEXT('CUST BY CITY / STATE')
     A          K CUCITY                                              
     A          K CUSTAT

Figure 2 - DDS for Logical File to Select and Re-sequence

     A          R CUREC                    PFILE(CUS)                
     A                                     TEXT('CUST NAME/ACTIVE ONLY')
     A          K CUNAME                                              
     A          S CUSTAT                   COMP(EQ A) 


Back to Basic 400 Skills    |   Back to Main Page