STATUS

STATUS is a predefined variable that contains the execution status of the last instruction.

Syntax

STATUS

Usage

STATUS is a predefined variable that contains the execution status of the last program instruction.

STATUS allows diagnostic information about procedural, interactive, and SQL instructions to be obtained.

The data type of STATUS is INTEGER.

Note: While STATUS can be modified by hand, it is not recommended except in specific situations as shown in the STATUS example.

STATUS is typically used with WHENEVER ERROR CONTINUE or WHENEVER ERROR CALL, or TRY/CATCH blocks, to identify the type of error that occurred.

STATUS will be set for expression evaluation errors only when WHENEVER ANY ERROR is used.

After an SQL statement execution, STATUS contains the value of SQLCA.SQLCODE.

STATUS is set to an error code when an instruction produces an error, or it is reset to zero when non-assignment instructions succeed. A typical mistake is to test STATUS after a DISPLAY STATUS instruction, written after an SQL statement:
WHENEVER ERROR CONTINUE
DELETE FROM _invalid_table_name_ where col = 1
WHENEVER ERROR STOP
DISPLAY "STATUS:", STATUS   -- this DISPLAY instruction reset STATUS to zero
IF STATUS<0 THEN            -- Will never be the case, since STATUS==0
   DISPLAY "SQL Error!"
   EXIT PROGRAM 1
END IF
Tip: Use SQLCA.SQLCODE for SQL error detection, and use STATUS for other language instructions.

Example

MAIN
  DISPLAY is_number(NULL)
  DISPLAY is_number("abc")
  DISPLAY is_number("-12.45")
END MAIN

FUNCTION is_number(s)
  DEFINE s STRING
  DEFINE f FLOAT, l_status INTEGER
  IF length(s)==0 THEN
     RETURN FALSE
  END IF
  WHENEVER ANY ERROR CONTINUE
  LET STATUS=0 # Needed, as STATUS won't be set if succeeds
  LET f = s
  LET l_status = STATUS
  WHENEVER ANY ERROR CONTINUE
  IF l_status == 0 THEN
     RETURN TRUE
  ELSE
     RETURN FALSE
  END IF
END FUNCTION