I would highly recommend that you review the Progress Programming Handbook (either the printed documentation or E-DOC), chapter 12 on Transactions. Here is a quick summary:
How does Progress know where to start the transaction and how much work to undo or back out? The following transaction blocks start a transaction if one is not already active:
· Any block that uses the TRANSACTION keyword on the block statement (DO, FOR EACH, or REPEAT).
· A procedure block, trigger block, and each iteration of a DO ON ERROR, FOR EACH, or REPEAT block that directly updates the database or directly reads records with EXCLUSIVE-LOCK. You use EXCLUSIVE-LOCK to read records in multi-user applications. See Chapter 13, "Locks," for more information on locking.
Directly updating the database means that the block contains at least one statement that can change the database. CREATE, DELETE, and UPDATE are examples of such statements.
If a block contains FIND or FOR EACH statements that specify EXCLUSIVE-LOCK, and at least one of the FIND or FOR EACH statements is not embedded within inner transaction blocks, then the block is directly reading records with EXCLUSIVE-LOCK.
Note that DO blocks do not automatically have the transaction property. Also, if the procedure or transaction you are looking at is run by another procedure, you must check the calling procedure to determine whether it starts a transaction before the RUN statement.
Once a transaction is started, all database changes are part of that transaction, until it ends. Each user of the database can have just one active transaction at a time.
<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
/* p-txn2.p */
REPEAT:
INSERT order WITH 2 COLUMNS.
END.
[/code]
This procedure has two blocks: the procedure block and the REPEAT block. The procedure block has no statements directly in it that are not contained within the REPEAT block.
The REPEAT block contains an INSERT statement that lets you add order records to the database. Because the REPEAT block is the outermost block that contains direct updates to the database, it is the transaction block.
At the start of an iteration of the REPEAT block, Progress starts a transaction. If any errors occur before the END statement, Progress backs out any work done during that transaction.
Note that data-handling statements that cause Progress to automatically start a transaction for a regular table will not cause Progress to automatically start a transaction for a work table or temporary table.
Consider another example:
<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
/* ptxn3.p */
REPEAT:
INSERT order WITH 2 COLUMNS.
FIND customer OF order.
REPEAT:
CREATE order-line.
order-line.order-num = order.order-num.
DISPLAY order-line.order-num.
UPDATE line-num order-line.item-num qty price.
END.
END.
FOR EACH salesrep:
DISPLAY sales-rep rep-name.
UPDATE region.
END.
[/code]
This procedure has four blocks:
· Procedure block - There are no statements in this block, so Progress does not start a transaction at the start of the procedure.
· Outer REPEAT block - The outermost block that directly updates the database (INSERT order WITH 2 COLUMNS). Therefore, it is a transaction block. On each iteration of this block, Progress starts a transaction. If an error occurs before the end of the block, all work done in that iteration is undone.
· Inner REPEAT block - Directly updates the database but it is not the outermost block to do so. Therefore, it is not a transaction block. It is, however, a subtransaction block. Subtransactions are discussed later in this chapter.
· FOR EACH block - An outermost block that directly updates the database (UPDATE region). Therefore, it is a transaction block. On each iteration of this block, Progress starts a transaction. If an error occurs before the end of the block, all work done in that iteration is undone.
Hope this helps.
[This message has been edited by progresstalk (edited 28 December 1999).]