UCS-2 Format

The Universal Character Set (UCS-2) format is a character string where each character is represented by 2 bytes. This character set can encode the characters for many written languages.

Fields defined as UCS-2 data do not contain shift-out (SO) or shift-in (SI) characters.

The length of a UCS-2 field, in bytes, is two times the number of UCS-2 characters in the field.

The fixed-length UCS-2 format is a character string with a set length where each character is represented by 2 bytes.

For information on the variable-length UCS-2 format, see Variable-Length Character, Graphic and UCS-2 Formats.

You define a UCS-2 field by specifying the UCS2 or VARUCS2 keyword in a free-form definition or by specifying C in the Data-Type entry of a fixed-form specification. You can also define one using the LIKE keyword on the definition specification where the parameter is a UCS-2 field.

The default initialization value for UCS-2 data is X'0020'. The value of *HIVAL is X'FFFF', *LOVAL is X'0000', and the value of *BLANKS is X'0020'. You can specify the initialization value for UCS-2 fields using character, UCS-2 or Graphic values. If the type of the literal is not UCS-2, the compiler will perform an implicit conversion to UCS-2. For example, to initialize a UCS-2 field with the UCS-2 form of 'abc', you can specify INZ('abc'), INZ(%UCS2('abc')) or INZ(U'006100620063').

For more information on the UCS-2 format, see the IBM® i Information Center globalization topic.

The following are restrictions on the implementation of UCS-2 data when using the Program Verifier:
  • On the Control Specification, when we have:
           H  CSSID(*GRAPH: *SRC)
    the second parameter *SRC will not be substituted as the Program Verifier cannot always retrieve the source CCSID, especially when the source is residing on the workstation or we do not have a connection to the host. The Program verifier will issue a warning message indicating that the *SRC has not been substituted.
    Note: This may result in the Program Verifier giving error messages that may not be issued on the host. For example, look at the following source:
              H CCSID(*GRAPH: *SRC)
              D grafld1         S             10G
              D grafld2         S             10G   ccsid(300)
              C                   if        grafld1 = grafld2
              C                   endif     
    Since the *SRC is not substituted, an error message will be issued on program verification indicating that fields with different CCSIDs are not allowed in the same operation. While on the host, if *SRC is 300 then no error message is issued.
  • The built-in functions %GRAPH and %UCS2 on a definition specification will not be evaluated on program verification:
              D grafld2         S             10G   inz(%ucs2(u'aabbcc'))
    The Program Verifier will issue a warning message indicating that the %UCS2 is not evaluated and any errors resulting from the evaluation will not be reported.
  • Compile time data for UCS-2 will not be validated and a warning message will be issued by the Program Verifier to indicate that the data has not been validated.