Progress
Programming
Handbook


WRITE Session Trigger Example

Whenever the contents of a record are changed and the record is validated, Progress executes the WRITE trigger. After the WRITE trigger executes, Progress writes the modified record to the record buffer. Note that if the trigger is executed by a VALIDATE statement, the record is not necessarily written to the record buffer.

During trigger execution, Progress makes two record buffers available to the trigger procedure. The NEW buffer contains the modified record that is being validated. The OLD buffer contains the most recent version of the record before the latest changes were made (this will be the template record if it is a newly created record, the record from the DB if it has not been validated, of the most recently validated record if it has been validated). You can modify the contents of the NEW buffer, but the OLD buffer is read-only. You can compare the contents of these two buffers and perform actions based on the results.

The following is an example of a WRITE session trigger:

p-sestrg.p
ON WRITE OF customer OLD BUFFER ocust DO: 
    IF customer.sales-rep <> ocust.sales-rep 
    THEN DO: 
       FIND salesrep OF customer NO-LOCK. 
       customer.comments = customer.comments + " Salesrep changed to " + 
                           salesrep.rep-name + " on " + STRING(TODAY). 
    END. 
END. 

This trigger tests whether you modified the Sales–rep field. If so, it adds a comment to the customer record.

The trigger executes before the record is actually written, which means that the trigger can make modifications to the record before it is released. These modifications do not cause the trigger to execute again.

NOTE: If you create a record and then write it to the database without updating it (the initial field values remain the same), the WRITE trigger does not execute; only the CREATE trigger executes. If you update one or more fields before you write the record, both the CREATE and WRITE triggers execute. On Embedded SQL (ESQL), an INSERT statement always executes both the CREATE and WRITE triggers.


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