This topic provides examples of trigger programs written in C,
COBOL, and RPG.
The trigger programs in the following examples are triggered by write,
update, and delete operations to 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.