Labels can be used to undo the transaction associated with the outer block, rather than just the subtransaction of the inner block.

The following example sets up a common set of nested FOR EACH blocks that list the order numbers for the first few customer records in the Sports2000 database. Within the inner block, a nonsensical FIND statement raises error after the first iteration. This trivial framework allows you to test the interactions of ON ERROR phrases.

PROCEDURE NestedBlocks:
    
Outer-Block: 
    FOR EACH Customer WHERE CustNum < 5:
        ASSIGN Customer.Name = Customer.Name + "_changed".

Inner-Block: 
        FOR EACH Order OF Customer 
            ON ERROR UNDO Outer-Block, RETURN:

            DISPLAY OrderNum.

            /* Nonsense code raises ERROR. */
            FIND SalesRep WHERE RepName = Customer.Name.

        END. /* Inner-Block */ 
    END. /* Outer-Block */

    DISPLAY "For Blocks Complete".
END PROCEDURE.

RUN NestedBlocks.

DISPLAY "Procedure NestedBlocks Complete."

The flow of this example is as follows:

  1. The ASSIGN statement in Outer-Block starts a transaction.
  2. The FIND statement in Inner-Block raises the ERROR condition.
  3. The error message is displayed.
  4. The explicit ON ERROR phrase of Inner-Block activates, causing the entire Outer-Block transaction to be undone, and a RETURN to the main block.
  5. The string "Procedure NestedBlocks Complete." is displayed.