Progress
Programming
Handbook


Transactions and Subprocedures

If you start a transaction in a main procedure, that transaction remains active even while the main procedure runs called procedures. For example, p-txn11.p runs p-txn11a.p within a transaction:

p-txn11.p
DEFINE VARIABLE answer AS LOGICAL. 
DEFINE NEW SHARED VARIABLE cust-num-var AS ROWID. 
REPEAT WITH 1 DOWN: 
    PROMPT-FOR customer.cust-num. 
    FIND customer USING cust-num. 
    DISPLAY name sales-rep. 
    UPDATE credit-limit balance. 
    SET answer LABEL "Do you want to do order processing?" 
          WITH FRAME a NO-HIDE. 
    IF answer THEN DO: 
       cust-num-var = ROWID(customer). 
       RUN p-txn11a.p. 
    END. 
END. 

This procedure lets you update customer information and then asks if you want to process the customer’s orders. If you say yes, the procedure runs a second procedure called p-txn11a.p.

p-txn11a.p
DEFINE SHARED VARIABLE cust-num-var AS ROWID. 
HIDE ALL. 
FIND customer WHERE ROWID(customer) = cust-num-var. 
FOR EACH order OF customer: 
    UPDATE order WITH 2 COLUMNS. 
    FOR EACH order-line OF order: 
      UPDATE order-line. 
  END. 
END. 

The REPEAT block in the p-txn11.p procedure is the transaction block for that procedure: it contains a direct update to the database. The transaction begins at the start of each iteration of the REPEAT block and ends at the end of each iteration. That means that, when the p-txn11.p procedure calls the p-txn11a.p procedure, the transaction is still active. So all the work done in the p-txn11a.p subroutine is part of the transaction started by the main procedure, p-txn11.p. The following figure, illustrates the start and end of the full transaction.

Figure 12–3: The Transaction Block for the p-txn11.p Procedure

If a system error occurs while you are processing orders for a customer, Progress undoes all the order processing work you have done for that customer, as well as any changes you made to the customer record itself.


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