Specifying a CCSID for your application

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.

About this task

If the CCSID values do not match the actual CCSID of the data or source, data corruption might occur.

Recommendation: Having all of your CCSIDs match is ideal but not always possible. If they do not match, character conversion can occur, and you should consider the possible consequences of character conversion.

Procedure

To specify a CCSID for your application:

  1. 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 instructions: 1.a

    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 statements 1.b

    Use one or more of the following DB2 mechanisms to set the CCSID value of the application data, 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 on a COBOL or PL/I application, you can override the ENCODING bind option by using the following language compiler options:
    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.
    Notes:
    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.
    3. For DRDA applications, the ENCODING bind option does not set the CCSID of the data. In a DRDA environment, the CCSIDs are communicated as part of the protocol.
  2. 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.