I am new to Progress. I found how to audit DB changes with the help of DB triggers .
Can anyone help me out with the sample code in implementing the below code to audit Database changes by creating a class that generates data appropriately in to the new audit logging table.
Table to audit - tabeltoaudit
New table to audit the changes - Audit_data
Sample code using DB triggers :
TRIGGER PROCEDURE FOR WRITE OF tabeltoaudit OLD BUFFER oldtabletoaudit.
DEFINE VARIABLE hOldRecord AS HANDLE NO-UNDO.
DEFINE VARIABLE hNewRecord AS HANDLE NO-UNDO.
DEFINE VARIABLE hOldField AS HANDLE NO-UNDO.
DEFINE VARIABLE hNewField AS HANDLE NO-UNDO.
DEFINE VARIABLE cChangedFields AS CHARACTER NO-UNDO.
DEFINE VARIABLE iChangedFields AS INTEGER NO-UNDO.
/* Difference between the two buffers */
BUFFER-COMPARE tabeltoaudit TO oldtabeltoaudit SAVE RESULT IN cChangedFields NO-ERROR.
IF cChangedFields <> "" THEN DO:
ASSIGN
hOldRecord = BUFFER tabeltoaudit :HANDLE
hNewRecord = BUFFER oldtabeltoaudit :HANDLE.
DO iChangedFields = 1 TO NUM-ENTRIES(cChangedFields):
CREATE Audit_data.
ASSIGN
Audit_data.rOldRecid = RECID(oldtabeltoaudit )
Audit_data.rNewRecId = RECID(tabeltoaudit )
Audit_data.cUserId = cUserId
Audit_data.dTimeSt = string(today) + " " + STRING(TIME,"HH:MM:SS")
Audit_data.cTableName = hOldRecord:NAME
Audit_data.cFieldName = ENTRY(iChangedFields, cChangedFields)
hOldField = hOldRecord:BUFFER-FIELD(ENTRY(iChangedFields, cChangedFields))
Audit_data.cOldValue = hOldField:STRING-VALUE
hNewField = hNewRecord:BUFFER-FIELD(ENTRY(iChangedFields, cChangedFields))
Audit_data.cNewValue = hNewField:STRING-VALUE.
END.
END.