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
.
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
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