AS/400 Triggers – Writing a trigger for a file

895 pts.
as400/DB2 - Trigger - Comit
Hi, I want to write a Trigger for a file. I want to test if the trigger can be fired only when the file operation is committed in the program. can you explain me this trigger concept in scenario such that......I update a file. This file has trigger associated with it. now suppose the program fails after I update the file and before program executes 'Comit' operation.....In such case I don't want the trigger to be fired as my operation is not committed......Is there any work around for such scenario.... Can I write a simple routines to test my programs for such scenarios... Thanks, Nutan.

Software/Hardware used:

Answer Wiki

Thanks. We'll let you know when a new response is added.

Here’s a recent discussion that should help. 

Didn’t read your question closely enough.
You trigger on add/update/delete not commit.
The add/update/delete makes the file changes but keeps the records locked
The Commit releases the locks and moves the boundry in the journal but doesn’t fire a trigger.
On the other hand, you could call a program at the point of the commit.


The journal will recieve each file update and if a rollback occurs the journal will recieve the roll back for each file that was changed. The journal has integrity.

Apparently your trigger is writting to a log file, you may want to write to the log file also when you commit or rollback but you cann’t do these with a trigger.

Discuss This Question: 2  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Nutangujar
    thanks Phil. I'm still confused with the concept of Comit operation on database.... I think there is no way I can make 'Comit' operation as the trigger event. If I'm not wrong then this is the limitation of AS400 Trigger ....This may mar integrity between the trigger log file and actual database update that has taken place....and there is no way to overcome this... Please correct if I'm wrong.. Nutan.
    895 pointsBadges:
  • TomLiotta
    As long as the trigger action is part of the COMMIT transaction, any rows written to a log file will be rolled back when the transaction is rolled back. Writing to a log file generally is not a very good use of a trigger anyway. If you need to "log" database activity, use a journal. You'll have a journal anyway if you're working with commitment control, so what's the point of a "log file"? . Tom
    125,585 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: