|Product:||DBConnectivity Products for IBM Db2 for i(HiT ODBC/400, HiT OLEDB/400, Ritmo/i, HiT JDBC/400)|
|Summary:||How to set a database trigger in IBM Db2 for i from a DBConnectivity product|
A database trigger can be set via support for remote command CALL QSYS.QCMDEXC.
Add Physical File Trigger
A developer should be able to set a trigger against a physical file using the Add Physical File Trigger (ADDPFTRG)CL command with our CALL QSYS.QCMDEXC support. Once the association exists between a file and a trigger program, the system calls the trigger program when a data operation is initiated against the physical file, any member of the physical file, and any logical file created over the physical file.
Remove Physical File Trigger
The Remove Physical File Trigger (RMVPFTRG) CL command can similarly be used with our CALL QSYS.QCMDEXC support. This command removes the association of file with its trigger program. Once you remove this association, no action is taken if a change is made to the physical file.
View Trigger Components
To display the components of a trigger, a developer can use the Display File Description (DSPFD) CL command. It provides a list of the triggers associated with a file.
Remote CL Command
DBConnectivity products support passing these CL commands. Use the CALL statement to invoke the remote CL command. You need to reference the OS/400program that will process the CL command (QCMDEXC in library QSYS).
The QCMDEXC program takes two arguments, a string containing the text of the command, followed by the length of the command text as a decimal number (15,5). Below is an example of a generic string:
CALLQSYS.QCMDEXC(‘my command string', 0000000017.00000)
The CL command for adding a physical file trigger is:
CALL QSYS.QCMDEXC(ADDPFTRG FILE(name/XXXXX)TRGTIME(*AFTER) TRGEVENT(*INSERT) PGM(name/UUUUU) THDSAFE(*YES),0000000086.00000)