Try OpenEdge Now
skip to main content
ABL Database Triggers and Indexes
Database triggers : Best practices for ABL triggers
 

Best practices for ABL triggers

When you write ABL triggers, there are several general considerations that you should keep in mind.

Metaschema tables

ABL does not allow any database triggers on events for metaschema tables and fields (tables or fields named with an initial underscore). You can only intercept database events for an application database object.

User-interaction code

ABL allows you to include any type of ABL statement within a database trigger block, including those that involve user interaction. However, it is not a recommended to include any statements that call for input from the user.
For example, if the user runs your procedure in batch mode, a trigger with a prompt causes the procedure to stop, waiting for user input.

FIND NEXT and FIND PREV

You cannot delete or advance any record in a buffer passed to a database trigger procedure (as with a FIND NEXT or FIND PREV statement) within the trigger procedure.

Triggers execute other triggers

An action within one trigger procedure can execute another trigger procedure. For example, if a trigger procedure assigns a value to a field and you defined an ASSIGN trigger for that field, that ASSIGN trigger executes. You must carefully design your triggers to avoid conflicts. For example, trigger A could change data, which could cause trigger B to execute. Trigger B could change the same data, a change you did not anticipate or want.

Triggers can start transactions

By their nature, CREATE, DELETE, WRITE, and ASSIGN triggers execute from within a transaction. (The triggering event itself must occur within a transaction.)
This means that while you can start a subtransaction within a trigger procedure for these events, you cannot start a new transaction. However, a FIND might or might not be executed within a transaction. Therefore, you should not assume that you can start a subtransaction within a FIND trigger; it might turn out to be a complete transaction.

Where triggers execute

Database triggers (including replication-related triggers) execute in the application logic, which consists of OpenEdge Application Servers and local ABL procedures. For more information on OpenEdge Application Servers, see OpenEdge Application Server: Developing AppServer Applications.

Storing trigger procedures

You can store a database’s trigger procedures in an operating system directory or in an ABL r-code library.

SQL considerations

Because of inherent differences between ABL and SQL, triggers might not execute in exactly the same way. For more information on how SQL and database triggers interact, see OpenEdge Data Management: SQL Reference. The following rules apply:
*SQL triggers will not fire when ABL events occur.
*ABL triggers will not fire when SQL events occur.
*To ensure integrity, you must have both types of triggers, or use SQL to only read data, or have only a SQL table.