SAP NetWeaver AS ABAP Release 752, ©Copyright 2017 SAP AG. All rights reserved.
ABAP - Keyword Documentation → ABAP - Reference → Processing External Data → ABAP File Interface → Statements for the ABAP File Interface → OPEN DATASET →
OPEN DATASET - position
Syntax
... AT POSITION pos ...
Effect
This addition sets the file pointer at the position specified in pos. pos expects a numeric data object. Numbers with a value greater than the value range of the data type i can also be entered.
The position is specified in bytes; the start of the file corresponds to position 0. If pos contains the value -1, the position is at the end of the file. For all other negative values, the behavior is undefined.
Note the following special cases:
The addition POSITION cannot be specified if one of the additions
FILTER or BYTE-ORDER MARK is specified at the same time.
Notes
Example
A file test.dat is created as a text file, then filled with data, changed, and read. Since each TRANSFER statement appends 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" is overwritten by the end-of-line selection of the first line.
DATA(file) = `test.dat`.
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.
DATA: result TYPE string,
output TYPE TABLE OF string WITH EMPTY KEY.
WHILE sy-subrc = 0.
READ DATASET file INTO result.
APPEND result TO output.
ENDWHILE.
CLOSE DATASET file.
cl_demo_output=>display_data( output ).
DELETE DATASET file.