This section describes how to use the national character data types using the SQL embedded COBOL preprocessor.
The table below lists the COBOL variable types supporting the national character data types. The number of characters specified for the national character data type must be specified for the length of the host variable.
National character data type | COBOL variable type |
---|---|
CHARACTER(n) NATIONAL CHARACTER(n) | varName PIC N(n) |
CHARACTER VARYING(n) NATIONAL CHARACTER VARYING(n) | varName PIC N(n) VARYING |
To use COBOL variable types that support national character data types, it is necessary to specify the ECOBPG_NCHAR environment variable.
ECOBPG_NCHAR={ UTF16LE | UTF16BE | UTF32LE | UTF32BE | SJIS }
In SQL embedded COBOL, specify the encoding of the COBOL variable types that support national character data types.
UTF16LE: UTF-16 little-endian
UTF16BE: UTF-16 big-endian
UTF32LE: UTF-32 little-endian
UTF32BE: UTF-32 big-endian
SJIS: Shift JIS
If this environment variable is omitted, the encoding will be determined according to the encoding system of the client.
If UTF8 is used: UTF16 (endians will be encoded in accordance with endians of the client system)
If SJIS is used: SJIS
If encoding is specified for the translation option when compiling with NetCOBOL, the encoding specified for the national character data types should be used for the environment variable ECOBPG_NCHAR.
The list below shows NetCOBOL translation options and their corresponding environment variable ECOBPG_NCHAR values.
NetCOBOL translation options | Environment variable ECOBPG_NCHAR |
---|---|
ENCODE (UTF-8,UTF16,LE) RCS (UTF-16,LE) | UTF-16LE |
ENCODE (UTF-8,UTF-16,BE) RCS (UTF-16,BE) | UTF-16BE |
ENCODE (UTF-8,UTF-32,LE) | UTF-32LE |
ENCODE (UTF-8,UTF-32,BE) | UTF-32BE |
ENCODE (SJIS,SJIS) | SJIS |
Not specified | No need to specify |
Also, if the post-compiling encoding for an application differs from the locale of the execution environment, then the client encoding must be used for the application.
The list below shows the values supported for the combinations of application encoding, locale of the execution environment, and client encodings.
Application encoding | Locale used when executing an application | Client encoding |
---|---|---|
UTF-8 | UTF-8 | UTF-8 |
SJIS | UTF-8 | |
SJIS | UTF-8 | SJIS |
SJIS | SJIS |
Refer to "7.2.2 Message Language and Encoding System Used by Applications" for information on how to set client encoding systems.
The following example shows host variable declaration of a national character data type.
01 DATA1 PIC N(10). 01 DATA2 PIC N(10) VARYING.
Note
Halfwidth characters should not be used for the national character data type COBOL variable.
The national character data type column attribute obtained by applications should be the CHAR type.
Encoding cannot be specified using the ENCODING clause, which is a feature of NetCOBOL.