Return to the ProgTips Tips
Using CHGPF to handle file changes with ease.
When the structure of a physical file changes, most AS/400 programmers take the following steps to incorporate the change:
a. Change the DDS to reflect the new structure.
b. Make a copy of the data from the old structure file.
c. Delete any logical files based on the physical file.
d. Recompile the source and rebuild any logical files.
e. Copy the old data back to the new structure, specifying options *DROP and *MAP.
You can use the CHGPF command to achieve the same goal with less effort. When you need to recompile because of a change in file structure, follow these steps:
a. Make the necessary changes to the DDS source.
b. Type CHGPF and press F4 to display the screen below:
Change Physical File (CHGPF) Type choices, press Enter. Physical file . . . . . . ARETURNS Name Library . . . . . . . . INVLIB Name, *LIBL, *CURLIB System . . . . . . . . . . *LCL *LCL, *RMT, *FILETYPE Source file . . . . . . . QDDSSRC Name, *NONE Library . . . . . . . . SRCLIB Name, *LIBL, *CURLIBEnter the name of the physical file and the name of the library in which the file resides. Also type the source physical file name and the name of the library in which the source file resides.
c. Press Enter to display the screen below:
Change Physical File (CHGPF) Type choices, press Enter. Physical file . . . . . . . ARETURNS Name Library . . . . . . . . . INVLIB Name, *LIBL, *CURLIB System . . . . . . . . . . . *LCL *LCL, *RMT, *FILETYPE Source file . . . . . . . . QDDSSRC Name, *NONE Library . . . . . . . . . SRCLIB Name, *LIBL, *CURLIB Source member . . . . . . . *FILE Name, *FILE Source listing options . . . *SRC, *NOSRC,*SOURCE... + for more values Generation severity level . 20 0-30 Flagging severity level . . 0 0-30 Delete dependent logical file *NO *NO, *YES Remove constraint . . . . . *RESTRICT *RESTRICT, *REMOVE Expiration date for member . *NONE Date, *SAME, *NONEEnter the source member name, and press Enter. This step recompiles the physical and logical files and copies data back. In fact, it does all the steps you've been doing manually.
Note that when you change the DDS to reduce a field's size or drop a field, you may receive a message warning that you may lose your data. You can ignore the message by responding to it with I(gnore).
You can use a similar technique to delete all the logical files based on a physical file. Rather than using the DSPDBR command to find all dependent logicals and then deleting them one by one, simply use the CHGPF command as described above and specify *YES for "Delete dependent logical file" on the second screen to delete all dependent files.
The above tip was published in NEWS/400 by Vijay Yadav
[report a broken link by clicking here]