In addition to using the
Audit Policy Maintenance tool, audit policies can be deleted from the database audit tables using ABL code. This can be useful to replicate changes to multiple databases where the policies need to be kept identical.
The following ABL sample code:
- Accepts an Audit Policy name as a parameter, and deletes the named policy and its related table, field and event policies.
- It does not delete any audit records from the _aud-audit-data table that were created due to that policy when the policy was active, thus preserving the integrity of the audit trail.
- The same new audit records that would be created in _aud-audit-data if the policy was deleted in the Audit Policy Maintenance tool are created when the policy is deleted using ABL code as well.
/* FUNCTION deleteAuditPolicy
Deletes named audit policy record and all table, field and event policy
records associated with that policy.
INPUT PARAMETER: picAuditPolicyName -- Name of policy to be deleted
RETURNS: TRUE if all related records successfully deleted
FALSE if error, transaction rolled back
ERROR: Sets ERROR-STATUS:ERROR if transaction rolled back
*/
FUNCTION deleteAuditPolicy RETURNS LOGICAL
(picAuditPolicyName AS CHARACTER).
FOR FIRST _aud-audit-policy
WHERE _audit-policy-name = picAuditPolicyName
ON ERROR UNDO, RETURN ERROR FALSE:
FOR EACH _aud-event-policy
WHERE _aud-event-policy._audit-policy-guid
= _aud-audit-policy._audit-policy-guid
ON ERROR UNDO, RETURN ERROR FALSE:
DELETE _aud-event-policy NO-ERROR.
END. /* _aud-event-policy */
FOR EACH _aud-field-policy
WHERE _aud-field-policy._audit-policy-guid
= _aud-audit-policy._audit-policy-guid
ON ERROR UNDO, RETURN ERROR FALSE:
DELETE _aud-field-policy NO-ERROR.
END. /* _aud-field-policy */
FOR EACH _aud-file-policy
WHERE _aud-file-policy._audit-policy-guid
= _aud-audit-policy._audit-policy-guid
ON ERROR UNDO, RETURN ERROR FALSE:
DELETE _aud-file-policy NO-ERROR.
END. /* _aud-file-policy */
DELETE _aud-audit-policy NO-ERROR.
END. /* EACH _aud-audit-policy */
RETURN TRUE.
END FUNCTION. /* deleteAuditPolicy */