Character Format

The fixed-length character format is one or more bytes long with a set length.

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

You define a character field by specifying the CHAR or VARCHAR keyword in a free-form definition or by specifying A 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 character field.

The default initialization value is blanks. A blank is x'40' for EBCDIC data and x'20' for ASCII or UTF-8 data.

You can specify the default CCSID for character fields using the CCSID(*CHAR) keyword on a Control statement or a /SET directive. You can also specify the CCSID explicitly using the Definition statement CCSID keyword.

CCSID of data in character format

Character data is considered to have the CCSID explicitly or implicitly specified if at least one of the following is true.
  • CCSID(*EXACT) is specified on a Control statement.
  • CCSID(*CHAR) is specified on a Control statement with a CCSID other than *JOBRUN.
  • CCSID(*CHAR) is specified on a /SET statement that is in effect.
  • CCSID(*EXACT) or CCSID(*NOEXACT) is specified for the data structure containing the character subfield.
  • The CCSID keyword is specified on the definition for the character item.
If character data is not considered to have the CCSID explicitly or implicitly specified
  • if CCSID(*CHAR:*JOBRUN) is in effect, the data has the job CCSID.
  • otherwise, the CCSID is assumed to be the mixed graphic CCSID related to the job CCSID.
    Warning: When CCSID(*CHAR:*JOBRUN) is specified, and control statement keyword CCSID(*EXACT) is not specified, alphanumeric fields that do not have the CCSID explicitly specified are not considered to have a known CCSID when the RPG compiler determines whether to perform CCSID conversion between the data in the input or output buffer and the program field. See CCSID conversions during input and output operations for more details.
If the CCSID of character data is 65535 (*HEX), no CCSID conversion is performed when the data is used with character data in another CCSID, and CCSID conversion is not allowed when the data is used with graphic data or UCS-2 data. The CCSID of a character item is 65535 in the following cases:
  • The item is a hexadecimal literal.
  • CCSID(*HEX) or CCSID(65535) is implicitly or explicitly specified by the CCSID keyword on the definition for the item.
  • The default character CCSID is 65535 See CCSID control keyword for information on how to set the default character CCSID.
  • The item is the result of the %CHAR built-in function with *HEX specified for the CCSID operand.
  • The item is a subfield in an externally-described data structure or a data structure defined with the LIKEREC keyword, CCSID(*EXACT) is specified for the data structure definition, and the external field has type Hexadecimal.