Progress
Programming
Handbook
All-or-nothing Processing
Suppose a customer calls to change an order for four sweat bands to nine sweat bands. This means you must make two changes to your database:
What if you changed the quantity field in the order–line record and are in the midst of changing the allocated field in the item record, when the machine goes down? You want to restore the records to their original state. That is, you want to be sure that Progress changes both records or neither.
Figure 12–2 shows this scenario for a database similar to sports (same tables, different data).
Figure 12–2: Transaction Involving Two Tables
![]()
The following procedure,
p-txn.p
, executes the scenario shown in Figure 12–2, using the sports database.
Progress starts a transaction at the beginning of each iteration of the REPEAT block and ends that transaction at the end of each iteration of the REPEAT block.
Run
p-txn.p
. Type 1 as the order number and 1 as the line number and press GO:
![]()
Now type 35 as the New Quantity and press RETURN. The procedure calculates and displays the new allocated value:
![]()
The quantity has been changed to 35 and the amount allocated changed to 187. At this point control has reached the PAUSE statement at the end of the REPEAT block:
Press SPACEBAR. The procedure prompts you for another order number and line number. Type 1 for the order number and 2 for the line number:
![]()
Change the number of ordered stop watches to 31:
![]()
You can see that the quantity has been changed to 31 and the amount allocated has been increased to 215 (you increased the number ordered by 10). You have once again reached the PAUSE statement just before the end of the REPEAT block.
What if, for some reason, your machine goes down or you decide to press STOP at this point in the procedure? Progress undoes any database changes made during the current iteration of the REPEAT block. Go ahead and press STOP.
Now you are back in the Procedure Editor. Run the
p-txn.p
procedure again.Remember that you had changed the quantity to 35 on line 1 of order 1.
Type 1 as the order number and 1 as the line number. The following screen appears:
![]()
You can see that the first change you made is safely stored in the database. Both the order–line table and the item table reflect the new values of 35 and 348. Press GO to continue on until you reach the PAUSE statement just before the end of the REPEAT block. Then press SPACEBAR to continue on to the next iteration.
Type 1 for the order number and 2 for the line number.
![]()
Notice that for line 2 of order number 1, both the quantity field in the order-line record and the allocated field in the item record have been returned to their original values of 21 and 0, respectively.
Remember that each iteration of the REPEAT block started a new transaction. Once the first iteration (the shin pads) completed successfully, Progress ended the transaction and committed the changed data to the database.
Progress started another transaction on the next iteration of the REPEAT block. When you pressed STOP during that iteration, Progress backed out the transaction, undoing all database changes made since the start of the transaction.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |