Progress
Language Reference


TRIGGER PROCEDURE Statement

Interfaces
OS
SpeedScript
All
All
Yes

Defines a schema trigger.

SYNTAX

TRIGGER PROCEDURE FOR event OF object [ options ] 

event

The event for which the schema trigger is being defined. The Valid events are CREATE, DELETE, FIND, WRITE, and ASSIGN.

object

The object on which the event is defined. If the event is CREATE, DELETE, FIND, or WRITE, the object must be a reference to a database table. If the event is ASSIGN, the object must be a reference to a database field qualified by a table name.

options

Optional parts of the trigger header.

Headers for CREATE, DELETE, and FIND triggers take no options. Their syntaxes are as follows.

SYNTAX
TRIGGER PROCEDURE FOR CREATE OF table 

SYNTAX
TRIGGER PROCEDURE FOR DELETE OF table 

SYNTAX
TRIGGER PROCEDURE FOR FIND OF table 

In the header for a WRITE trigger you can optionally include one or two buffer names.

SYNTAX
TRIGGER PROCEDURE FOR WRITE OF table
  [ NEW [ BUFFER ] buffer-name1 ]
  [ OLD [ BUFFER ] buffer-name2 ] 

In the header for an ASSIGN trigger, you can optionally specify one or two value holders. You can specify formatting for each.

SYNTAX
TRIGGER PROCEDURE FOR ASSIGN
  {     { OF table .field }
     |  { NEW [ VALUE ] value1
            { AS data-type | LIKE db-field }
        }
  }
  [ COLUMN-LABEL label ]
  [ FORMAT format-string ]
  [ INITIAL constant ]
  [ LABEL label-string ]
  [ NO-UNDO ]
  [ OLD [ VALUE ] value2
      { AS data-type | LIKE db-field }
      [ COLUMN-LABEL label ]
      [ FORMAT format-string ]
      [ INITIAL constant ]
      [ LABEL label-string ]
      [ NO-UNDO ]
  ] 

EXAMPLE

The following is a WRITE trigger for the customer table. It uses the OLD BUFFER option so that it can determine whether the cust-num value has changed. If the customer’s outstanding balance exceeds its credit limit, the trigger returns the error condition (in which case the record is not updated).

r-wrcust.p
TRIGGER PROCEDURE FOR Write OF Customer OLD BUFFER oldCustomer.

/* Variable Definitions */
DEFINE VARIABLE i AS INTEGER INITIAL 0.
DEFINE VARIABLE Outstanding AS INTEGER INITIAL 0.

/* Check to see if the user changed the Customer Number */
IF Customer.Cust-Num <> oldCustomer.Cust-Num AND oldCustomer.Cust-Num <> 0
THEN DO:
   /* If the user changed the Customer Number, find all related orders
      and change their customer numbers.                              */
   
   FOR EACH order OF oldCustomer:
      Order.Cust-Num = Customer.Cust-Num.
      i = i + 1.
   END.
   IF i > 0 THEN
     MESSAGE i "orders changed to reflect the new customer number!".
END.

/* Ensure that the Credit Limit value is always Greater than the sum of
   this Customer’s Outstanding Balance */
FOR EACH Order OF Customer:
   FOR EACH Order-Line OF Order:
      Outstanding = Outstanding + ( Qty * Order-Line.Price ).
   END.
END.
FOR EACH Invoice OF Customer:
   Outstanding = Outstanding + ( Amount - ( Total-Paid + Adjustment )).
END.

IF Customer.Credit-Limit < Outstanding THEN DO:
   MESSAGE "This Customer has an outstanding balance of: " Outstanding 
           ".  The Credit Limit MUST exceed this amount!".
   RETURN ERROR.
END.  

NOTES

SEE ALSO

PROCEDURE Statement


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095