Kbase P95931: How to check if an error occurs after SAVE-ROW-CHANGES and return the error messages
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  9/7/2005 |
|
Status: Unverified
GOAL:
How to check if an error occurs after SAVE-ROW-CHANGES?
GOAL:
How to return the precise errors that occur during a SAVE-ROW-CHANGES operation?
GOAL:
Where is the ERROR flag set when SAVE-ROW-CHANGES fails?
GOAL:
Why ERROR-STATUS:ERROR returns FALSE after SAVE-ROW-CHANGES fails?
FACT(s) (Environment):
OpenEdge 10.0x
FIX:
When SAVE-ROW-CHANGES fails to update the record, the ERROR flag is NOT set to the ERROR-STATUS system handle. SAVE-ROW-CHANGES sets the ERROR attribute to TRUE for the ProDataSet,temp-table and the particular buffer that failed in the save attempt.
The following is an example that check if SAVE-ROW-CHANGES fails:
/* Sample Code */
DEFINE TEMP-TABLE ttcustomer NO-UNDO
BEFORE-TABLE ttBefore
FIELD custnum LIKE customer.custnum
FIELD NAME LIKE customer.NAME.
DEFINE QUERY qCustomer FOR Customer SCROLLING .
DEFINE DATASET ds FOR ttCustomer.
DEFINE DATA-SOURCE srcCustomer FOR QUERY qCustomer .
QUERY qCustomer:QUERY-PREPARE("for each Customer").
BUFFER ttCustomer:ATTACH-DATA-SOURCE(DATA-SOURCE srcCustomer:HANDLE).
DATASET ds:FILL().
TEMP-TABLE ttCustomer:TRACKING-CHANGES = YES.
FIND FIRST ttcustomer WHERE ttCustomer.CustNum = 1.
ttCustomer.NAME = ttCustomer.NAME + "@@".
/* Save-row-changes for this record will fail due to a duplicated unique key */
FIND FIRST ttcustomer WHERE ttCustomer.CustNum = 3 .
ttCustomer.NAME = ttCustomer.NAME + "@@".
ttCustomer.CustNum = 1.
FIND FIRST ttcustomer WHERE ttCustomer.CustNum = 6 .
ttCustomer.NAME = ttCustomer.NAME + "@@".
TransBlock:
FOR EACH ttBefore TRANSACTION:
BUFFER ttBefore:SAVE-ROW-CHANGES() NO-ERROR.
IF BUFFER ttBefore:ERROR THEN DO:
IF ERROR-STATUS:NUM-MESSAGES > 0 THEN DO:
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 1 TO ERROR-STATUS:NUM-MESSAGES:
BUFFER ttBefore:ERROR-STRING = (IF BUFFER ttBefore:ERROR-STRING = ? THEN "" ELSE BUFFER ttBefore:ERROR-STRING)
+ STRING(ERROR-STATUS:GET-NUMBER(i)) + ": "
+ ERROR-STATUS:GET-MESSAGE(i) + CHR(13). /* 6 */
END.
IF BUFFER ttBefore:ERROR-STRING <> "" THEN
MESSAGE BUFFER ttBefore:ERROR-STRING
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
END.
END.
FIND FIRST Customer WHERE Customer.CustNum = 1 .
MESSAGE Customer.CustNum Customer.NAME VIEW-AS ALERT-BOX.
FIND FIRST Customer WHERE Customer.CustNum = 3 .
MESSAGE Customer.CustNum Customer.NAME VIEW-AS ALERT-BOX.
FIND FIRST Customer WHERE Customer.CustNum = 6 .
MESSAGE Customer.CustNum Customer.NAME VIEW-AS ALERT-BOX.