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™

Link to PDF redbook. The application contains the following types of transactions.

  1. 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.

  2. Next, the application makes two withdrawals, which run an update trigger:

    1. 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.

    2. 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.

  3. 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.

 

Parent topic:

Creating trigger programs