Progress
Programming
Handbook


Making Transactions Smaller

Now imagine the reverse situation to the one in the last section. That is, in the event of a system crash or pressing STOP, you want to undo only the current order–line. Again, you use a DO block with the TRANSACTION option to tell Progress where to start transactions:

p-txn10.p
REPEAT: 
    DO TRANSACTION: 
        INSERT order WITH 2 COLUMNS. 
        FIND customer OF order. 
    END. 
    REPEAT TRANSACTION: 
        CREATE order-line. 
        order-line.order-num = order.order-num. 
        DISPLAY order-line.order-num. 
        UPDATE line-num order-line.item-num qty price. 
        FIND item OF order-line. 
    END. 
END. 

In p-txn10.p, Progress starts a transaction for each order and also for each order–line you enter. There are two outermost blocks that contain direct updates to the database:

The outer REPEAT block is not the transaction block because it does not contain any direct updates to the database. Run p-txn10.p, entering the following data:

Press STOP while entering the second order–line. Progress undoes the current transaction block, which means that only the work done on the second order–line is undone. Order 1030 and the first order–line should be in the database. Run p-check.p to find out:

p-check.p
PROMPT-FOR order.order-num. 
FIND order USING order-num. 
DISPLAY order WITH 2 COLUMNS. 
FOR EACH order-line OF order: 
  DISPLAY order-line. 
END. 

Note that any activity that occurs within a DO block that has no TRANSACTION or ON ERROR phrase in the block header is encompassed in an enclosing transaction or subtransaction and does not result in a transaction or subtransaction being started.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095