Replace the Contents of a Physical File That Has Triggers
May 7, 2008 Hey, Ted
I need to copy the contents of a physical file from our production system to its counterpart in our development system, which is a separate logical partition. I have several ways to copy the file from the production system to the development system. However, error messages I get say that I cannot replace the data because the database file has triggers over it. Help!
You need to disable the triggers. Disabling triggers is most easily done if all of the triggers are active. Use Change Physical File (CHGPF) to disable the triggers.
CHGPFTRG FILE(MYLIB/MYFILE) TRG(*ALL) STATE(*DISABLED)
Then copy the data.
CPYF FROMFILE(YOURLIB/YOURFILE) + TOFILE(MYLIB/MYFILE) MBROPT(*REPLACE)
And re-enable the triggers.
CHGPFTRG FILE(MYLIB/MYFILE) TRG(*ALL) STATE(*ENABLED)
If the file has one or more disabled triggers, note the names of the disabled triggers so that you will be able to re-enable the right ones. The easiest way is to run DSPFD … OUTPUT(*PRINT) before disabling the triggers. Then you’ll be able to enable or disable triggers one at a time, as illustrated by the following command.
CHGPFTRG FILE(MYLIB/MYFILE) TRG(AFTDELETE) + TRGLIB(MYLIB) STATE(*ENABLED)