ERROR-STATUS system handle

A handle to error information on the last statement executed with the NO-ERROR option.

Syntax

ERROR-STATUS [ :attribute | :method ]
attribute
Specifies an attribute of the ERROR-STATUS handle.
method
Specifies a method of the ERROR-STATUS handle.

Attributes

Methods

Examples

The following example uses the NO-ERROR and the ERROR-STATUS handle extensively to demonstrate when ERROR-STATUS attributes are reset:

r-errst1.p

CONNECT "db-xyz" NO-ERROR.
RUN chk-connect NO-ERROR.
IF ERROR-STATUS:ERROR THEN 
  MESSAGE "Run statement failed.".

PROCEDURE chk-connect:
  DEFINE VARIABLE connect-ok AS LOGICAL NO-UNDO INITIAL TRUE.

  IF ERROR-STATUS:ERROR THEN DO:
    MESSAGE "Connect failed.".
    connect-ok = FALSE NO-ERROR.
    IF ERROR-STATUS:ERROR THEN 
      MESSAGE "Assignment failed.".
  END.
   
  IF connect-ok THEN RETURN "OK".
   ELSE RETURN "FAILED".
END PROCEDURE.

Within the internal procedure, chk-connect, the first reference to ERROR-STATUS:ERROR returns status on the CONNECT statement from the main procedure. The second reference returns status on the assignment statement. The reference to ERROR-STATUS:ERROR in the main procedure returns status on the RUN statement. Note that the ERROR-STATUS attributes are set only after the statement with NO-ERROR completes. Therefore the references in the internal procedure are not affected by the RUN statement itself.

The following procedure accepts a character string value and lets you convert it to one of several data types. The internal convert procedure attempts the conversion. If the conversion is successful, it displays the converted value. If the conversion is unsuccessful, the ERROR-STATUS handle holds error information. After running convert, the CHOOSE trigger checks ERROR-STATUS:ERROR and ERROR-STATUS:NUM-MESSAGES to determine if either error information is available or messages have been returned, even if ERROR is not raised. If either condition is true, this lets you view this information. ABL includes many errors that generate messages, but do not raise the ERROR condition, such as most errors generated by ABL built-in functions and handle methods.

r-errsts.p

DEFINE VARIABLE txt AS CHARACTER NO-UNDO FORMAT "X(20)".
DEFINE VARIABLE ix  AS INTEGER   NO-UNDO.

DEFINE BUTTON b_int  LABEL "Integer".
DEFINE BUTTON b_date LABEL "Date".
DEFINE BUTTON b_dec  LABEL "Decimal".
DEFINE BUTTON b_log  LABEL "Logical".
DEFINE BUTTON b_quit LABEL "Quit" AUTO-ENDKEY. 
  
DEFINE FRAME butt-frame
  b_int b_date b_dec b_log b_quit
  WITH CENTERED ROW SCREEN-LINES - 2.
DEFINE FRAME get-info
  txt LABEL "Enter Data To Convert"
  WITH ROW 2 CENTERED SIDE-LABELS TITLE "Data Conversion - Error Check".
  
ON CHOOSE OF b_int, b_date, b_dec, b_log IN FRAME butt-frame DO:
  IF txt:MODIFIED IN FRAME get-info THEN DO:
    ASSIGN txt.
    RUN convert(txt).
    IF ERROR-STATUS:ERROR OR ERROR-STATUS:NUM-MESSAGES > 0 THEN DO:
      MESSAGE ERROR-STATUS:NUM-MESSAGES 
        " errors occurred during conversion." SKIP 
        "Do you want to view them?" 
        VIEW-AS ALERT-BOX QUESTION BUTTONS YES-NO 
        UPDATE view-errs AS LOGICAL.
      IF view-errs THEN
      DO ix = 1 TO ERROR-STATUS:NUM-MESSAGES:
        MESSAGE ERROR-STATUS:GET-NUMBER(ix) ERROR-STATUS:GET-MESSAGE(ix).
      END.
    END.
  END. /* IF txt:MODIFIED... */
  ELSE
    MESSAGE "Please enter data to be converted, then choose the type of
conversion to perform."
      VIEW-AS ALERT-BOX MESSAGE BUTTONS OK.
END.

ENABLE ALL WITH FRAME butt-frame.
ENABLE txt WITH FRAME get-info.
WAIT-FOR CHOOSE OF b_quit IN FRAME butt-frame FOCUS txt IN FRAME get-info.

PROCEDURE convert:
  DEFINE INPUT PARAMETER cText AS CHARACTER NO-UNDO.

  DEFINE VARIABLE dValue AS DATE    NO-UNDO.
  DEFINE VARIABLE fValue AS DECIMAL NO-UNDO.
  DEFINE VARIABLE iValue AS INTEGER NO-UNDO.
  DEFINE VARIABLE lValue AS LOGICAL NO-UNDO.
  
  MESSAGE SELF:LABEL.

  CASE SELF:LABEL:
    WHEN "Integer" THEN DO:
      ASSIGN iValue = INTEGER(cText) NO-ERROR.
      MESSAGE "Converted value:" iValue.
    END.
    WHEN "Date" THEN DO:
      ASSIGN dValue = DATE(INTEGER(SUBSTRING(cText,1,2)),
                       INTEGER(SUBSTRING(cText,4,2)),
                       INTEGER(SUBSTRING(cText,7)) ) NO-ERROR.
      MESSAGE "Converted value:" dValue.
    END. 
    WHEN "Decimal" THEN DO:
      ASSIGN fValue = DECIMAL(cText) NO-ERROR.
      MESSAGE "Converted value:" fValue.
    END.
    WHEN "Logical" THEN DO:
      ASSIGN lValue = (cText = "yes" OR cText = "true") NO-ERROR.
      MESSAGE "Converted value:" lValue.
    END.
  END.
END PROCEDURE.

Notes

See also

SOAP-fault object handle, SOAP-fault object handle