Examine or load trigger definition. The format of the $ZTRIGGER() function is:
$ZTRIgger(expr1
[,expr2
])
$ZTRIGGER() returns a truth value (1 or 0) depending on the success of the specified action.
$ZTRIGGER() performs trigger maintenance actions similar those performed by MUPIP TRIGGER.
If expr1
evaluates to case-insensitive "FILE", $ZTRIGGER() evaluates expr2
as the location of the trigger definition file. Then, it applies the trigger definitions in the file specified by expr2
. If a file contains a delete all (-*), that action produces no user confirmation.
If expr1
evaluates to case-insensitive "ITEM", $ZTRIGGER() evaluates expr2
as a single line or multi-line trigger definition entry. A multi-line trigger definition or a multi-line XECUTE string starts with << and uses $char(10) to denote the newline separator. expr2
with ITEM does not permit a multi-line XECUTE string to end with the >> terminator. It does not require trigger logic to appear immediately after the -xecute=<<, but a $char(10) must prefix the logic as shown in the following examples:
set trigstr="+^a -xecute=<< -commands=S"_$char(10)_" do ^twork1"_$char(10)_" do ^twork2"_$char(10) write $ztrigger("item",trigstr) set trigstr="+^a -xecute=<< -commands=S "_$c(10)_" do ^twork1"_$c(10)_" do ^twork2"_$c(10) write $ztrigger("item",trigstr)
If expr1
evaluates to case-insensitive "SELECT", $ZTRIGGER() evaluates the optional expr2
as a trigger name or name wildcard, and directs its output to $IO. A FALSE result (0) indicates there are no matching triggers.
$ZTRIGGER() always operates within a TP transaction even if it needs to implicitly create one to encapsulate its work. Trigger maintenance operations reserve their output until the transaction commits (TCOMMIT where $TLEVEL goes to zero), at which time they deliver their entire output to the current $IO containing consistent information for all $ZTRIGGER() invocations within the successful processing of a larger transaction at that ultimate TCOMMIT. If an explicit transaction ends with a TROLLBACK, it does not produce any $ZTRIGGER() output.
$ZTRIGGER() can appear within a transaction as long as it does not update any triggers for globals which have had triggers invoked earlier in the same transaction.
An attempt by a $ZTRIGGER() within a transaction to remove or replace a trigger on a global after the transaction has activated any trigger defined within the named global generates a TRIGMODINTP error.
$ZTRIGGER() treats the deletion of a non-existent trigger as a success; if that is the only operation, or one of a set of successful operations, it return success (TRUE/1) to the GT.M process. $ZTRIGGER() returns failure in case of trigger selection using trigger names where the number after the pound-sign (#) starts with a 0 (which is an impossible auto-generated trigger name).
GT.M maps trigger definitions to the region to which they apply.
GT.M allows defining triggers with the same name and signature in different regions, but does not allow defining triggers with the same name, but different signatures, in different regions within the same global directory. When loading a trigger definition, if a user-defined name conflicts with a name in any region to which the trigger applies, $ZTRIGGER() reports an error. However, when the name is auto-generated, it generates a name in every region, so if there are multiple (spanning) regions, the same trigger might have a differing auto-generated name in each region.
Note | |
---|---|
A $ZTRIGGER() action (delete or select) applies to all triggers in all regions matching the specified signature. If the argument specifies an incomplete trigger signature, for example, only the name, the specification may match multiple triggers and apply the delete or select to all of them. FIS recommends you run a select and analyze the scope of the signature before any signature limited delete. |
Example:
GTM>set X=$ztrigger("S") GTM>
This example displays the current trigger definitions stored in the database.
GTM>set X=$ztrigger("i","+^Acct(sub=:) -command=set -xecute=""set ^X($ztvalue)=sub""") GTM>
This example adds a trigger definition for the first level node of ^Acct.
Example:
GTM>set trigstr="+^a -commands=S -xecute=<<"_$c(10)_" do ^twork1"_$c(10)_" do ^twork2"_$c(10) write $ztrigger("item",trigstr)
This example demonstrates the usage of the $ztrigger("ITEM",<multi-line-trigger-definition>> where <<denotes the definition of a multi-line -XECUTE string and $c(10) to denote the newline separator. Unlike the $ztrigger("FILE") form, $ztrigger("ITEM",<multi-line-trigger-definition>> does not require the trigger definition to terminate with >>.
Example:
GTM>write $ztrigger("file","agbl.trg") 1 GTM>
This example is equivalent to the previous $ztrigger("ITEM") example. In this example, agbl.trg contains the following multi-line trigger definition:
+^a -commands=S -xecute=<< do ^twork1 do ^twork2 >>
Unlike $ztrigger("ITEM"), $ztrigger("FILE") usages require the trigger definition to terminate with >>