Sign in

docs RPG Reference

Conversions

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.

Built-in functions : Implicit CCSID conversion is done for the following built-in functions:

Table 1. Built-In Functions

| Built-in function | Arguments | Implicit conversion |
| --- | --- | --- |
| [%CHECK](/doc/en/docs/rpg-reference/bbchk/#bbchk) | comparator string:string to be checked{:start position} | The comparator string is converted to the CCSID of the string to be checked. |
| [%CHECKR](/doc/en/docs/rpg-reference/bbchkr/#bbchkr) | comparator string:string to be checked{:start position} | The comparator string is converted to the CCSID of the string to be checked. |
| [%LOOKUPxx](bbloo.htm#bbloo) | search argument: array{:start index {:number of elements}} | The search argument is converted to the CCSID of the array. |
| [%REPLACE](/doc/en/docs/rpg-reference/bbrepl/#bbrepl) | replacement string: source string {:start position {:source length to replace}} | The replacement string is converted to the CCSID of the source string. |
| [%SCAN](/doc/en/docs/rpg-reference/bbscan/#bbscan) | search argument:string to be searched{:start position{:length}} | The search argument is converted to the CCSID of the string to be searched. |
| [%SCANR](/doc/en/docs/rpg-reference/bbscanr/#bbscanr) | search argument:string to be searched{:start position{:length}} | The search argument is converted to the CCSID of the string to be searched. |
| [%SCANRPL](/doc/en/docs/rpg-reference/bbscanrp/#bbscanrp) | scan string: replacement string: source string  {:scan start position {:scan length}} | The scan string and replacement string are converted to the CCSID of the source string. |
| [%SPLIT](/doc/en/docs/rpg-reference/bbsplit/#bbsplit) | string to be split {:string with separators} | The string with separators is converted to the CCSID of the string to be split. |
| [%TLOOKUPxx](/doc/en/docs/rpg-reference/bbtloo/#bbtloo) | search argument: table to be searched {: alternate table} | The search argument is converted to the CCSID of the table to be searched. |
| [%TRIM](/doc/en/docs/rpg-reference/bbtrim/#bbtrim) | string to be trimmed {: string with characters to trim} | The string with characters to trim is converted to the CCSID of the string to be trimmed. |
| [%TRIML](/doc/en/docs/rpg-reference/bbtriml/#bbtriml) | string {: characters to trim} | The string with characters to trim is converted to the CCSID of the string to be trimmed. |
| [%TRIMR](/doc/en/docs/rpg-reference/bbtrimr/#bbtrimr) | string {: characters to trim} | The string with characters to trim is converted to the CCSID of the string to be trimmed. |
| [%XLATE](/doc/en/docs/rpg-reference/bbxlat/#bbxlat) | string with from-characters: string with to-characters: source string {: start position} | The string with from-characters and the string with to-characters are converted to the CCSID of the source string. |

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.