Transactions and trigger and procedure blocks
- Last Updated: January 16, 2024
- 1 minute read
- OpenEdge
- Version 12.8
- Documentation
If your code starts a transaction in one procedure and then calls another procedure, whether internal or external, the entire subprocedure is contained within the transaction that was started before it was called. If a subprocedure starts a transaction, then it must end within that subprocedure as well, because the beginning and end of the transaction are always the beginning and end of a particular block of code.
Since a database trigger procedure is an external procedure called
under special circumstances—in response to an update event elsewhere
in the application—it follows the same rule. There is always a transaction
active when a database trigger is called (except in the case of
the FIND trigger), so the trigger procedure is
entirely contained within the larger transaction that caused it
to be called.
Trigger blocks beginning with the ON event phrase
are treated the same as an internal procedure call. If there is
a transaction active when the block is executed in response to the
event, then its code is contained within that transaction.
Checking whether a transaction is active
You can use the built-in TRANSACTION
function in your procedures to determine whether a transaction is currently active. This
LOGICAL function returns TRUE if a transaction is active and FALSE
otherwise. You might use this, for example, in a subprocedure that is called from multiple
places and which needs to react differently depending on whether its caller started a
transaction. (When you have a single procedure, you should not need this function to tell
you if a transaction is active!)