What is the purpose and usage of SQLCODE within the SQLCA in a COBOL-DB2 program


The SQLCODE field of SQLCA is used to get the return code for the last executed SQL query from DB2 to COBOL program. Below are the range of return codes which SQLCODE field can take along with their significance.

SQLCODE = 0 → Query executed successfully without any issue.

SQLCODE > 0 → There was a warning issued while executing the query.

SQLCODE < 0 → There was an error occurred while executing the query.

Below is the sample paragraph where the usage of SQLCODE is demonstrated.

A010-CHECK-ORDER.
EXEC SQL
   SELECT ORDER_DATE
      INTO :ORDER-DATE,
      FROM ORDERS
      WHERE ORDER_ID = :ORDER-ID
END-EXEC
   EVALUATE SQLCODE
      WHEN 0
         DISPLAY ‘ROW FETCHED SUCCESSFULLY’
      WHEN 100
         DISPLAY ‘DATA NOT FOUND’
      WHEN OTHER
         DISPLAY ‘ERROR WHILE FETCHING THE ROW’ SQLCODE
END-EVALUATE

Updated on: 14-Sep-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements