Progress
Programming
Handbook
How Much to Undo
You have seen how, when the system crashes or when you press STOP, Progress undoes the current transaction. Suppose you want to undo a transaction under program control or want to undo a smaller amount of work than that done since the beginning of the transaction.
Take a look at a different version of the
p-txn3.p
procedure. The outer REPEAT block is the transaction block:
Suppose that you wanted to restrict the maximum amount of an order to $500. In the event that the value of an order exceeded that amount, you want to undo the current order–line entry and display a message to the user. For example, look at
p-txn5.p
:
The outer REPEAT block is still the transaction block; it is the outermost block that contains direct updates to the database. However, in this example, Progress starts a subtransaction when it reaches the inner REPEAT block.
If an error occurs during a subtransaction, all the work done since the beginning of the subtransaction is undone. Subtransactions can be nested within other subtransactions.
A subtransaction is started when a transaction is already active and Progress encounters a subtransaction block. The following are subtransaction blocks:
- A procedure block that is run from a transaction block in another procedure.
- Each iteration of a FOR EACH block nested within a transaction block.
- Each iteration of a REPEAT block nested within a transaction block.
- Each iteration of a DO TRANSACTION, DO ON ERROR, or DO ON ENDKEY block. (These blocks are discussed later in this chapter.)
Now go ahead and run the
p-txn5.p
procedure. Enter the data shown in the following display:
![]()
After you enter the second order–line, the amount of the order is $225. When you try to enter the third order–line, the following happens:
- The MESSAGE statements display messages telling you that the limit has been exceeded.
- The UNDO statement undoes the o–l–block. The UNDO statement can undo only those blocks that are either transactions or subtransactions within the current transaction. In this case, the o–l–block is a subtransaction.
Table 12–1 shows when transactions and subtransactions are started.
Note that data handling statements that cause Progress to automatically start a transaction for a database table do not cause Progress to automatically start a transaction for a work table or temporary table.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |