Previous Topic: Implementing TriggersNext Topic: CA 2E Trigger Implementation


Typical Trigger Implementation

User-written trigger programs typically perform semi-generic processing to retrieve the file-specific ORF and NRF from the trigger buffer and move them into named structures prior to performing trigger-specific processing. This retrieval processing often involves relatively high complexity. Such processing can require the use of relatively esoteric functionality like pointer-based variables and dynamic memory operations not normally found in most HLL programming.

As a result of IBM’s implementation of triggers (and particularly the way in which DM passes parameters to the trigger program), developers typically write separate trigger programs for each database file. A single trigger program may be used for more than one trigger on that file, however.

This implementation also makes it difficult to test trigger programs, since any test-harness must exactly duplicate the trigger buffer parameter specific to the file to which the trigger is attached.

In addition, the actual insertion of a trigger into the database (either initially or following a change in a trigger) requires multiple file locks on the database file and on all related access paths, often requiring the database to be taken offline during trigger implementation.

The following diagram shows the structure of a typical (non-CA 2E) trigger showing how the various components interact.

Typical Trigger Implementation

The processing flow is as follows:

  1. Application program (APP) executes a database change statement (an INSERT, DELETE or UPDATE), resulting in a low-level call to i OS Data Management (DM).
  2. DM calls the trigger program (TRG) specified for the trigger.
  3. TRG performs user-defined processing and then returns control to DM.
  4. If DM receives an error code from TRG (indicating that an error occurred during the processing in TRG), it does not update the file and instead sends the error code back to APP. Otherwise, it updates the file and returns control to APP.