I have a database file which has some audit fields on it: add date and time, and update date and time (all numeric fields). I wish to update these fields with the current date and time whenever the database has a record updated or inserted. I also want to add a unique identifier sequence number into any inserted record.
I've written a trigger to do this, and I am simply putting the date, time and sequence number into the new record image in the trigger buffer. The trigger is written in RPGLE under V4R5, with ACTGRP(*CALLER) and DFTACTGRP(*NO).
The trigger is added to the PF for after insert and after update, with ALWREPCHG(*YES).
When the file is changed through DFU or SQL, the trigger works fine. When the file is changed by an RPG/III program, the calling program fails with a "pointer reference not set" error at the UPDATE or WRITE statement. Why is this? What am I missing?
"Pointer reference not set" sounds very much like an ILE parameter problem such as using a parameter that has not been passed to the called program. I would suggest finding out exactly where the crash occurs. To do so, the RPG/3 program should be compiled with option(*LSTDBG). This will let you use the ILE debugger STRDBG (not forgetting to specify OPMSRC(*YES) for both OPM and ILE programs. Put a debug point on the UPDAT and the WRITE and when you get there, use F22 to see what happens in the trigger and where the problem is. It is surprising the trigger works in most cases but OPM and ILE work in different ways when it comes to parameters.
MORE INFORMATION ON THIS TOPIC
Search400's targeted search engine: Get relevant information on DB2/400.
The Best Web Links: tips, tutorials and more.
Check out this online event, Getting the Most out of SQL & DB2 UDB for the iSeries.