Validate_Delete - BaseData_Set

Guards execution of delete operation

Type: Event

Return Data Type: Integer

Parameters: None

Return Value

Should return zero if deletion is allowed, else should return non-zero or generate an error to prevent deletion. By default, returns zero to allow deletion.


Syntax
Function Validate_Delete Returns Integer

Description

The Validate_Delete function is called right before a delete will occur. The participating tables are locked. Generating an error or returning a non-zero value will stop the delete.

A delete operation will delete the main file and all related descendant-file records (child, grandchild, etc.). It does this to prevent orphans. This only occurs if Cascade_Delete_State is true and there is a child-parent relationship between the tables and the DDO structure is proper.

Validate_Delete is only sent to the DDO in whose Main_File the delete is being done. If Validate_Delete is approved, the main-table record and all child-table records will be deleted. Using CascadeDeleteAllowed in a child table DD (DataDictionary) allows any child table to determine if it will allow itself to be deleted as part of a cascade delete.

You can augment Validate_Cascade_Delete in the child DD for delete validations in each child record.

If you are prohibiting cascade deletes, it is vital that you forward the Validate_Delete message. The cascade-delete checking occurs as part of this forwarded behavior:

Function Validate_Delete Returns Integer
    Integer iError

    Forward get Validate_Delete to iError
    If (Not(iError)) Begin
        If (Customer.status = 'A') Begin
            Error 306 'Cannot delete active record' 
        End
    End
    Function_Return iError
End_Function


The tables of all participating DDOs are locked during Validate_Delete. 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_Delete will be deferred until after the delete has been backed out and the tables have been unlocked.

An error in any of the delete events (Validate_Delete, Deleting, Backout, Delete_Main_File, etc.) starts a transaction rollback. This is a special process. When this happens, the remaining code in the function is not executed.

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 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.

Note:
Validate_Delete is not called as part of a cascading delete from a parent; so, a Validate_Delete sent to a child DDO that would block the delete when called from the child will not block the delete from taking place when the parent is being deleted. This is intentional and by design.

See Also

Cascade_Delete_State | When to Use the File-Buffer | Defining Data Dictionary Events