Try OpenEdge Now
skip to main content
Developing WebSpeed Applications
Controlling Database Transactions : Understanding the scope of database transactions : Controlling where DB transactions begin and end
 

Controlling where DB transactions begin and end

You might find that for certain procedure types, you want to start or end database transactions in locations other than those WebSpeed automatically chooses. You know that WebSpeed automatically starts a database transaction for each iteration of four kinds of blocks:
*FOR EACH blocks that directly update the database
*REPEAT blocks that directly update the database
*Procedure blocks that directly update the database
*DO ON ERROR or DO ON ENDKEY blocks that contain statements that update the database
A database transaction ends at the end of the transaction block or when the transaction is backed out for any reason.
Sometimes you want a database transaction to be larger or smaller depending on the amount of work you want undone in the event of an error. You can explicitly tell WebSpeed to start a database transaction by using the TRANSACTION option with a DO, FOR EACH, or REPEAT block header:
*DO TRANSACTION:
*FOR EACH TRANSACTION:
*REPEAT TRANSACTION:
When you explicitly tell WebSpeed to start a database transaction, it starts a transaction on each iteration of the block regardless of whether the block contains statements that directly update the database. Of course, WebSpeed does not start a database transaction if one is already active.