/* Defines an undoable variable because the NO-UNDO option is not specified. */
DEFINE VARIABLE TargetCustNum AS INTEGER. /* The last valid value before the beginning of the DO block */ ASSIGN TargetCustNum = 1. DO ON ERROR UNDO, LEAVE: /* This value will be undone on ERROR! */ ASSIGN TargetCustNum = 15. /* Find a Customer */ FIND Customer WHERE Customer.CustNum = TargetCustNum. /* Change the database! A transaction is now active. */ ASSIGN Customer.Name = Customer.NAME + " And Much More". /* Confirm change to persistent field. */ MESSAGE "Customer Name changed to: " Customer.Name VIEW-AS ALERT-BOX BUTTONS OK. /* ERROR raised. Control passes to CATCH block. */ FIND Order OF Customer WHERE OrderNum = 1234. /* Statement will not execute. */ DISPLAY Customer.CustNum SKIP Customer.Name SKIP OrderNum SKIP OrderStatus VIEW-AS TEXT WITH FRAME b SIDE-LABELS. CATCH eSysError AS Progress.Lang.SysError: /* Confirm if Customer record is available in CATCH. */ IF AVAILABLE (Customer) THEN MESSAGE "Customer record is still available." VIEW-AS ALERT-BOX BUTTONS OK. ELSE DO: MESSAGE "No Customer record is currently available." VIEW-AS ALERT-BOX BUTTONS OK. /* Re-Find the Customer. Cannot rely on value of TargetCustNum! */ FIND Customer WHERE Customer.CustNum = 15. /* Confirm that change to database field was not committed and UNDO variable was rolled back. */ MESSAGE "TargetCustNum = " TargetCustNum SKIP "Customer name is now: " Customer.Name VIEW-AS ALERT-BOX BUTTONS OK. END. /* ELSE */ END CATCH. END. /* DO */ |