Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP File Interface →  Statements for the ABAP File Interface →  OPEN DATASET →  OPEN DATASET - mode 

OPEN DATASET - CODE PAGE

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


...  CODE PAGE cp ... 

Effect

This addition specifies that, when a legacy file is opened, the representation of character-like data objects in the file is based on the code page specified in cp. When a character-like data object is written or read, a conversion between this code page and the current character representation is performed, if necessary. If this addition is not specified, the characters in the file are handled in accordance with the non-Unicode code page that would be assigned when reading or writing data in a non-Unicode system (as specified by the entry in the database table TCP0C in the current text environment).

If specified, the code page cp expects a character-like data object that must contain, when the statement is executed, the name of a non-Unicode page from the column CPCODEPAGE in the database table TCP00. Unicode code pages cannot be specified.


Notes

  • This addition enables the automatic conversion of file content to the current Unicode character representation UCS-2 when reading and writing files. In this way, files saved in any non-Unicode systems can be imported.
  • The statement SET DATASET can be used to specify a different code page for an opened legacy file.
  • The addition CODE PAGE replaces the use of the obsolete statement TRANSLATE CODE PAGE in when accessing files.

Example

Opens legacy text files with the IDs 1101 for 7-Bit USA ASCII and 1102 for 7-Bit German ASCII from the table TCP00. When a German umlaut character is written to the open file with the ID 1101, an exception of the class CX_SY_CONVERSION_CODEPAGE is raised. When the character is written to the open file with the ID 1102, this exception is not raised. See also the example for the addition REPLACEMENT CHARACTER.

DATA(dset) = 'test.dat'. 

OPEN DATASET dset FOR OUTPUT IN LEGACY TEXT MODE CODE PAGE '1101'. 
TRY. 
    TRANSFER 'ÄaÖöÜü' TO dset. 
  CATCH cx_sy_conversion_codepage INTO DATA(exc). 
    cl_demo_output=>write( 'Error writing to 7-Bit USA ASCII' ). 
ENDTRY. 
CLOSE DATASET dset. 

OPEN DATASET dset FOR OUTPUT IN LEGACY TEXT MODE CODE PAGE '1102'. 
TRY. 
    TRANSFER 'ÄaÖöÜü' TO dset. 
  CATCH cx_sy_conversion_codepage INTO exc. 
    cl_demo_output=>write( 'Error writing to 7-Bit German ASCII' ). 
ENDTRY. 
CLOSE DATASET dset. 

cl_demo_output=>display( ). 

DELETE DATASET dset.