CHGPF without losing data

5 Views


To compile a Physical File (PF) without deleting the data, you should avoid using CHGPF unless necessary, as it replaces the file and can result in loss of data if the level IDs or formats have changed.

However, if you do use CHGPF, here’s how to preserve the data:


1. CHGPF with MBROPT(*UPD)

CHGPF FILE(MYLIB/MYFILE) SRCFILE(MYLIB/QDDSSRC) SRCMBR(MYFILE) MBROPT(*UPD)
  • MBROPT(*UPD) tries to update the file instead of replacing it.

  • It retains data, but this works only if the format hasn’t changed incompatibly (e.g., same record length, fields not removed or changed type).


⚠️ When CHGPF Fails to Preserve Data

If you changed the format significantly (e.g., added or deleted fields, changed types), then:

  • CHGPF fails or deletes data.

  • In such cases, consider using CPYF to preserve data:


2. Safe Method Using CPYF

CPYF FROMFILE(MYLIB/MYFILE) TOFILE(MYLIB/MYFILEBKUP) MBROPT(*REPLACE) FMTOPT(*NOCHK)
/* Recompile the file now */
CHGPF FILE(MYLIB/MYFILE) SRCFILE(MYLIB/QDDSSRC)
/* Restore the data */
CPYF FROMFILE(MYLIB/MYFILEBKUP) TOFILE(MYLIB/MYFILE) MBROPT(*REPLACE) FMTOPT(*MAP)
  • This ensures data is backed up and restored.

  • Use FMTOPT(*MAP) or *DROP depending on compatibility between old and new formats.


 

Post Comments