Richard Grimmett
New Member
I know 9.1d is old hat, but we really cannot migrate currently.
I am trying to develop a WRITE trigger which I can use across multiple tables. These tables already have some complex triggers and so I simply want to install a run statement into the existing trigger to my new routine. The routine I have developed looks like this:
(trigw.p)
and I call it by inserting RUN trig4(workrec. oldworkrec, "wrecid") into the existing trigger.
This all works fine for the workrec table, but I am trying to find a way of being able to do this for all tables without needing to modify my code, and I cannot find a way of not needing to define the BUFFER parameters as explicitly being required for specific tables. Is there a way I can get around this please?
Thanks
Richard
I am trying to develop a WRITE trigger which I can use across multiple tables. These tables already have some complex triggers and so I simply want to install a run statement into the existing trigger to my new routine. The routine I have developed looks like this:
(trigw.p)
Code:
Def Parameter BUFFER workrec for workrec.
Def Parameter BUFFER oldworkrec for workrec.
Def INPUT Parameter TKey AS CHARACTER.
DEFINE VARIABLE TKeyVal as CHARACTER NO-UNDO.
DEFINE VARIABLE TKeyValFld as HANDLE NO-UNDO.
DEFINE VARIABLE TKeyValFldType as CHARACTER NO-UNDO.
DEFINE VARIABLE Action AS CHARACTER INIT "WRITE" NO-UNDO.
DEFINE VARIABLE i AS INTEGER.
DEFINE VARIABLE j AS INTEGER NO-UNDO.
DEFINE VARIABLE hOldRecord AS HANDLE NO-UNDO.
DEFINE VARIABLE hNewRecord AS HANDLE NO-UNDO.
DEFINE VARIABLE hOldField AS HANDLE NO-UNDO.
DEFINE VARIABLE oldFieldVal AS CHARACTER NO-UNDO.
DEFINE VARIABLE hNewField AS HANDLE NO-UNDO.
DEFINE VARIABLE newFieldVal AS CHARACTER NO-UNDO.
DEFINE VARIABLE cChangedFields AS CHARACTER NO-UNDO.
DEFINE VARIABLE iChangedFields AS INTEGER NO-UNDO.
j=1.
BUFFER-COMPARE workrec TO oldworkrec SAVE RESULT IN cChangedFields NO-ERROR.
IF cChangedFields <> "" THEN DO:
ASSIGN
hNewRecord = BUFFER workrec:HANDLE
hOldRecord = BUFFER oldworkrec:HANDLE.
tKeyValFld = hNewRecord:BUFFER-FIELD(TKey).
tKeyValFldType = tKeyValFld:DATA-TYPE.
tKeyVal=tKeyValFld:STRING-VALUE.
CREATE Monitor.
ASSIGN
Monitor.tDate = TODAY
Monitor.tTime = STRING(TIME,"HH:MM:SS")
Monitor.Action = Action
Monitor.TableName = hNewRecord:NAME
Monitor.TableKey = TKey
Monitor.TableKeyType=tKeyValFldType
Monitor.TableKeyValue = TKeyVal.
DO iChangedFields = 1 TO NUM-ENTRIES(cChangedFields):
hOldField = hOldRecord:BUFFER-FIELD(ENTRY(iChangedFields, cChangedFields)).
hNewField = hNewRecord:BUFFER-FIELD(ENTRY(iChangedFields, cChangedFields)).
IF hOldField:EXTENT = 0 THEN DO:
oldFieldVal = hOldField:STRING-VALUE.
newFieldVal = hnewField:STRING-VALUE.
ASSIGN
Monitor.ft[j] = hOldField:DATA-TYPE
Monitor.fov[j] = oldFieldVal
Monitor.fnv[j] = newFieldVal
Monitor.fn[j] = ENTRY(iChangedFields, cChangedFields).
j = j + 1.
END.
ELSE DO:
DO i = 1 TO hOldField:EXTENT:
oldFieldVal = STRING(hOldField:BUFFER-VALUE(i)).
newFieldVal = STRING(hnewField:BUFFER-VALUE(i)).
IF oldFieldVal<>newFieldVal THEN DO:
ASSIGN
Monitor.ft[j] = hOldField:DATA-TYPE
Monitor.fov[j] = oldFieldVal
Monitor.fnv[j] = newFieldVal
Monitor.fn[j] = ENTRY(iChangedFields, cChangedFields) + "@" + STRING(i).
j = j + 1.
END.
END.
END.
END.
END.
and I call it by inserting RUN trig4(workrec. oldworkrec, "wrecid") into the existing trigger.
This all works fine for the workrec table, but I am trying to find a way of being able to do this for all tables without needing to modify my code, and I cannot find a way of not needing to define the BUFFER parameters as explicitly being required for specific tables. Is there a way I can get around this please?
Thanks
Richard
Last edited: