Examples: Trigger programs
These example trigger programs are triggered by write, update, and delete operations on the ATMTRANS file. They are written in ILE C, ILE COBOL, and RPG/400®.
For an ILE RPG example, see the Stored Procedures, Triggers, and User-Defined Functions on DB2 Universal Database™ for iSeries™
redbook. The application contains the following types of transactions.
- The application inserts three records into the ATMTRANS file which runs an insert trigger. The insert trigger adds the correct amount to the ATMS file and the ACCTS file to reflect the changes.
- Next, the application makes two withdrawals, which run an update trigger:
- The application withdraws $25.00 from account number 20001 and ATM number 10001 which runs the update trigger. The update trigger subtracts $25.00 from the ACCTS and ATMS files.
- The application withdraws $900.00 from account number 20002 and ATM number 10002 which runs an update trigger. The update trigger signals an exception to the application indicating that the transaction fails.
- Finally, the application deletes the ATM number from the ATMTRANS file which runs a delete trigger. The delete trigger deletes the corresponding ACCTID from the ACCTS file and ATMID from the ATMS file.
- Example: Insert trigger written in RPG/400
This trigger program runs after records are inserted into the ATMTRANS file.
- Example: Update trigger written in ILE COBOL
This trigger program runs after a record is updated in the ATMTRANS file.
- Example: Delete trigger written in ILE C
This trigger program runs after a record is deleted from the ATMTRANS file.
- Data structures for the example database files
These data structures are used in the application for the ATMTRANS, ATMS, and ACCTS files.
Parent topic:
Creating trigger programs