Triggers

Trigger Concepts

A database trigger is a condition that is defined at the field or table level in the Repository. The trigger definition allows a function to be linked to a specific database operation and condition. The trigger function will be invoked automatically when a specific type of I/O operation occurs to a table and when a specific set of conditions are met.

For example, when an application developer defines the "Cancel of an Order" via the RDML command DELETE FROM_FILE(ORDHDR) WITH_KEY(#ORDNUM), they have initiated an "event", which may automatically cause other functions to be "triggered".

When the order is cancelled it may "trigger" the following:

Activity A

Flag Order Historical Details

Activity B

Print Outstanding Credit Invoices

Activity C

Send a Message to the Sales Department

 

A trigger function allows a business activity to be associated directly with a database table. When a specified event happens to information in the table, then the trigger(s) will be automatically invoked.

Similar to validation checks, LANSA supports Repository-based triggers in order to centralize the business logic of your application. Instead of repeatedly coding the same business procedures into each program, LANSA allows a trigger to be defined once for a field or table, and then it will be applied during database operations from any LANSA application.

Sensible use of triggers may transform the way that an application is designed. The user interface can be fully designed, and then the complexities and rules can be introduced later by using table validation rules and database trigger functions. The resulting design is much more in the "object oriented" style. Triggers separate "business function" from "user interface" in a much clearer and easier way.

Also See

Trigger Definition in the Technical Reference Guide

Trigger Condition in the Technical Reference Guide

Trigger Functions in the LANSA for i User Guide

REP007 - Table Validation Rules/Triggers in the Repository Tutorial.