In Db2 for z/OS® applications,
one CCSID is associated with the source code and one or more CCSIDs
can be associated with the data that your application manipulates.
The CCSID that Db2 associates
with the data is called the application encoding scheme.
Before you begin
If the CCSID values for your application do not match the actual CCSID of the data or source, data corruption might occur.
Important: For best results, try to avoid character conversions whenever possible, because conversions can potentially slow performance and sometimes cause data loss. The best way to avoid conversions is to use the same CCSID for all of your data. For more information, see
Possible consequences of character conversion.
Procedure
To specify a CCSID for your application, use the following approaches:
- Use the options as shown in the following table:
Table 1. Options to
set application CCSIDs
Item for which you want to specify the CCSID |
Option to use |
Application source code (which includes SQL
statements and literal strings in the SQL statements) |
If you are using the Db2 precompiler, use the CCSID SQL processing option when you precompile the application. Specify the same CCSID when you compile the application.
If you are using the Db2 coprocessor, use the language compiler to set the CCSID. For COBOL, PL/I, and C/C++, use the following instructions1:
The default CCSID for the application source code is the subsystem
EBCDIC CCSID (DECP value SCCSID or MCCSID). Db2 uses this value if you do not use one of
the preceding mechanisms to specify a CCSID.
Restriction: The
compilers for high level host languages do not support Unicode source
code.
|
Application data (values that are passed through host variables and parameter markers) within SQL statements2 |
You can use one or more of the following Db2 approaches to specify CCSID values for the application data3, which is called the application encoding scheme:
The default CCSID for the application data is the subsystem
default application encoding scheme. For static SQL (host variables),
this value is the APPENSCH value from the DECP that is loaded when
you bind your application. For dynamic SQL (parameter markers), this
value is the APPENSCH value from the DECP that is loaded at the time
that the application is executed.
Alternatively, if you are using the Db2 coprocessor for COBOL or PL/I applications, you can override the ENCODING bind option by using language-specific compiler options. For more information, see the following topics:
|
Application data that is referenced outside
of SQL statements |
Use the rules of the programming language. In
some cases, the CCSID of this data is the same as the CCSID of the
source code. |
- Optional: If
you want to confirm which CCSID value the Db2 precompiler used, look at the precompiler
listing. If you want to confirm which CCSID value the Db2 coprocessor used, look at the compiler listing.
If you need help finding the CCSID values in these listings,
see the example listings in
Finding the CCSID values of your data sources.
You can also use these listings to confirm which DECP
module Db2 used. Knowing which
DECP module is useful if you modified a DECP value, such as APPENSCH,
before you compiled or executed your program. You can see which DECP
module and which values Db2 used.
1 For older compilers that do not pass a CCSID value to the
Db2 coprocessor, use the SQL compiler option with the CCSID suboption to specify a value.
2 You can specify different CCSIDs for different pieces of data in one application. However, if you specify multiple CCSIDs, do so with caution.
4 For DRDA applications, the ENCODING bind option does not set the CCSID of the data, and CCSIDs are communicated as part of the protocol.