Conversions

When you use character, graphic, and UCS-2 values with different types or CCSIDs in the same operation, conversions must be done to ensure that all the values have the same type and CCSID. The conversions can be done explicitly, using the conversion built-in functions %CHAR, %UCS2 or %GRAPH or the MOVE or MOVEL operation. However, in the following scenarios, the compiler will do the conversions implicitly when necessary:
Comparison
The comparison is done using a Unicode CCSID. If one or both of the operands is not already in that CCSID, the operand is converted to a temporary with that CCSID.
Assignment
The source value is converted to the type and CCSID of the target value.
Parameters passed by value and by read-only reference
The passed parameter is converted to the type and CCSID of the prototyped parameter.
Concatenation
If one of the operands is a hexadecimal literal the other operand must also be of type character; in this case the hexadecimal literal will be considered to have the same CCSID as the other operand. Otherwise, the operands are converted to a Unicode CCSID.
When operands are converted to a Unicode CCSID, the following rules are used to determine the exact Unicode CCSID to use
  • If the type of either operand is character, the operands are converted to UTF-8.
  • Otherwise, if the type of neither operand is UCS-2, the operands are converted to the UCS-2 CCSID of the module. The UCS-2 CCSID for the module defaults to 13488; you can set it to a different CCSID using keyword CCSID(*UCS2) on a control statement.
  • Otherwise, if the type of only one operand is UCS-2, the other operand is converted to the CCSID of the UCS-2 operand.
  • Otherwise, if one of the UCS-2 operands has the default UCS-2 CCSID of the module, that CCSID is used.
  • Otherwise, the operand with the shorter defined length is converted to the CCSID of the longer operand.
Warning:
  • Some CCSID conversions may not be able to convert all characters, if a character in one operand does not exist in the character set of the other operand. For example, if you assign data from a Unicode operand to an operand whose CCSID represents a single character set, such as an EBCDIC CCSID, some of the characters in the Unicode operand might be from a different character set. In this case, a substitution character will be placed in the target operand. By default this situation results in the non-error status code 50. However, if you specify control keyword CCSIDCVT(*EXCP), this situation will result in the error status 00452.
  • You can get a listing of all the CCSID conversions that might be performed in the module using control keyword CCSIDCVT(*LIST) This listing includes warnings about CCSID conversions that might result in substitution characters.
See CCSIDCVT(*EXCP | *LIST) for more information about substitution characters and the CCSIDCVT keyword.