Validate_Save is used as final validation of a record before saving it. It is sent to every table in the DDO structure that will participate in the save. It is called when the database is locked and all field values have been updated. You may directly query the value of any file.field buffer and if any value or combination of values is invalid, stop the save by declaring an error or by returning a non-zero value.

The data in the file buffer is exactly what would get saved. The exception to this is that the file buffer attaches have not yet occurred. This means that a child-file buffer may not contain the parent information that will get placed in the file buffer during the Attach_Main_File event. The Attach_Main_File event occurs after the Validate_Save.

The tables of all participating DDOs are locked during Validate_Save. Therefore, the function should be fast and must never call for user input. The exception to this is the UserError message or the error command. An error generated during the Validate_Save will be deferred until after the save has been backed out and the tables have been unlocked.

Typically, a failed Validate_Save will generate an error message, as in the example below.

Function Validate_Save returns Integer

    integer iError

    If (Invt.Qty < 0) Begin

        Send UserError 'Insufficient Inventory on hand'


    forward get Validate_Save to iError

    Function_Return iError


An error in any of the save events (Validate_Save, Update, Backout, Save_Main_File, etc.) starts a transaction rollback. This is a special process. When this happens the remaining code in the function is not executed.

Because the buffers for all participating tables have been updated, you should not find, clear, delete, or alter any file buffers.

This should not be confused with field validation. Field validation occurs before the database is locked and before the fields are updated to the file buffer. Field validation can be used to handle most validations. Validate_Save is used to handle special validations that can only be checked in a locked and updated state.

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 UserError message or 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.

See Also

Defining Data Dictionary Events