Specifying CCSIDs for COBOL applications when using the Db2 coprocessor

If you are using the Db2 coprocessor to prepare a COBOL application with SQL statements, use the COBOL compiler to specify the CCSID of the application source code. For optimal performance, use Db2 to specify the CCSID of the application data in SQL statements.

About this task

The COBOL compiler accepts only one CCSID value that it uses for both the application source code and data. However, Db2 can accept one CCSID value for the source code and one or more CCSID values for the data that is manipulated in SQL statements through host variables and parameter markers.

Procedure

To specify CCSIDs for COBOL applications when using the Db2 coprocessor:

  1. To specify the CCSID of the COBOL application source code, use the CODEPAGE compiler option. 1
    For example, both of the following JCL EXEC statements for COBOL compile jobs specify a CCSID of 37:
    //COB  EXEC  PGM=IGYCRCTL,PARM='...,SQL,CODEPAGE(037),...
    //COB EXEC PGM=IGYCRCTL,PARM='...,SQL,CP(37),...

    Otherwise, if you do not specify the CODEPAGE compiler option, the default COBOL compiler CCSID is passed to the Db2 coprocessor and is used as the CCSID for the source code. The default COBOL compiler CCSID is 1140 unless you changed it.

    The following JCL EXEC statement for a COBOL compile job does not explicitly specify a CCSID. In this case, the COBOL compiler passes the default CCSID, 1140, to the Db2 coprocessor.
    //COB EXEC PGM=IGYCRCTR,PARM='...,SQL(),...'

    CCSID 1140 is the equivalent to CCSID 37 plus the euro symbol (). However, be aware that conversions, and thus conversion cost, still occur between CCSID 1140 and CCSID 37.

    Recommendation: If you are using the Db2 coprocessor on a COBOL application, do not specify the SQL compiler option with the CCSID suboption. If you specify it anyway, and it conflicts with the CODEPAGE compiler value, Db2 issues a warning. 2 For example, the following EXEC statement for a COBOL compile job specifies a CCSID value of 1140; the CCSID value 37 is ignored:
    //COB EXEC PGM=IGYCRCTR,PARM='CP(1140),SQL("CCSID(37)")'

    To verify which CCSID value was used, look at the compiler listing and check the CCSID option.

  2. To specify whether Db2 or the COBOL compiler determines the CCSID of application data for host variables and parameter markers in the program, specify one of the following compiler options:
    NOSQLCCSID (Recommended option)

    Specifies that the CCSID that is passed from the COBOL compiler is used only for the COBOL application source and string literals. That CCSID is not used for the host variables and parameter markers in SQL statements. For host variables and parameter markers, Db2 uses the CCSIDs that are specified through Db2 mechanisms, as described in the next step.

    Specifying NOSQLCCSID typically yields better performance, because you can then use a Db2 mechanism to specify the host variable CCSIDs.

    NOSQLCCSID simulates the behavior of the precompiler. Specify this option for existing applications that previously used the Db2 precompiler and now use the Db2 coprocessor. By default, the Db2 coprocessor uses the same CCSID value that is passed from the COBOL CODEPAGE(nnnnn) compiler option for both the source code and data. This behavior is different than the Db2 precompiler, which does not use the CCSID from the COBOL compiler. For applications that use the Db2 precompiler, you specify the CCSID for the data through Db2 mechanisms only. When you specify NOSQLCCSID, Db2 does not use the COBOL CCSID for the application data.

    SQLCCSID (default option)
    Specifies that the Db2 coprocessor is to use the CCSID from the COBOL CODEPAGE(nnnnn) compiler option for your application data. 2 The CCSID value is the same one that you specified for your COBOL source code.
  3. Optional: Start of changeIf you specified the NOSQLCCSID compiler option, you can specify different encoding schemes for data processed by the program. 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:
    End of change
  4. If you want to specify a Unicode CCSID for a particular variable, declare it as a PIC N USAGE NATIONAL variable.
    For COBOL PIC N USAGE NATIONAL variables, the Db2 coprocessor always uses the CCSID 1200. You do not need to use a DECLARE VARIABLE statement with the CCSID clause for these variables.

Example

The following table shows examples of the CCSID that Db2 uses for data in COBOL applications depending on the options that you specify. This table assumes that you did not specify any DECLARE VARIABLE statements with the CCSID clause.

Table 1. CCSID resolution for data in COBOL applications that use the Db2 coprocessor
Variable ENCODING bind option COBOL compiler options CCSID that Db2 uses for the data
CODEPAGE(nnnn)1 (NO)SQLCCSID
PIC X not explicitly specified 1140 SQLCCSID 11402
PIC X not explicitly specified 1140 NOSQLCCSID Subsystem default application encoding scheme (DECP value APPENSCH)3
PIC X 273 1140 SQLCCSID 11402
PIC X 273 1140 NOSQLCCSID 2734
PIC X UNICODE 1140 SQLCCSID 11402
PIC X UNICODE 1140 NOSQLCCSID 1208

This CCSID does not logically make sense for COBOL.

5
PIC N USAGE NATIONAL 1140 1140 NOSQLCCSID 12006
Notes:
  1. This value can be the value that you explicitly specify with the CODEPAGE compiler option or the default COBOL compiler code page.
  2. Because you specified SQLCCSID, Db2 uses the code page value from the COBOL compiler.
  3. Because you specified NOSQLCCSID, Db2 does not use the COBOL code page value. Additionally, because you did not explicitly specify a value for the ENCODING bind option, Db2 uses the default application encoding scheme.
  4. Because you specified NOSQLCCSID, Db2 does not use the COBOL code page value. Instead, Db2 uses the value that you specified for the ENCODING bind option.
  5. Because you specified NOSQLCCSID and the ENCODING bind option UNICODE, Db2 uses CCSID 1208, which is UTF-8. However, COBOL does not support 1208 as a native data type. So, although you can specify this combination of options, do not do so.
  6. Because you specified a PIC N USAGE NATIONAL variable, Db2 uses CCSID 1200.
1 If you are using an older compiler that does not otherwise pass a CCSID value to Db2, use the SQL compiler option with the CCSID suboption to specify the CCSID of the application source. For example, the following EXEC statement for a COBOL compile job specifies a source CCSID of 1140.
//COB EXEC PGM=IGYCRCTR,PARM='SQL("CCSID(1140)"'
2 The exception is if you are using an older compiler that does not otherwise pass a CCSID value to the Db2 coprocessor. In this case, you need to specify the SQL compiler option with the CCSID suboption.
3 Use caution if you specify different CCSIDs for different pieces of data, which can result in character conversion.
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.