In this article I will try to cover as much as possible about DB2 triggers on AS400 system. I plan to cover the following topics in this article.
- What is a trigger?
- How to create a DB2 trigger program on AS400 system.
- How to add a DB2 trigger to a physical file.?
- How to change a DB2 trigger on AS400.?
- How to delete a DB2 trigger?
- How to move a database file from one library to different library?
- FAQs of triggers.
Lets us begin with the definition of a trigger.
What is a trigger?
Trigger is very generic concept in the sense that it's not limited to AS400 DB2 only. Trigger concept is available with almost all databases.
Trigger is nothing but a predefined action (Trigger event) on database file which when happens, a predefined program is run.
The predefined action:- The predefined action can be an UPDATE, DELETE, INSERT or even READ operation on DB2 database. Other file activities like adding/removing journals do not trigger the trigger programs.
The predefined program:- When the trigger event occurs, a predefined program is run. This program generally maintains data integrity.
When exactly the trigger program is called?
The trigger program is called either before or after the trigger event. We specify this thing while adding the trigger to a physical file. The following event matrix displays all situations when a trigger program is called.
When? ?
Action ? |
Before event |
After event |
| Update |
Yes |
Yes |
| Delete |
Yes |
Yes |
| Insert |
Yes |
Yes |
| Read |
Yes |
Yes |
Other file activities (Add journal,
Remove journal, Create logicals) |
No |
No |
Do we really require trigger programs?
We can do everything we achieve using the trigger program by writing our own script or calling the trigger program ourselves. However, a trigger program is called even when data manipulation is done through using DFU or SQL utility. If we need the trigger program to be called in such conditions also then adding a trigger to the physical file is better solution. Since triggers are directly associated to a database file, they have global effect.
Example of a RPG ILE DB2 trigger program on AS400 system.
I am currently preparing the example. I will post it on the next page of this article as soon as this example is complete.
Recent comments
5 days 1 hour ago
5 days 2 hours ago
5 days 2 hours ago
5 days 4 hours ago
5 days 15 hours ago
5 days 17 hours ago
5 days 18 hours ago
5 days 19 hours ago
6 days 8 hours ago
6 days 18 hours ago