Try OpenEdge Now
skip to main content
Error Handling
Traditional Error Handling : Undoing work
 

Undoing work

The options of the UNDO statement and the ON ERROR phrase are nearly identical. The UNDO statement serves the role of undoing the work of the block when your business logic detects a problem that needs to be treated as an application error. Therefore, you need the same set of branching options to provide the same level of support for handling application errors.
Borrowing the test framework from Providing custom error handling section, this example removes the explicit ON ERROR phrase and provides a nonsensical IF test that always leads to the execution of the UNDO statement:
PROCEDURE NestedBlocks:

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

Inner-Block:
FOR EACH Order OF Customer:

DISPLAY OrderNum.

/* Nonsense code tests for application error. */
IF SUBSTRING(Customer.Name, 1, 8) EQ "changed_" THEN
UNDO, RETURN ERROR.
END.
END.

DISPLAY "For Blocks Complete".
END PROCEDURE.

RUN NestedBlocks.

DISPLAY "Procedure NestedBlocks Complete."