Procedure Backout
The Update and Backout events are used to maintain relational balances between tables. Update is called when a record is being saved or edited. Backout is called when a record is being edited or deleted. Update and Backout is usually used adjust the balances of parent tables. Backout is used to remove the effect of a save while Update is used to add the effect of a save.
The following Update and Backout in a checks Data Dictionary would adjust the balances of its parent, the vndr table.
Procedure Update Forward Send Update Move (Checks.Total+ Vndr.Total_Paid) to Vndr.Total_Paid End_Procedure Procedure Backout Forward Send Backout Move (Checks.Total - Vndr.Total_Paid) to Vndr.Total_Paid End_Procedure
When a new record is saved, Update (and not Backout) is called.
When a record is deleted, Backout (and not Update) is called.
When a record is edited, Backout and Update are both called.
The contents of an Update and Backout will almost always be the inverse of each other. If they are not, you should carefully recheck your logic. Whatever Update adds to a balance, Backout should deduct.
It is possible that the Backout and Update might adjust different parent balances during an edit. This would happen if the edit caused the parent record to change. DDOs support this.
Do not make the assumption that Update and Backout events only get sent once during a save. While this is true in cases where parent records are not switched, it will not be true when parent records are switched. The process of maintaining relational integrity when parent records are switched is quite complicated and both events can be called multiple times for the same table (for different records).
If a change in a record should adjust balances in both a parent and a grandparent record (e.g., check detail adjusts checks total, which adjusts vendor total), it is best to let a Data Dictionary only adjust its immediate parents (e.g., check detail's Update would adjust the checks table, check's Update would adjust the vendor table).
This message is always called in a locked state. Do not perform user input in this event.
If an Error is declared, the transaction will be rolled back. Errors must be generated using the Error command. See Error Handling in Transactions for more information.
When accessing table values you should always access the global file buffers and not the DDO buffers (i.e., use "Move File.Field to var" syntax). See Understanding File Buffers and DDO Field Buffers for more information.
When to Use the File-Buffer | Defining Data Dictionary Events | Creating | Deleting | Update