Create Logical File

DDS on IBM Power i systems defines logical files.

Logical Files

The Create Logical File (CRTLF) command creates a logical file, an object similar to an SQL index from the information specified on the CRTLF command and from the data description specifications (DDS) contained in a source file.

A logical file points to a database file and describes how data records contained in one or more physical files are presented to a program. LFs are dependent on one (or more) physical files. Logical files do not contain data records, they merely point to where the data records are stored. Normally, database files have only one member which, by default, is created with the physical file.The data records contained in the physical files may be grouped into physical file members. The logical file accesses the data records through one or more logical file members. Each logical file member describes the data contained in one or more physical file members, and each logical file member has its own access path to the data.

Selecting Data

The examples below are simple. In addition to file level, record level, and key level entries, logical files (LFs) also have an option select/omit level. This allows the logical file to determine what records are passed to the processing program. The logical file references the physical file, (ADMHDRPF) with the PFILE keyword in Fig. 1. It definines a key, and selects only those records where the field ADHSTS contains an asterisk. Omit is implied in Fig. 1. But OMIT may be explicitly defined as in Fig. 2. Multiple selection entries are permissable. Fig. 3 illustrates a selection where the CMP keyword is used to select records where the field FSTAZ is equal to 'E', and include records where the field RESBMH is set to 'Y'.

A          R RADMHDR                   PFILE(ADMHDRPF)
A          K ADHOID                                   
A          S ADHSTS                    COMP(EQ '*')   
                                                  
Fig. 1

A          R GPORTA                    PFILE(GPORTAFL)  
A          K INVDTZ                                     
A          K INVNOZ                                     
A          S EXTR8H                    COMP(EQ ' ')     
A          O                           ALL         

Fig. 2

A          R GPORTA                    PFILE(GPORTAFL)
A          K COMPNZ                                   
A          K INVNOZ                                   
A          S FSTATZ                    CMP(EQ 'E')    
A          S RESBMH                    CMP(EQ 'Y')   

Fig. 3

Derived Fields

The substring keyword (SST) is restricted to LFs. The substring begins at the starting position you specify on the SST keyword, the length is optional. The specification must be 'I' (input only) or 'N' (none). In the example below the date field ENTDTD is eight characters long. Using the SST keyword, three derived fields have been created, YEARAD, MONTAD, and DAYEAD.
Note the keyword DESCEND at the key level in the example above. The key field order defaults to ascending, but allows the data order to be organized in descending sequence.

     A          R DLORPC                    PFILE(DLORPCFL)
     A            COMPBD    R
     A            RECNOD    R
     A            INVNOD    R
     A            CSTNOD    R
     A            SLSNOD    R
     A            ORQTYD    R
     A            FRAMED    R
     A            FDESCD    R
     A            COVR1D    R
     A            COLR1D    R
     A            COVR2D    R
     A            COLR2D    R
     A            COVDSD    R
     A            FCODED    R
     A            WHSNOD    R
     A            SLPRCD    R
     A            SPCD1D    R
     A            STPRCD    R
     A            FRCSTD    R
     A            LACSTD    R
     A            MSTSTD    R
     A            OHCSTD    R
     A            CRCSTD    R
     A            YDGE1D    R
     A            YDGE2D    R
     A            SHPVAD    R
     A            TERMSD    R
     A            CATGYD    R
     A            VOLMND    R
     A            ZONE1D    R
     A            FRAMTD    R
     A            ENTDTD    R     S
     A            YEARAD             I      SST(ENTDTD 5 4)
     A            MONTAD             I      SST(ENTDTD 1 2)
     A            DAYEAD             I      SST(ENTDTD 3 2)
     A            SSDATD    R     S
     A            YEARBD             I      SST(SSDATD 5 4)
     A            MONTBD             I      SST(SSDATD 1 2)
     A            DAYEBD             I      SST(SSDATD 3 2)
     A            INVDTD    R     S
     A            YEARCD             I      SST(INVDTD 5 4)
     A            MONTCD             I      SST(INVDTD 1 2)
     A            DAYECD             I      SST(INVDTD 3 2)
     A            TRKNOD    R
     A            CSTORD    R
     A            HOWSHD    R
     A            SHBLND    R
     A            COMRTD    R
     A            DSGVND    R
     A            SKUNOD    R
     A            BOQTYD    R
     A            ADVALD    R
     A            SCHNOD    R
     A            SERNOD    R
     A            DTSCHD    R
     A            FRTCDD    R
     A            ADVCDD    R
     A            SHPCDD    R
     A            FSTATD    R
     A          K COMPBD
     A          K CSTNOD
     A          K INVNOD
     A          K FRAMED
     A          K YEARAD                    DESCEND
     A          K MONTAD                    DESCEND
     A          K DAYEAD                    DESCEND


Multiple Format Logical

In a multiple-format logical file, a record format can use only the fields common to all the physical files specified on the PFILE keyword for that record format.

|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
00010A* LOGICAL FILE EXAMPLE from IBM
00020A* INVENTORY FORMAT
00030A          R INVFMT                    PFILE(INVENTORY)
00040A          K ITEM
00050A*
00060A* ORDER FORMAT
00070A          R ORDFMT                    PFILE(ORDER)
00080A                                      TEXT(’ORDER ANALYSIS’)
00090A            ITEM
00100A            ORDER         10
00110A            SUPPLY        +2
00120A            SHPDAT                    CONCAT(SHPMO SHPDA SHPYR)
00130A            QTY            5P         RENAME(QTYDUE)
00140A          K ITEM
00150A          K SHPYR
00160A          K SHPMO
00180A          O QTYDUE                    CMP(LT 1)
00190A*
00200A* ACCOUNTING FORMAT
00210A          R ACTFMT                    PFILE(ACCOUNTS)
00220A                                      FORMAT(ACCOUNTL)
00230A          K ITEM


When creating a single or multiple-format LF, be sure to place the entries in the following order. Notice that the only required entry is the record format level.

Level Entry Order

Order Level
1 Optional: File-level entries
2 Record-level entries
3 Optional: Field-level entries
4 Optional: Key field-level entries
5 Optional: Select/omit field-level entries