What does it do? The additions after the mandatory addition ENCODING> define the character representation in which the content of a text file is handled.
ABAP_PGL Write text files in UTF-8 and with a byte order mark.> ABAP_PGL_END
Latest notes: It is best to always write files in UTF-8 if all readers can process this format. Otherwise, the code page can depend on the text environment> and it is difficult to identify the code page from the file content. ABAP_HINT_END • DEFAULT OPEN DATASET
ABAP Alternative 1 ... DEFAULT>
What does it do? If specified, DEFAULT> is the same as specifying UTF-8>. • UTF-8 OPEN DATASET
ABAP Alternative 2 ... UTF-8 $[SKIPPING$|WITH BYTE-ORDER MARK$] >
ABAP Addition ... SKIPPING$|WITH BYTE-ORDER MARK>
What does it do? The characters in the file are handled in accordance with the Unicode character representation UTF-8>.
Latest notes:
The class CL_ABAP_FILE_UTILITIES>> contains the method CHECK_UTF8> for determining whether a file is a UTF-8 file.
A UTF-16 file can only be opened as a binary file. ABAP_HINT_END
Example ABAP Coding
Opens a text file as a UTF-8 file and writes a string containing German umlaut characters to the file. The file is read to a byte string and this byte string is converted from UTF-8 to a character string. This is done using an object created by the class CL_ABAP_CONV_CODEPAGE>> and the method CONVERT> of the interface IF_ABAP_CONV_IN>>.
ABEXA 00465 ABAP_EXAMPLE_END • WITH BYTE-ORDER MARK OPEN DATASET • SKIPPING BYTE-ORDER MARK OPEN DATASET
ABAP Addition
What does it do? This addition defines how the byte order mark (BOM), with which a file encoded in the UTF-8 format can begin, is handled. The BOM is a sequence of three bytes that indicates that a file is encoded in UTF-8>.
SKIPPING BYTE-ORDER MARK> is only allowed if the file is opened for reads or writes using FOR INPUT>> or FOR UPDATE>>. If there is a BOM at the start of the file, this is ignored, and the file pointer is set after it. Without the addition, the BOM is handled as regular file content.
WITH BYTE-ORDER MARK> is only allowed if the file is opened for writing using FOR OUTPUT>>. When the file is opened, a BOM is inserted at the start of the file. Without the addition, no BOM is inserted. The addition BYTE-ORDER MARK> cannot be used together with the AT POSITION>> addition.
Latest notes:
When opening UTF-8 files for reading, it is best to always specify the addition SKIPPING BYTE-ORDER MARK> to prevent a BOM from being handled as file content.
It is recommended that a file for reading is always opened as a UTF-8 file using the addition WITH BYTE-ORDER MARK> (if all readers can process this format).
The method CREATE_UTF8_FILE_WITH_BOM> in the system class CL_ABAP_FILE_UTILITIES>> can be used to create a file with BOM. ABAP_HINT_END
Example ABAP Coding
The binary content of the text file opened using WITH BYTE-ORDER MARK> is EFBBBF616263>. EFBBBF> is specified as a BOM at the start of the file. This is followed by the UTF-8 representation 616263> of the actual characters abc>. ABEXA 00466 ABAP_EXAMPLE_END • NON-UNICODE OPEN DATASET
ABAP Alternative 3 ... NON-UNICODE>
What does it do? The characters of 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>.
Example ABAP Coding
Writing of German umlaut characters to a non-Unicode code page. This code page is then extracted from the database table TCP0C> and used to open the file as a a legacy text file. ABEXA 00467 ABAP_EXAMPLE_END