Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP File Interface →  Statements for the ABAP File Interface 

GET DATASET

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


GET DATASET dset [POSITION pos] [ATTRIBUTES attr]. 

Extras

1. ... POSITION pos
2. ... ATTRIBUTES attr

Effect

The POSITION addition is used by this statement to determine the current position of the file pointer in the file specified in dset and the ATTRIBUTES addition is used to get additional file attributes.

dset expects a character-like data object containing the physical name of the file. The file must already be open, otherwise a handleable exception is raised.


Note

If no additions are specified, the statement can be used to determine whether or not the file is open with the aid of a TRY control structure.

Addition 1

... POSITION pos

Effect

This addition assigns the current position of the file pointer to the data object pos. pos expects a numerical variable. The position is specified in bytes; the start of the file corresponds to position 0.

The addition POSITION cannot be specified for files that have been opened with the addition FILTER of the statement OPEN DATASET. This raises a handleable exception.


Note

For file sizes greater than 2 GB, a data object pos of data type i is not sufficient for recording all the possible positions of the file pointer.


Example

After the first literal is saved, the position of the file pointer is assigned to the variable pos, which is then used to position the file pointer before the read access.

DATA: file TYPE string VALUE 'test.dat', 
      pos  TYPE i, 
      text TYPE string. 

OPEN DATASET file FOR OUTPUT IN TEXT MODE 
                             ENCODING DEFAULT 
                             WITH SMART LINEFEED. 
TRANSFER '1234567890' TO file. 
GET DATASET file POSITION pos. 
TRANSFER 'ABCDEFGHIJ' TO file. 
CLOSE DATASET file. 

OPEN DATASET file FOR INPUT IN TEXT MODE 
                           ENCODING DEFAULT 
                            WITH SMART LINEFEED 
                            AT POSITION pos. 
READ DATASET file INTO text. 
CLOSE DATASET file. 

Addition 2

... ATTRIBUTES attr

Effect

This addition passes the attributes used to open the file (using the OPEN DATASET statement) to the data object attr. The data type of attr must be dset_attributes, which is defined in the type group DSET as follows:

Table

1Table 2

Table 1

Component Meaning
indicator Structure whose components mode, access_type,encoding, filter, and linefeedin attr contain the value "X" if the identically named components of the structure fixed are significant for the current file.
mode Storage mode. Possible values in attr are "T", "LT", "B", and "LB" fortext files,legacy text files,binary files, andlegacy binary files. Theassociated addition of the OPEN DATASET statement is IN mode.
access_type Access mode. Possible values in attr are "I", "O", "A", and "U" for filesthat were opened for reading, writing, appending, and editing. The associated addition of the OPEN DATASET statement is FOR access.
encoding Character format. Possible values in attr are "NON-UNICODE" and "UTF-8".The associated addition of the OPEN DATASET statement is ENCODING { DEFAULT
filter In attr, contains the filter command if the file was opened with theFILTER addition of the OPEN DATASET statement.
linefeed Contains the end-of-line marking used when accessing atext file or legacy text file.

Table 2

Component Meaning
indicator Structure whose components repl_char, conv_errors,code_page, endian, and linefeed_modecontain the value "X" in attr if the identically named components of the structure changeable are significant for the current file.
repl_char After opening the file, this component contains the replacement character in attrthat was specified using the REPLACEMENT CHARACTER addition of the OPEN DATASET statement.
conv_errors After opening the file, this component contains the value "I" in attrif it was opened using the addition IGNORING CONVERSION ERRORS of the statement OPEN DATASET, otherwise it contains the value "R".
code_page After opening the file, this component contains thecode page in attrthat was specified using the CODEPAGE addition to the OPEN DATASET statement. If no addition is used, the content of attr is initial.
endian After opening the file, this component contains the value "B" in attrif the BIG ENDIAN additionto the OPEN DATASET statement was used or "L" if the LITTLE ENDIAN addition was used. If no addition is used, the content of attr is initial.
linefeed_mode After opening the file, this component contains one of the values "N", "S", "U", or "W" in attr if the corresponding addition WITH NATIVE

For some of the components, constants are defined in the type group DSET as comparison values.


Note

The determinable attributes do not represent the attributes of the file in the operating system, but the attributes with and by which the file is opened and handled in ABAP.


Example

In this example, the system first checks whether the file test.dat was opened using the FILTER addition. If not (and only if not), the current file position is determined using GET DATASET.

DATA: dset TYPE string VALUE 'test.dat', 
      attr TYPE dset_attributes, 
      pos TYPE i. 

OPEN DATASET dset FOR INPUT IN BINARY MODE 
                  FILTER 'uncompress'. 

... 

GET DATASET dset ATTRIBUTES attr. 
IF attr-fixed-indicator-filter <> 'X'. 
  GET DATASET dset POSITION pos. 
ELSE. 
  ... 
ENDIF. 

CLOSE DATASET dset. 

Exceptions


Catchable Exceptions

  • CX_SY_FILE_OPEN_MODE The file is not open.
  • CX_SY_FILE_POSITION The file could not be read because an invalid status exists or the type of file does not permit position specification.
  • CX_SY_CONVERSION_OVERFLOW The variable pos was assigned a type that is too small to include the current position.