Controlling the CCSID for COBOL host variables
Setting the CCSID for COBOL host variables is slightly different than the process for other host languages. In COBOL, several other settings affect the CCSID.
Before you begin
Procedure
To control the CCSID for COBOL host variables:
- The NATIONAL data type
- Use this data type to declare Unicode values in the UTF-16 format
(CCSID 1200). If you declare a host variable HV1 as USAGE NATIONAL, DB2 always handles HV1 as if you had used the following DECLARE VARIABLE statement:
DECLARE :HV1 VARIABLE CCSID 1200
- The COBOL CODEPAGE compiler option
- Use this option to specify the default EBCDIC CCSID of character data items.
- The SQLCCSID compiler option
- Use this option to control whether the CODEPAGE compiler option
influences the processing of SQL host variables in your COBOL programs
(available in Enterprise COBOL V3R4 or later).
When you specify the SQLCCSID compiler option, the COBOL DB2 coprocessor uses the CCSID that is specified in the CODEPAGE compiler option. All host variables of character data type, other than NATIONAL, are specified with that CCSID unless they are explicitly overridden by a DECLARE VARIABLE statement.
When you specify the NOSQLCCSID compiler option, the CCSID that is specified in the CODEPAGE compiler option is used for processing only COBOL statements within the COBOL program. That CCSID is not used for the processing of host variables in SQL statements. DB2 uses the CCSIDs that are specified through DB2 mechanisms and defaults as host variable data value encodings.
- The DECLARE VARIABLE statement.
- This statement explicitly sets the CCSID for individual host variables.
Example
DATA DIVISION.
01 HV1 PIC N(10) USAGE NATIONAL.
01 HV2 PIC X(20) USAGE DISPLAY.
01 HV3 PIC X(30) USAGE DISPLAY.
...
EXEC SQL
DECLARE :HV3 VARIABLE CCSID 1047
END-EXEC.
...
PROCEDURE DIVISION.
...
EXEC SQL
SELECT C1, C2, C3 INTO :HV1, :HV2, :HV3 FROM T1
END-EXEC.
Each of the host variables have the following
CCSIDs:- HV1
- 1200
- HV2
- 1141
- HV3
- 1047
- HV1
- 1200
- HV2
- 37
- HV3
- 1047