GET DATASET dset [POSITION pos] [ATTRIBUTES attr].
1. ... POSITION pos
2. ... ATTRIBUTES attr
With the POSITION addition, this statement determines the current position of the file pointer in the file specified in dset and gets additional file attributes using the ATTRIBUTES addition.
dset must be a character-type data object that contains the
platform-specific name of the file. The file must be open, otherwise an exception that can be handled is raised.
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.
... POSITION pos
This addition assigns the current position of the file pointer to the data object pos, which must be a numeric variable. The position is specified in bytes; that start of the file corresponds to position 0.
The POSITION addition cannot be specified for files that
were opened using the FILTER
addition to the OPEN DATASET statement, otherwise an exception that can be handled is raised.
In the case of files larger than 2 GB, a data object pos
of the data type i is not sufficient for including all possible positions of the file pointer.
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.
... ATTRIBUTES attr
This addition places the attributes with which the file was opened (using the OPEN DATASET statement) into the data object attr. The data type of attr must be dset_attributes, which is defined in the type group DSET as follows:
dset_attributes is a structured type with two substructures: fixed and changeable. The components of the substructure AB> fixed> take in attributes of the file that cannot be changed using the SET DATASET statement (see Table 1). The components of the substructure changeable include attributes of the file that can be changed using the SET DATASET statement (see Table 2).
Table 1
Component | Description |
indicator | Structure, whose components mode, access_type, encoding, and filter contain the value "X" in attr if the identically-named components of the structure fixed are significant for the current file. |
mode | Storage type. Possible values in attr are "T", "LT", "B", and "LB" for text files, legacy text files, binary files, and legacy binary files. The corresponding addition to the OPEN DATASET statement is IN mode. |
access_type | Access type. Possible values in attr are "I", "O", "A", and "U" for files that were opened for reading, writing, appending, and editing. The corresponding addition to the OPEN DATASET statement is FOR access. |
encoding | Character representation. Possible values in attr are "NON-UNICODE" and "UTF-8". The corresponding addition to the OPEN DATASET statement is ENCODING { DEFAULT | UTF-8 | NON-UNICODE }. |
filter | In attr, contains the filter command if the file was opened with the FILTER addition to the OPEN DATASET statement. |
linefeed | Contains the end-of-line marking used during access in the case of a text file or legacy text file. |
Table 2
Component | Description |
indicator | Structure, whose components repl_char, conv_errors, code_page, and endian contain 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 attr that was specified using the REPLACEMENT CHARACTER addition to the OPEN DATASET statement. |
conv_errors | After opening the file, this component contains the value "I" in attr if 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 the code page in attr that was specified using the CODE PAGE addition to the OPEN DATASET statement. If this statement is not used, the content of attr initial. |
endian | After opening the file, this component contains the value "B" in attr if the BIG ENDIAN addition to 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 | Contains in attr - after the file has been opened - one of the values "N", " S", "U", or "W" if the respective addition WITH NATIVE|SMART|UNIX|WINDOWS LINEFEED of the statement OPEN DATASET was used. If none of the additions is used, the content in attr is initial. |
For some of the components, constands are defined in the type group DSET as comparison values.
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.
In this example, the system first checks whether the file test.dat was opened using the FILTER addition. Only if this is not the case, is the current file position determined using GET DATASET.
TYPE-POOLS dset.
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.