Specifying CCSIDs for PL/I applications when using the Db2 coprocessor

If you are using the Db2 coprocessor to prepare a PL/I application with SQL statements, use the PL/I 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 PL/I 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 PL/I applications when using the Db2 coprocessor:

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

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

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

    CCSID 1140 is 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 to prepare a PL/I application, do not specify the PL/I preprocessor option SQL 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 PL/I compile job specifies the CODEPAGE compiler option with a CCSID value of 1140; the CCSID value 37 is ignored:
    //PLI EXEC PGM=IBMZPLI,PARM='CP(1140),PP(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 PL/I compiler determines the CCSID of application data for host variables and parameter markers in the program, specify one of the following PP compiler options.
    CCSID0 (default)
    Specifies that only host variables with the WIDECHAR data type are to be assigned a CCSID value by the Db2 coprocessor (PL/I SQL preprocessor). Host variables with the WIDECHAR data type are always assigned a CCSID value of 1200.

    If your program updates FOR BIT DATA columns with a data type that is not BIT data, choose CCSID0. CCSID0 informs Db2 that the host variable is not associated with a CCSID, allowing the assignment to be made.

    Specifying CCSID0 can yield better performance, because you can then use a Db2 mechanism, such as the ENCODING bind option, to specify the host variable CCSIDs.

    CCSID0 simulates the behavior of the Db2 precompiler, which does not use the CCSID from the PL/I compiler for host variable data.

    The following examples of the PARM clause specify the PP PL/I preprocessor option of the PL/I compiler with the SQL suboption CCSID0.
    PARM='S,XREF,PP(SQL(APOSTSQL,CCSID0))' 
    PARM='S,XREF,PP(SQL(APOSTSQL))'
    NOCCSID0
    Allows host variables to be assigned a CCSID value by the PL/I SQL preprocessor. If the PL/I SQL preprocessor CODEPAGE option is not also specified, or if the PL/I SQL preprocessor NOCODEPAGE option is also specified, the compiler CODEPAGE option is used as the CCSID for SQL host variables of the CHARACTER data type.

    The following example of the PARM clause specifies the PP PL/I preprocessor option of the PL/I compiler with the SQL suboption NOCCSID0.

    PARM='S,XREF,PP(SQL(APOSTSQL,NOCCSID0))' 
    CODEPAGE
    Specifies that the compiler CODEPAGE option is always used as the CCSID for SQL host variables of the CHARACTER type. The following example of the PARM clause specifies the PP PL/I preprocessor option of the PL/I compiler with the SQL suboption CODEPAGE.
    PARM='S,XREF,PP(SQL(APOSTSQL,CODEPAGE))' 

    For more information ,see.PL/I PP compiler option.

  3. Optional: Start of changeIf you specified the CCSID0 option, you can specify a different encoding scheme for data processed by the application. You can use one or more of the following Db2 approaches to specify CCSID values for the application data2, 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 WIDECHAR variable, and use the default SQL preprocessor option of CCSID0. For PL/I variables in applications that are processed by the Db2 coprocessor, the Db2 coprocessor always uses CCSID 1200 for WIDECHAR variables. 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 PL/I applications depending on the options that you specify.

Table 1. CCSID resolution for data in PL/I applications that use the Db2 coprocessor
Variable ENCODING bind option PL/I options CCSID that Db2 uses for the data
PL/I CODEPAGE compiler option1 PP(SQL) suboption
CHAR(n) not explicitly specified 1140 NOCCSID0 11402
CHAR(n) not explicitly specified 1140 CCSID0 Subsystem default application encoding scheme (DECP value APPENSCH)3
CHAR(n) 500 1140 NOCCSID0 11402
CHAR(n) 500 1140 CCSID0 5004
CHAR(n) UNICODE 1140 NOCCSID0 11402
CHAR(n) UNICODE 1140 CCSID0 1208

This CCSID and options combination does not logically make sense for PL/I.

5
UCHAR(n) 1208 1140 CCSID0 12084
WIDECHAR(n) 1140 1140 CCSID0 12006
Note:
  1. This value can be the value that you explicitly specify with the CODEPAGE compiler option or the default PL/I compiler code page.
  2. Because you specified NOCCSID0, Db2 uses the code page value from the PL/I compiler.
  3. Because you specified CCSID0, Db2 does not use the PL/I 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 CCSID0, Db2 does not use the PL/I code page value. Instead, Db2 uses the value that you specified for the ENCODING bind option.
  5. Because you specified CCSID0 and the ENCODING bind option UNICODE, Db2 uses CCSID 1208, which is UTF-8. Although you can specify this combination of options, do not do so. Specify compiler option CODEPAGE(1208) and the NOCCSID0 and CODEPAGE Db2 coprocessor coprocessor options instead.
  6. Because you specified a WIDECHAR 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 PL/I preprocessor option 'PP(SQL...' with the CCSID suboption to specify the CCSID of the application source. For example, if you are using an older compiler that does not pass a CCSID value to the Db2 coprocessor, the following EXEC statement for a PL/I compile job specifies a source CCSID of 37.
/PLI EXEC PGM=IBMZPLI,PARM='...,PP(SQL("CCSID(37)"),...),...'           
2 Use caution if you specify different CCSIDs for different pieces of data, which can result in character conversion.
3 For DRDA applications, the ENCODING bind option does not set the CCSID of the data, and CCSIDs are communicated as part of the protocol.