Sign in

docs RPG Reference

How character data is processed for file I/O

How character data is processed for file I/O

For general information about the CHARCOUNT mode, see Processing string data by the natural size of each character.

The CHARCOUNT mode for a file is set by the CHARCOUNT keyword for the file. If the CHARCOUNT keyword is not specified for the file, the CHARCOUNT mode defaults to the current CHARCOUNT mode for the module, which is determined by the CHARCOUNT Control keyword or the most recent /CHARCOUNT directive that precedes the definition of the file.

With CHARCOUNT NATURAL mode, the RPG compiler ensures that data is truncated correctly when data is moved from RPG variables to the buffers used by data management. With CHARCOUNT STDCHARSIZE mode, the value placed in the I/O buffer can end with a partial character.

Note: The CHARCOUNT mode is only in effect for the data with the type and CCSID specified in the CHARCOUNTTYPES keyword.

The CHARCOUNT mode for a file affects the following scenarios:

  • Moving data from a list of keywords to the key buffer for keyed operations.
  • Moving data from a %KDS data structure to the key buffer for keyed operations.
  • Moving data to the Output buffer from RPG variables when a result data structure is not specified.
  • Moving data to the Output buffer from a result data structure for output or update operations when the result data structure does not match the I/O buffer. See CCSID conversions during input and output operations.