Should return 0 if saving is permissible, else non-zero, which prevents saving. By default, returns 0 to allow saving.
Function Validate_Save Returns Integer
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 table buffer attaches have not yet occurred. This means that a child-table buffer may not contain the parent information that will get placed in the table 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 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 iRetVal If (Invt.Qty < 0) Begin Error DFERR_OPERATOR 'Insufficient Inventory on hand' End Forward Get Validate_Save to iRetVal Function_Return iRetVal End_Function
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 table 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 table 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 Error command. See Handling in Transactions for more information.
When accessing table values you should always access the global table buffers and not the DDO buffers (i.e., use "Move Table.Column to var" syntax). See Understanding File Buffers and DDO Field Buffers for more information.
When to Use the File-Buffer | Defining Data Dictionary Events