Ramesh Chand Rebari
New Member
main Procedure
{Table_audit.i &Table = "Order" }/*here we included the session.i file that is used for auditing*/
define variable lChoice as logical no-undo.
define variable iCustNum as integer no-undo.
/*Frame for all the Creating or Updating activities*/
define frame CustInfo
with size 500 by 20.
do transaction:
display "Do you want to update the Order yes/no".
set lChoice.
/*If we want to update this will be execute*/
if lChoice then
do:
for each Order:
update Order with frame CustInfo.
end.
message "Order updated".
end.
/*If we want to create this will be execute*/
else
do:
set iCustNum.
create Order.
assign
Order.CustNum = iCustNum.
update Order with frame f with size 100 by 20.
message "created".
end.
end.
/*for display the EventLog*/
for each EventLog no-lock:
display EventLog.
end.
/*table_audit.i file */
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.
on write of {&table}
new newBuffer old oldBuffer
do:
ASSIGN
hOldRecord = BUFFER oldBuffer:HANDLE
hNewRecord = BUFFER newBuffer:HANDLE.
if new newBuffer then
do:
message "create"
view-as alert-box.
CREATE EventLog.
EventLog.cDate = today.
EventLog.cTime = STRING(TIME,"HH:MM:SS").
EventLog.cTableName = hOldRecord:name.
EventLog.action = "create".
end.
else
do:
BUFFER-COMPARE newBuffer TO oldBuffer SAVE RESULT IN cChangedFields NO-ERROR.
IF cChangedFields <> "" THEN
DO:
DO iChangedFields = 1 TO NUM-ENTRIES(cChangedFields):
CREATE EventLog.
EventLog.cDate = today.
EventLog.cTime = STRING(TIME,"HH:MM:SS").
EventLog.cTableName = hOldRecord:name.
EventLog.action = "Update".
EventLog.cFieldName = ENTRY(iChangedFields, cChangedFields).
hOldField = hOldRecord:BUFFER-FIELD(ENTRY(iChangedFields, cChangedFields)).
EventLog.cOldStringValue = hOldField:buffer-value.
hNewField = hNewRecord:BUFFER-FIELD(ENTRY(iChangedFields, cChangedFields)).
EventLog.cNewStringValue = hNewField:buffer-value.
end.
end.
end.
end.
{Table_audit.i &Table = "Order" }/*here we included the session.i file that is used for auditing*/
define variable lChoice as logical no-undo.
define variable iCustNum as integer no-undo.
/*Frame for all the Creating or Updating activities*/
define frame CustInfo
with size 500 by 20.
do transaction:
display "Do you want to update the Order yes/no".
set lChoice.
/*If we want to update this will be execute*/
if lChoice then
do:
for each Order:
update Order with frame CustInfo.
end.
message "Order updated".
end.
/*If we want to create this will be execute*/
else
do:
set iCustNum.
create Order.
assign
Order.CustNum = iCustNum.
update Order with frame f with size 100 by 20.
message "created".
end.
end.
/*for display the EventLog*/
for each EventLog no-lock:
display EventLog.
end.
/*table_audit.i file */
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.
on write of {&table}
new newBuffer old oldBuffer
do:
ASSIGN
hOldRecord = BUFFER oldBuffer:HANDLE
hNewRecord = BUFFER newBuffer:HANDLE.
if new newBuffer then
do:
message "create"
view-as alert-box.
CREATE EventLog.
EventLog.cDate = today.
EventLog.cTime = STRING(TIME,"HH:MM:SS").
EventLog.cTableName = hOldRecord:name.
EventLog.action = "create".
end.
else
do:
BUFFER-COMPARE newBuffer TO oldBuffer SAVE RESULT IN cChangedFields NO-ERROR.
IF cChangedFields <> "" THEN
DO:
DO iChangedFields = 1 TO NUM-ENTRIES(cChangedFields):
CREATE EventLog.
EventLog.cDate = today.
EventLog.cTime = STRING(TIME,"HH:MM:SS").
EventLog.cTableName = hOldRecord:name.
EventLog.action = "Update".
EventLog.cFieldName = ENTRY(iChangedFields, cChangedFields).
hOldField = hOldRecord:BUFFER-FIELD(ENTRY(iChangedFields, cChangedFields)).
EventLog.cOldStringValue = hOldField:buffer-value.
hNewField = hNewRecord:BUFFER-FIELD(ENTRY(iChangedFields, cChangedFields)).
EventLog.cNewStringValue = hNewField:buffer-value.
end.
end.
end.
end.