Differences between the Db2 coprocessor and the Db2 precompiler

Start of changeThe Db2 coprocessor and the Db2 precompiler have architectural differences. You cannot switch from one to the other without considering those differences and adjusting your program accordingly. End of change

Tip: The Db2 coprocessor is the recommended method for processing SQL statements in application programs. Compared to the Db2 precompiler, the Db2 coprocessor has fewer restrictions on SQL programs, and more fully supports the latest SQL and programming language enhancements. See Processing SQL statements by using the Db2 coprocessor.
Recommendation: Use the Db2 coprocessor instead of the precompiler when using Unicode variables in COBOL or PL/I applications.
Depending on whether you use the Db2 coprocessor which is recommended in most cases, or the Db2 precompiler, ensure that you account for the following differences:
  • Differences in handling source CCSIDs:

    The Db2 coprocessor and Db2 precompiler both convert the SQL statements of your source program to UTF-8 for parsing.

    The Db2 coprocessor or Db2 precompiler uses the source CCSID(n) value to convert from that CCSID to CCSID 1208 (UTF-8). The CCSID value must be an EBCDIC CCSID. If you want to prepare a source program that is written in a CCSID that cannot be directly converted to or from CCSID 1208, you must create an indirect conversion.

  • Differences in handling host variable CCSIDs:
    • COBOL:
      Db2 coprocessor
      The COBOL compiler with National Character Support always sets CCSIDs for alphanumeric variables, including host variables that are used within SQL, to the source CCSID. Alternatively, you can specify that you want the COBOL Db2 coprocessor to handle CCSIDs the same way as the Db2 precompiler.
      Db2 precompiler:
      The Db2 precompiler sets CCSIDs for alphanumeric host variables only when the program includes an explicit DECLARE :hv VARIABLE statement.
      Recommendation: If you have problems with host variable CCSIDs, change your application to include the DECLARE :hv VARIABLE statement to overwrite the CCSID that is specified by the COBOL compiler, or use the Db2 precompiler.
      For example, assume that Db2 has mapped a FOR BIT DATA column to a host variable in the following way:
      01  hv1  pic x(5).
      01  hv2  pic x(5).
       
      EXEC SQL  CREATE TABLE T1 (colwbit  char(5) for bit data,  
                                 rowid    char(5))   END-EXEC.
      
         EXEC SQL                                             
         INSERT INTO T1 VALUES (:hv1, :hv2)    
         END-EXEC.     
      
      Db2 coprocessor: In the modified source from the Db2 coprocessor with the National Character Support for COBOL, hv1 and hv2 are represented to Db2 in the following way, with CCSIDs: (Assume that the source CCSID is 1140.)
      for hv1 and hv2, the value for CCSID is set to '1140' ('474'x) in input SQLDA 
      of the INSERT statement. 
      
      '7F00000474000000007F'x 
      

      To ensure that no discrepancy exists between the column with FOR BIT DATA and the host variable with CCSID 1140, add the following statement for :hv1 or use the Db2 precompiler:

      EXEC SQL DECLARE : hv1 VARIABLE FOR BIT DATA END-EXEC.   
      
       for hv1 declared with for bit data. The value in  SQL---AVAR-NAME-DATA  is 
        set to  'FFFF'x for CCSID instead of '474x'. 
      
      '7F0000FFFF000000007F'x  <<= with DECLARE :hv1 VARIABLE FOR BIT DATA
      vs. 
      '7F00000474000000007F'x   <<= without 
      
      Db2 precompiler: In the modified source from the Db2 precompiler, hv1 and hv2 are represented to Db2 through SQLDA in the following way, without CCSIDs:
      for hv1: NO CCSID
      
      20 SQL-PVAR-NAMEL1  PIC S9(4) COMP-4 VALUE +0.    
      20 SQL-PVAR-NAMEC1  PIC X(30) VALUE ' '.         
       
      for hv2:  NO CCSID
      
      20 SQL-PVAR-NAMEL2  PIC S9(4) COMP-4 VALUE +0.    
      20 SQL-PVAR-NAMEC2  PIC X(30) VALUE ' '
      
    • PL/I
      Db2 coprocessor:
      You can specify whether CCSIDs are to be associated with host variables by using the following PL/I SQL preprocessor options:
      CCSID0
      Specifies that the PL/I SQL preprocessor is not to set the CCSIDs for all host variables unless they are defined with the SQL DECLARE :hv VARIABLE statement.
      NOCCSID0
      Specifies that the PL/I SQL preprocessor is to set the CCSIDs for all host variables.