OPEN DATASET - Mode

Syntax

... {BINARY MODE}
  | {TEXT MODE encoding [linefeed] }
  | {LEGACY BINARY MODE [{BIG|LITTLE} ENDIAN] [CODE PAGE cp]}
  | {LEGACY TEXT MODE [{BIG|LITTLE} ENDIAN] [CODE PAGE cp] [linefeed]} ... .

Alternatives:

1. ... BINARY MODE

2. ... TEXT MODE encoding [linefeed]

3. ... LEGACY BINARY MODE [{BIG|LITTLE} ENDIAN ] [CODE PAGE cp]

4. ... LEGACY TEXT MODE [{BIG|LITTLE} ENDIAN] [CODE PAGE cp]
[linefeed]

Extras:

1. ... {BIG|LITTLE} ENDIAN

2. ... CODE PAGE cp

Effect:

These additions define whether the file is treated as a binary file or as a text file. By specifying LEGACY, files can be written in the format that is expected by a non- Unicode system, and files that have been created by a non-Unicode-system can be read. The byte order or the code page must be specified explicitly. In Unicode programs, specification of the storage type is obligatory.

Alternative 1

... BINARY MODE


Effect:

The addition IN BINARY MODE opens the file as a binary file. When writing to a binary file, the binary content of a data object is transferred in unchanged form into the file. When reading from a binary file, the binary content of the file is transferred in unchanged form into a data object.

The addition BINARY MODE has the same meaning in Unicode programs and non-Unicode programs.

Alternative 2

... TEXT MODE encoding [linefeed]


Effect:

The addition IN TEXT MODE opens the file as a text file. The addition ENCODING defines how the characters are represented in the text file. When writing to a text file, the content of a data object is converted to the representation entered after ENCODING, and transferred to the file. If the data type is character-type and flat, trailing blanks are cut off. In the data type string, trailing blanks are not cut off. The end-of-line selection of the relevant platform is applied to the transferred data by default. When reading from a text file, the content of the file is read until the next end-of-line selection, converted from the format specified after ENCODING into the current character format, and transferred to a data object. The end-of-line selection used is controlled using the addition linefeed (as of Release 7.0).

In Unicode programs, only the content of character-type data objects can be transferred to text files and read from text files. The addition encoding must be specified in Unicode programs, and can only be omitted in non-Unicode programs.

Alternative 3

... LEGACY BINARY MODE [{BIG|LITTLE} ENDIAN] [CODE PAGE cp]


Effect:

Opening a legacy file. The addition IN LEGACY BINARY MODE opens the file as a binary file, exactly as in the addition IN BINARY MODE, except in this case the byte order and the codepage with which the file should be handled can also be specified.

Note:

When a flat, character-type field is written into the legacy binary files, the number of bytes written to the file is the same as the number of characters in the source field. In Unicode systems, the field content can be cut off by this when texts are written in Eastern Asian languages. Therefore, we recommend writing only texts into the text fiels that were opened without the addition LEGACY.

Addition 1

... {BIG|LITTLE} ENDIAN

Effect:

This addition specifies that numeric data objects of the type i, f or s are stored in the file in the byte sequence Big Endian and Little Endian. When a data object of these types is written or read, conversion between these and the byte sequence of the current platform will be performed, if necessary. If the addition is not specified, the byte sequence of the current application server will be used.

Notes

  1. With the statement SET DATASET, a different byte sequence can be specified for an opened legacy file.

  2. The addition {BIG|LITTLE} ENDIAN replaces the use of the obsolete statement TRANSLATE NUMBER FORMAT in the case of file accesses.


Addition 2

... CODE PAGE cp

Effect:

This file specifies that the representation of character-type data objects in the file is based on the code page specified in cp. When a character-type data object is written or read, conversion between this code page and the current character representation is performed, if required. If the addition is not specified, the data is read or written in a non-Unicode system without conversion. In a Unicode system, the characters of the file are treated in accordance with the non-Unicode code page that would be assigned at the time of read/write in a non-Unicode system - in accordance with the entry specified in the database table TCP0C of the current text environment.

For the specification of the code page cp, a character-type data object is expected that must contain - at the time of execution of the statement - the label of a non-Unicode page from the column CPCODEPAGE in the database table TCP00. A Unicode page must not be specified.

Notes

  1. The addition allows in Unicode systems - for reading and writing of files - automatic conversion of file content into the current character representation. Files that were stored in arbitrary non-Unicode systems can thus be imported into Unicode systems.

  2. With the statement SET DATASET, a different code page can be specified for an opened legacy file.

  3. The addition CODE PAGE replaces the use of the obsolete statement TRANSLATE CODE PAGE in file accesses.


Alternative 4:

... LEGACY TEXT MODE [{BIG|LITTLE} ENDIAN] [CODE PAGE cp] [linefeed]


Effect:

Opening a legacy file. The addition IN LEGACY TEXT MODE opens the file as a legacy text file. In this case, as with legacy binary files, both byte sequence and the code page with which the content of the file is to be handled can be specified. Syntax and meaning of { BIG|LITTLE} ENDIAN, CODE PAGE cp, and linefeed are the same as for legacy binary files.

In contrast to legacy binary files, the trailing blanks are cut off when writing character-type flat data objects into a legacy text file. Also, as in the case of a text file, an end-of-line selection is added on to the transferred data in the standard version. In contrast to text files opened with the addition IN TEXT MODE, there is no check in Unicode programs as to whether the data objects used in writing or reading are character-type. Furthermore, counting is performed for legacy text files in bytes and for text files in the units of a character represented in storage - using the LENGTH additions of the statements READ DATASET and TRANSFER.

Notes:

Example:

A file test.dat is created as a text file, then filled with data, changed, and read. Since each TRANSFER statement adds on an end-of-line selection to the written content, the content of the file is double-lined after the change. The first line contains " 12ABCD". The second line contains "890". The character "7" was overwritten by the end-of-line selection of the first line.

DATA: file   TYPE string VALUE `test.dat`,
      result TYPE string.

OPEN DATASET file FOR OUTPUT IN TEXT MODE
                             ENCODING DEFAULT
                             WITH SMART LINEFEED.
TRANSFER `1234567890` TO file.
CLOSE DATASET file.

OPEN DATASET file FOR UPDATE IN TEXT MODE
                             ENCODING DEFAULT
                             WITH SMART LINEFEED
                             AT POSITION 2.
TRANSFER `ABCD` TO file.
CLOSE DATASET file.

OPEN DATASET file FOR INPUT IN TEXT MODE
                            ENCODING DEFAULT
                            WITH SMART LINEFEED.
WHILE sy-subrc = 0.
  READ DATASET file INTO result.
  WRITE / result.
ENDWHILE.
CLOSE DATASET file.

INCLUDE ABAPOPEN_DATASET_ENCODING OBJECT DOKU ID SD
INCLUDE ABAPOPEN_DATASET_LINEFEED OBJECT DOKU ID SD ________________________________________________________________________