Changing a physical file description and attributes

 

Sometimes when you make a change to a physical file description and then re-create the file, the level identifier can change. If the level identifier changes, you can either compile the program again or avoid recompiling using a logical file.

For example, the level identifier changes if you add a field to the file description, or change the length of an existing field. If the level identifier changes, you can compile the program again that uses the physical file. After the program is recompiled, it uses the new level check identifier.

You can avoid compiling again by creating a logical file that presents data to your programs in the original record format of the physical file. Using this approach, the logical file has the same level check identifier as the physical file before the change.

For example, you decide to add a field to a physical file record format. To avoid compiling your program again, follow these steps:

  1. Change the DDS and create a new physical file (FILEB in LIBA) to include the new field:
    CRTPF FILE(LIBA/FILEB) MBR(*NONE)...

    FILEB does not have a member. (The old file FILEA is in library LIBA and has one member MBRA.)

  2. Copy the member of the old physical file to the new physical file:
    CPYF    FROMFILE(LIBA/FILEA) TOFILE(LIBA/FILEB)
            FROMMBR(*ALL) TOMBR(*FROMMBR)
            MBROPT(*ADD) FMTOPT(*MAP)

    The member in the new physical file is automatically named the same as the member in the old physical file because FROMMBR(*ALL) and TOMBR(*FROMMBR) are specified. The FMTOPT parameter specifies to copy (*MAP) the data in the fields by field name.

  3. Describe a new logical file (FILEC) that looks like the original physical file (the logical file record format does not include the new physical file field). Specify FILEB for the PFILE keyword. (When a level check is done, the level identifier in the logical file and the level identifier in the program match because FILEA and FILEC have the same format.)

  4. Create the new logical file:
    CRTLF FILE(LIBA/FILEC)...

  5. You can now perform one of the following operations:

    1. Use an Override with Database File (OVRDBF) command in the appropriate jobs to override the old physical file referred to in the program with the logical file (the OVRDBF command parameters are described in more detail in Database file processing: Runtime considerations).
      OVRDBF FILE(FILEA) TOFILE(LIBA/FILEC)

    2. Delete the old physical file and rename the logical file to the name of the old physical file so the file name in the program does not have to be overridden.
      DLTF FILE(LIBA/FILEA)
      RNMOBJ   OBJ(LIBA/FILEC) OBJTYPE(*FILE)
               NEWOBJ(FILEA)

The following tables illustrate the relationship of the record formats used in the three files.

Table 1. FILEA (old physical file)
FLDA FLDB FLDC FLDD

In FILEB, FLDB1 was added to the record format.

Table 2. FILEB (new physical file)
    FLDB1    

FILEC shares the record format of FILEA. FLDB1 is not used in the record format for the logical file.

Table 3. FILEC (logical file)
FLDA FLDB FLDC FLDD

When you make changes to a physical file, which causes you to create the file again, all logical files referring to it must first be deleted before you can delete and create a new physical file. After the physical file is re-created, you can re-create or restore the logical files referring to it.

 

Parent topic:

Changing database file descriptions and attributes