Backs out all modifications to fields and variables made during the current iteration of a block, and indicates what action to take next.
UNDO [ label ] [ , LEAVE [ label2 ] | , NEXT [ label2 ] | , RETRY [ label1 ] | , RETURN [ return-value | ERROR [ return-value | error-object-expression ] | NO-APPLY ] | , THROW error-or-stop-object-expression ] |
The name of the block whose processing you want to undo. If you do not name a block with label1, UNDO undoes the processing of the closest transaction or subtransaction block. In determining the closest transaction or subtransaction block, the AVM disregards DO ON ENDKEY blocks that do not have the ON ERROR or TRANSACTION option.
Indicates that after undoing the processing of a block, the AVM leaves the block you name with label2. If you do not name a block with the LEAVE option, the AVM leaves the block that was undone. After leaving a block, the AVM continues on with any remaining processing in a routine.
Indicates that after undoing the processing of a block, the AVM does the next iteration of the block you name with label2. If you do not name a block, the AVM does the next iteration of the block that was undone.
Indicates that after undoing the processing of a block, the AVM repeats the same iteration of the block you name with label1. If you name a block with label1 it must be the name of the block that was undone.
RETRY is the default processing if you do not use LEAVE, NEXT, RETRY, or RETURN. When a block is retried, any frames scoped to that block are not advanced or cleared.
Returns to the calling routine, or if there is no calling routine, returns to the OpenEdge Editor. The following table describes various RETURN cases:
Option | Description |
---|---|
return-value |
The CHARACTER string you provide is passed to the caller. The caller can use the RETURN-VALUE function to read the returned value. |
ERROR |
Raises ERROR in the caller and undoes the current subtransaction. |
ERROR return-value |
Raises ERROR in the caller and undoes the current
subtransaction. The CHARACTER string you provide is passed to the caller. The
caller can use the RETURN-VALUE function to read the returned value. The AVM also creates an Progress.Lang.AppError object and stores the return-value in the ReturnValue property. Note: User-defined functions have different
behavior since they must return the data type specified in the definition.
See the FUNCTION statement for more
information.
|
ERROR error-object-expression |
Raises ERROR in the caller and undoes the current
subtransaction. The specified error object is created and populated according to your code. If this is an Progress.Lang.AppError object, the caller can use the RETURN-VALUE function to read the setting of the ReturnValue property. |
NO-APPLY |
In a user-interface trigger, prevents the AVM from performing the default behavior for that event. |
You cannot specify ERROR within a user-interface trigger block or a destructor. You can specify the NO-APPLY option only within a user-interface trigger block.
The THROW directive stops the execution of the current block of ABL code, or the current iteration of an ABL iterating block, and raises the ERROR or STOP condition specified in error-or-stop-object-expression. The value of error-or-stop-object-expression must be an error or stop object type.
In this example, the THROW directive creates an instance of Progress.Lang.AppError using one of the default object constructors:
You can only THROW error or stop objects. An error object is an object that implements the built-in interface, Progress.Lang.Error. A stop object can be an instance of the built-in class Progress.Lang.Stop or one of its built-in subclasses, or it can be an instance of Progress.Lang.StopError, which is a built-in subclass of Progress.Lang.SysError and also implements the Progress.Lang.Error interface. It is a compile-time error to THROW an object that does not implement Progress.Lang.Error or that is not Progress.Lang.Stop or one of its subclasses.
When the THROW occurs, execution stops, and the specified ERROR or STOP condition is raised. An ERROR condition should then be handled by the NO-ERROR qualifier, a CATCH block, or by an explicit or implicit ON ERROR phrase. A STOP condition should then be handled by a CATCH block or by an explicit or implicit ON STOP phrase; otherwise the STOP condition is thrown all the way to the top of the call stack.
The following notes describe restrictions on using UNDO, THROW:
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. |