After the execution of each SQL statement (other than ``++DECLARE CURSOR++``, ``++DECLARE TABLE++`` and ``++DECLARE VARIABLE++``), the value of ``++SQLCODE++`` or ``++SQLSTATE++`` should be checked before proceeding. A 0 ``++SQLCODE++`` value means the statement succeeded, a positive value means success with a warning, and a negative value indicates an error. Proceeding without checking could put your program or your data in a bad state.


== Noncompliant Code Example

[source,text]
----
EXEC SQL
  SELECT name INTO :username FROM user WHERE id = :userid
END-EXEC.

DISPLAY username.    *> Noncompliant
----


== Compliant Solution

[source,text]
----
EXEC SQL
  SELECT name INTO :username FROM user WHERE id = :userid
END-EXEC.

IF SQLCODE = 0 THEN
  DISPLAY username
END-IF.
----


== Exceptions

When the value of ``++SQLCODE++`` or ``++SQLSTATE++`` is not checked but transferred to another variable for later use, no issue is raised.

----
EXEC SQL
  SELECT name INTO :username FROM user WHERE id = :userid
END-EXEC.
MOVE SQLCODE TO SQL-RETURN-CODE
----

