The reference I use is the Redbook "DB2 UDB for AS/400 Advanced Database
Functions" (SG24-4249). In the version of the book I use, Triggers are
discussed in chapter 10. It has several code examples (COBOL, RPG (ILE), and
C).

>From the book:
"Triggers run as part of the job that activated them. Since they might
access objects to which the current user is not authorized, you may create
them with the USRPRF(*OWNER) parameter. On the other hand, since triggers
are generally used to enforce business rules, avoid granting the *OBJMGMT
authorities or the ALTER or REFERENCE SQL privileges to users that do not
strictly need them. Use this precaution to avoid having users easily
circumvent the rules by removing the triggers from the database files.
"Also remove all the authorities on the trigger program from the public,
since they are not necessary for the triggering mechanism. The system can
always invoke the trigger, regardless of which user is performing the data
change"

I have since searched Google and learned that the above book is split into
smaller books. Here is a link to the book you want ("Stored Procedures and
Triggers on DB2 Universal Database for iSeries"):
http://publib-b.boulder.ibm.com/Redbooks.nsf/RedbookAbstracts/sg246503.html?
OpenDocument

Triggers are part of the job causing the trigger, and are subject to the
user executing the program. *IF* you compile them that way.

My guidelines:
The enforcement of business rules is handled in our vendor-supplied
application. However, I add triggers to certain files for auditing purposes,
or to ensure user-defined fields conform to our in-house specifications.
(For instance, a model number must always be upper case, but the application
allows upper and lower case. A trigger is added to always convert said model
to uppercase.) We do not use triggers to "kick off" processes as suggested
in the above book.

* Compile the trigger program to run as the owner (USRPRF(*OWNER)) and to
not use adopted authority.
* Make the program's owner the same as the database file to which it is
attached. If trigger program APCHKTRG is attached to file APCHK, then make
APCHKTRG's owner the same as APCHK.
* Change the trigger program to have PUBLIC *EXCLUDE authority. In general,
the owner of the trigger program has *ALL authority, and no one else has any
authority.

HTH,
Loyd

-----Original Message-----
From: JuanCarlos.Minuesa@es.huhtamaki.com
[mailto:JuanCarlos.Minuesa@es.huhtamaki.com]
Sent: Tuesday, October 22, 2002 6:28 AM
To: midrange-l@midrange.com
Subject: Trigger Program : what Program caused the Upd/Del/Ins I am
processing?


I've writen a trigger program and works OK, The question is: the transaction
that caused me (the trigger pgm) execute was originated by some other
Application program... I believe the trigger pgm executes under
Job/User/JobNo same as the originating job, but where can I find the info
about wich PGM (pgmname, libname, ...) originated the transaction? Regards,
Juan Carlos



As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.