PreviousNextIndex

TRIGGER PROCEDURE statement

Defines a schema trigger.

Syntax

TRIGGER PROCEDURE FOR event OF object [ options ] 

event
object
options
Example

The following is a WRITE trigger for the Customer table. It uses the OLD BUFFER option so that it can determine whether the CustNum 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 ix          AS INTEGER NO-UNDO. 
DEFINE VARIABLE Outstanding AS INTEGER NO-UNDO. 
/* Check to see if the user changed the Customer Number */ 
IF Customer.CustNum <> oldCustomer.CustNum  
  AND oldCustomer.CustNum <> 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.CustNum = Customer.CustNum. 
    ix = ix + 1. 
  END. 
  IF ix > 0 THEN 
    MESSAGE ix "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 NO-LOCK: 
  FOR EACH OrderLine OF Order NO-LOCK: 
    Outstanding = Outstanding + (OrderLine.Qty * OrderLine.Price). 
  END. 
END. 
FOR EACH Invoice OF Customer NO-LOCK: 
  Outstanding = Outstanding +  
    (Invoice.Amount - (Invoice.TotalPaid + Invoice.Adjustment)). 
END. 
IF Customer.CreditLimit < 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


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex