Understanding Character Fields and Byte Size
The COBOL Unicode conversion utility for z/OS changes the usage of alphanumeric character fields (PIC X) to usage NATIONAL (PIC N). This change works for the majority of the data fields, but may have side effects.
As in UCS-2 encoding, any character takes up two bytes. The size of one PIC N element is two bytes. The conversion from PIC X to PIC N implicitly doubles the field size. This can be a problem when a field must be a specific byte size. For example, in the following example, the PIC X field is used as filler to extract a portion of byte stream from numeric data field. This type of PIC X field should not be converted to PIC N.
01 W-WORK.
03 NUM-OUT-AREA PIC X(16).
03 NUM-OUT-0 REDEFINES NUM-OUT-AREA
PIC S9(31) COMP-3.
03 NUM-OUT-1 REDEFINES NUM-OUT-AREA
PIC S9(30)V9(1) COMP-3.
03 NUM-OUT-2 REDEFINES NUM-OUT-AREA
PIC S9(29)V9(2) COMP-3.
03 NUM-OUT-3 REDEFINES NUM-OUT-AREA
PIC S9(28)V9(3) COMP-3.
03 FILLER REDEFINES NUM-OUT-AREA.
05 FILLER PIC X(12).
05 NUM-OUT-INT PIC S9(8) COMP.
03 FILLER REDEFINES NUM-OUT-AREA.
05 FILLER PIC X(14).
05 NUM-OUT-SMALLINT PIC S9(4) COMP.
The utility converts all alphanumeric character fields to PIC N, except for a very limited case where it can detect it should not convert this field data type. For the cases like that shown in the previous example, you must manually modify the code and test it.
Additional Considerations
Consider the following:
-
Be very careful when deciding not to convert a PIC X field. COBOL does not allow moving data between PIC X and PIC N field without character set conversion between EBCDIC and Unicode, which adds extra complexity in your program and can cause performance overhead.
-
You cannot use national and non-national data in some statements, such as STRING and UNSTRING.
-
PIC N is two-byte field but content is not limited to Unicode strings. You can store binary, packed decimal or pointer values in the PIC N field (using redefinition) and can copy the value to another PIC N field. Therefore, it is not always necessary to use PIC X field to store non-Unicode values. Use the PeopleSoft-delivered COBOL Unicode conversion utility for z/OS to convert all fields to PIC N unless the field cannot be converted to PIC N (instead of trying to convert only the field that can contain international characters).