Unicode Encodings in PeopleSoft COBOL
The character set that is used for PeopleSoft COBOL processing must match the character set for your database. If you created a Unicode database for the PeopleSoft system, you must also run COBOL in Unicode.
Note:
In this document, the word character refers to a single character in any language, regardless of how many bytes are required to store the character.
The Unicode standard provides several methods of encoding Unicode characters into a byte stream. Each encoding has specific properties that make it suitable for use in different environments. The two main encodings that are important to understanding how PeopleSoft COBOL operates when running in Unicode are:
-
UCS-2 (2-byte Universal Character Set) — which is the Unicode encoding that PeopleTools uses internally for data that is held in memory on the application server.
UCS-2 encodes all characters into a fixed storage space of two bytes.
-
UTF-8 (8-bit Unicode Transformation Format) — which is the encoding that the PeopleSoft system uses in COBOL.
UTF-8 uses a format that varies from one to four bytes per character. Currently, the PeopleSoft system supports Unicode’s Basic Multilingual Plane (BMP), which requires one to three bytes per character. Four-byte UTF-8 characters are required to represent supplementary characters that are outside Unicode’s BMP.
In UTF-8, the actual number of bytes to encode a character can be determined by the first three bits of the first, and sometimes only, byte of a character. The following table shows how the bit pattern of the first byte is related to the number of bytes needed to encode the UTF-8 character.
| Unicode Code Point Range | UTF-8 Bit Pattern | UTF-8 Character Length |
|---|---|---|
|
U+0000 – U+007F |
0xxxxxxx |
One byte |
|
U+0080 – U+07FF |
110xxxxx 10xxxxxx |
Two bytes |
|
U+0800 – U+FFFF |
1110xxxx 10xxxxxx 10xxxxxx |
Three bytes |
The x bit positions are filled with the bits of the character code number in binary representation. The rightmost x is the least-significant bit (a big-endian representation). In multi-byte sequences (for Unicode code points greater than U+007F), the number of leading 1 bits in the first byte is identical to the number of bytes in the entire sequence. In addition, each byte in a multi-byte sequence has the most significant bit set.
This section includes Unicode encoding examples for the following characters:
| Character | Unicode Code Point | Description |
|---|---|---|
|
a |
U+0061 |
Latin small letter a. |
|
ñ |
U+00F1 |
Latin small letter ñ. |
|
€ |
U+20AC |
Euro symbol |
The following table shows the difference in how UCS-2 and UTF-8 encode several characters:
| Character | Unicode Code Point | UCS-2 Byte Values | UTF-8 Byte Values |
|---|---|---|---|
|
a |
U+0061 |
0x00 0x61 |
0x61 |
|
ñ |
U+00F1 |
0x00 0xF1 |
0xC3 0xB1 |
|
€ |
U+20AC |
0x20 0xAC |
0xE2 0x82 0xAC |
The PeopleSoft system transparently handles the conversion between UCS-2 and UTF-8 when data is passed into the COBOL program from the database. If you are reading or writing files directly from a COBOL program, the input and output files are UTF-8 encoded when running PeopleSoft COBOL programs in Unicode.
Related Topics