1

In SQLRPGLE programming I have seen that the SQLSTATE and SQLCODE being used in several areas in order to catch an error in the sql statement. My query is what is the difference between SQLSTATE and SQLCODE because I see them to be used for similar purpose. Is there any special scenario where SQLSTATE or SQLCODE is used or are they the same?

Kunal Roy
  • 729
  • 3
  • 11
  • During SQLRPGLE programming using SQLCODE is more simple.. [Look here](https://www.ibm.com/docs/en/i/7.3?topic=codes-listing-sqlstate-values) ... SQLCode Zero (no error) can have more SQLSTATE (with only a warning) – Nifriz Feb 14 '22 at 09:47
  • Unfortunately, I don't think it's clear which is more simple. The [docs](https://www.ibm.com/docs/en/i/7.4?topic=codes-sqlcode-sqlstate-concepts) actually say "SQLSTATE is related to SQLCODE. Every SQLSTATE has one or more SQLCODEs associated with it. An SQLSTATE can refer to more than one SQLCODE." Which sounds kind of like the opposite of what Nifriz is saying. However, that is an oversimplification as well. Some SQLCODE values correspond to more than one SQLSTATE (as Nifriz points out). So you really have to just look at the meanings and decide what you are really testing for. – John Y Feb 14 '22 at 15:25

1 Answers1

4

Short version, SQLCODE is DB2 for IBM i specific, SQLSTATE is standard

See here

SQLSTATE is the preferred standard return code. It provides application programs with return codes for common error conditions found among the DB2® products.

SQLSTATE values are consistent with the SQLSTATE specifications that are contained in the SQL 1999 standard.

Charles
  • 21,637
  • 1
  • 20
  • 44
nfgl
  • 2,812
  • 6
  • 16