Simple Logical Files

Logical files are objects of type *FILE you can create over one or more physical files to access records differently from the way they are stored in the physical files. Although this is usually called a different view of the file, the system creates a different access path through the records. Logical files don't contain any data. Each "record" in a logical file is nothing but a pointer to the actual record in the physical file.

Logical files are divided into two major categories: simple and join.

Creating a Simple Logical File

Simple logical files can be created over one or more physical files, which can have entirely different record structures and might have no fields in common at all. Unless you choose to omit records, a simple logical file accesses all the records in all the physical files it references.

To create a logical file, you must first write DDS specifications and compile them using the Create Logical File (CRTLF) command. The CRTLF command contains two parameters that cause confusion:

  • MBR (Member). This parameter receives the name of the member, in the logical file, to be created along with the file. It defaults to *FILE, which means that the logical file is created with one member named like the file.

  • DTAMBRS (Data Members). This parameter receives the names of the physical files and physical file members from which the logical file will draw data to create the member named in the MBR parameter. This parameter defaults to *ALL, which means that the logical file member named in MBR will be based on all the files and all the members in each file that have been referenced in the DDS of the logical file.

Adding and Removing Members

After creation, you can add members to a logical file using the Add Logical File Member (ADDLFM) command or remove members using the Remove Member (RMVM) command.

The ADDLFM command contains the same pair of MBR and DTAMBRS parameters, and they mean the same as they do for the CRTLF command.

Using Simple Logical Files

Simple logical files have many uses:

  • They can provide a key to an arrival sequence file. Often, it is more convenient and efficient to create physical files without a key (in other words, arrival sequence files). Using logical files is a good idea, especially if the file contains many records or will undergo much maintenance. For example, a transaction history file can have several hundred thousand records (or even millions of records).

  • They can provide a different key to a keyed file. Sometimes you have a keyed file but, for the purposes of an application program, you need to access the records using a different key field. Logical files let you do that.

  • They let you omit records from a file. If an application program can only use records that follow a certain pattern, you can create a logical file that includes only those records that follow the pattern. The application program then doesn't need to make the selections. As far as the program is concerned, it needs to process all records.

  • They let you redefine the key. If the key to the file is on a character field that can contain uppercase and lowercase letters, a logical file is capable of disregarding the distinction between upper-and lowercase.

  • They let you combine the records of more than one member, or more than one physical file, together. Logical files can have multiple record formats.

  • They let you exclude fields from the record layout of the physical file. This is useful for files that contain sensitive or confidential information. For example, you can define a logical file on top of the Employee Master (physical) file that has the same or different key. The logical file could exclude pay rate and other confidential data. Even if all users were allowed to read the file, the confidentiality would not be compromised.

To the application program, a logical file looks just like a physical file. You code the file description and operations exactly as you would for a physical file.

IBM i5/iSeries Primer(c) Concepts and Techniques for Programmers, Administrators, and Sys[... ]ators
IBM i5/iSeries Primer(c) Concepts and Techniques for Programmers, Administrators, and Sys[... ]ators
Year: 2004
Pages: 245 © 2008-2017.
If you may any questions please contact us: