TRIGGER PROCEDURE FOR event OF object optionsThe event for which the schema trigger is being defined. The Valid events are CREATE, DELETE, FIND, WRITE, and ASSIGN.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.Headers for CREATE, DELETE, and FIND triggers take no options. Their syntaxes are as follows:
TRIGGER PROCEDURE FOR CREATE OF table
TRIGGER PROCEDURE FOR DELETE OF table
TRIGGER PROCEDURE FOR FIND OF table
TRIGGER PROCEDURE FOR WRITE OF tableNEW BUFFER buffer-name1OLD BUFFER buffer-name2In the header for an ASSIGN trigger, you can optionally specify one or two value holders. You can specify formatting for each as follows:
TRIGGER PROCEDURE FOR ASSIGNOF table .fieldNEW VALUE value1AS data-type LIKE db-fieldCOLUMN-LABEL labelFORMAT format-stringINITIAL constantLABEL label-stringNO-UNDOOLD VALUE value2AS data-type LIKE db-fieldCOLUMN-LABEL labelFORMAT format-stringINITIAL constantLABEL label-stringNO-UNDOThe 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).
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.CustNumAND oldCustomer.CustNum <> 0 THEN DO:/* If the user changed the Customer Number, find all related Orders andchange their Customer numbers. */FOR EACH order OF oldCustomer:Order.CustNum = Customer.CustNum.ix = ix + 1.END.IF ix > 0 THENMESSAGE ix "Orders changed to reflect the new Customer number!".END./* Ensure that the Credit Limit value is always greater than the sum ofthis 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.
![]()
Some 3GL applications execute schema triggers. Triggers might also be executed in batch mode. Therefore, you should avoid any user-interface interactions within schema trigger procedures.
© 2012 Progress Software Corporation and/or its subsidiaries or affiliates. |