PreviousNextIndex

UNDO statement

Backs out all modifications to fields and variables made during the current iteration of a block, and indicates what action to take next.

Syntax

UNDO 
  [ label ] 
  [     , LEAVE [ label2 ]  
     |  , NEXT [ label2 ]  
     |  , RETRY [ label1 ]  
     |  , RETURN [ return-value | 
                  ERROR [ return-value | error-object-expression ] | 
                  NO-APPLY ]  
     |  , THROW error-object-expression 
  ] 

label
LEAVE label2
NEXT label2
RETRY label1
RETURN ...
THROW error-object-expression
Examples

The r-undo.p procedure prompts you for the initials of a sales representative. If the initials match those of an existing sales representative, the procedure displays that sales representative’s record. Otherwise, it prompts you to add another sales representative with the initials you supplied. If you enter no, the UNDO statement undoes the work you have done since the start of the REPEAT block and lets you enter another set of initials.

r-undo.p
DEFINE VARIABLE ans AS LOGICAL NO-UNDO. 
REPEAT FOR SalesRep WITH ROW 7 1 COLUMN 1 DOWN CENTERED ON ENDKEY UNDO, LEAVE: 
  PROMPT-FOR SalesRep.SalesRep. 
  FIND SalesRep USING SalesRep.SalesRep NO-ERROR. 
  IF NOT AVAILABLE salesrep THEN DO: 
    ans = TRUE. 
    MESSAGE "SalesRep record does not exist.". 
    MESSAGE "Do you want to add a SalesRep?" UPDATE ans. 
    IF ans THEN DO: 
      CREATE SalesRep. 
      ASSIGN SalesRep.SalesRep. 
      UPDATE SalesRep.RepName SalesRep.Region SalesRep.MonthQuota. 
    END. 
    ELSE UNDO, RETRY. 
  END. 
  ELSE DISPLAY SalesRep. 
END. 

This example shows how the UNDO, THROW statement specifies and populates an error object, and how the CATCH block handles it:

r-undothrow1.p
FIND Customer 1000 NO-ERROR. 
/* Raises error on current block (main block of .p); execution goes to CATCH 
   below */ 
IF ERROR-STATUS:ERROR THEN  
  UNDO, THROW NEW Progress.Lang.AppError("Can't find this customer", 550). 
MESSAGE Customer.CustNum. /* This code does not execute if FIND fails */ 
/* This CATCH is on the main block of r-undothrow1.p */ 
CATCH eAppError AS Progress.Lang.AppError: 
  MESSAGE eAppError:GetMessage(1) eAppError:GetMessageNum(1). 
END CATCH. 

Notes
See also

ON ENDKEY phrase, ON ERROR phrase, RETRY function, RETURN statement, ROUTINE-LEVEL ON ERROR UNDO, THROW statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex