Recommendations for trigger programs
Consider these recommendations when you create a trigger program.
- Create the trigger program so that it runs under the user profile of the user who created it. In this way, users who do not have the same level of authority to the program will not encounter errors.
- Create the program with USRPRF(*OWNER) and *EXCLUDE public authority, and do not grant authorities to the trigger program to USER(*PUBLIC). Avoid having the trigger program altered or replaced by other users. The database calls the trigger program even if the user causing the trigger program to run does not have authority to the trigger program.
- Create the program as ACTGRP(*CALLER) if the program is running in an Integrated Language Environment® (ILE). This allows the trigger program to run under the same commitment definition as the application.
- Open the file with a commit lock level the same as the application's commit lock level. This allows the trigger program to run under the same commit lock level as the application.
- Create the program in the physical file's library.
- Use commit or rollback in the trigger program if the trigger program runs under a different activation group than the application.
- Signal an exception if an error occurs or is detected in the trigger program. If an error message is not signalled from the trigger program, the database assumes that the trigger ran successfully. This might cause the user data to end up in an inconsistent state.