== Why is this an issue?

``++CAST(... AS CHAR/VARCHAR)++`` can be a source of incompatibilities between database versions: the behavior of ``++CAST++`` may not be the same depending on the version of the database system. Such incompatibilities can cause unexpected output from applications that ``++CAST++`` decimal data to ``++CHAR++`` or ``++VARCHAR++``, it's therefore best to avoid using ``++CAST(... AS CHAR/VARCHAR)++``.


=== Noncompliant code example

[source,cobol]
----
  DELETE product
  WHERE CAST(status_code AS CHAR(2)) = '42' -- Noncompliant
----



ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Avoid using 'CAST(... AS CHAR/VARCHAR)'


'''
== Comments And Links
(visible only on this page)

=== on 25 Oct 2016, 11:36:16 Nicolas Bontoux wrote:
+References+:

* http://www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/sqlref/src/tpc/db2z_castspecification.html[CAST specification]
* http://www.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/apsg/src/tpc/db2z_relincompatapplsqlfromv9.html[IBM note on SQL release incompatibilities] (see section _Changes to string formatting of decimal data_)

endif::env-github,rspecator-view[]
