Creating a logical file with more than one record format

A multiple-format logical file allows you to use records from two or more physical files by referring to only one logical file.

Each record format of such a multiple-format logical file is always associated with one or more physical files. You can use the same physical file in more than one record format.

The following example shows the data description specifications (DDS) for a physical file, ORDDTLP, built from a field reference file:

|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
     A* ORDER DETAIL FILE (ORDDTLP) - PHYSICAL FILE RECORD DEFINITION
     A                                      REF(DSTREF)
     A          R ORDDTL                    TEXT('Order detail record')
     A            CUST      R
     A            ORDER     R
     A            LINE      R
     A            ITEM      R
     A            QTYORD    R
     A            DESCRP    R
     A            PRICE     R
     A            EXTENS    R
     A            WHSLOC    R
     A            ORDATE    R
     A            CUTYPE    R
     A            STATE     R
     A            ACTMTH    R
     A            ACTYR     R
     A

The following example shows the DDS for the ORDHDRP physical file:

|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
     A* ORDER HEADER FILE (ORDHDRP) - PHYSICAL FILE RECORD DEFINITION
     A                                      REF(DSTREFP)
     A          R ORDHDR                    TEXT('Order header record')
     A            CUST      R
     A            ORDER     R
     A            ORDATE    R
     A            CUSORD    R
     A            SHPVIA    R
     A            ORDSTS    R
     A            OPRNME    R
     A            ORDMNT    R
     A            CUTYPE    R
     A            INVNBR    R
     A            PRTDAT    R
     A            SEQNBR    R
     A            OPNSTS    R
     A            LINES     R
     A            ACTMTH    R
     A            ACTYR     R
     A            STATE     R
     A

The following example shows how to create a logical file ORDFILL with two record formats. One record format is defined for order header records from the ORDHDRP physical file; the other is defined for order detail records from the ORDDTLP physical file.

The logical file record format ORDHDR uses one key field, Order, for sequencing; the logical file record format ORDDTL uses two keys fields, Order and Line, for sequencing.

The following example shows the DDS for the ORDFILL logical file:

|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
     A* ORDER TRANSACTION LOGICAL FILE (ORDFILL)
     A          R ORDHDR                    PFILE(ORDHDRP)
     A          K ORDER
     A
     A          R ORDDTL                    PFILE(ORDDTLP)
     A          K ORDER
     A          K LINE
     A
To create the logical file ORDFILL with two associated physical files, use a Create Logical File (CRTLF) command in the following way:
CRTLF  FILE(DSTPRODLB/ORDFILL)
       TEXT('Order transaction logical file')
The DDS source is in the ORDFILL member of the QDDSSRC file. The ORDFILL file with a member of the same name is placed in the DSTPRODLB library. The access path for the ORDFILL logical file member arranges records from both the ORDHDRP and ORDDTLP files. Record formats for both physical files are keyed on Order as the common field. Because of the order in which they were specified in the logical file description, they are merged in Order sequence with duplicates between files retrieved first from the ORDHDRP header file and second from the ORDDTLP detail file. Because FIFO, LIFO, or FCFO are not specified, the order of retrieval of duplicate keys in the same file is not guaranteed.
Note: In some circumstances, it is better to use multiple logical files, rather than to use a multiple-format logical file. For example, when keyed access is used with a multiple-format logical file, it is possible to experience poor performance if one of the files has very few records. Even though there are multiple formats, the logical file has only one index, with entries from each physical file. Depending on the kind of processing being done by the application program (for example, using RPG SETLL and READE with a key to process the small file), the system might have to search all index entries in order to find an entry from the small file. If the index has many entries, searching the index might take a long time, depending on the number of keys from each file and the sequence of keys in the index. (If the small file has no records, performance is not affected, because the system can take a fast path and avoid searching the index.)