SAP® Documentation

Single view

ABAPSET_DATASET - SET DATASET

SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   BAL_S_LOG - Application Log: Log header data  
This documentation is copyright by SAP AG.
SAP E-Book

SET DATASET

Short Reference



Syntax

SET DATASET dset $[POSITION ${pos$|${END OF FILE$}$}$]
                 $[ATTRIBUTES attr$].

Additions

1. ... POSITION ${pos$|${END OF FILE$}$}

2. ... ATTRIBUTES attr

Effect

This statement uses the addition POSITION to determine the position of the file pointer in the file specified in dset. It uses the addition ATTRIBUTES to set additional attributes for the file. At least one of these two additions must be specified.

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.

Return Value

The statement SET DATASET always sets sy-subrc to the value 0 or raises an exception.

Addition 1

... POSITION ${pos$|${END OF FILE$}$}

Effect

This addition sets the file pointer in the file, either in the position specified in pos, or at the end of the file. pos expects a numeric data object.

The position is specified in bytes; the start of the file corresponds to position 0. If the value of pos is -1, the file pointer is set at the end of the file. Other negative values are not permitted.

The following cases need to be distinguished:

  1. If the file is open for reads and the value of pos is greater than the length of the file, the file pointer is positioned outside the file. Unless the position is changed, no data can be read.

  2. If the file is opened for writes and the value of pos is greater than the length of the file, it is filled with hexadecimal 0s from the end of the file to the specified position the next time a write is performed on it.

  3. If the file is opened for appends, the position specified is ignored and the file pointer remains positioned at the end of the file.

  4. If the file is opened for changes, and the value of pos is greater than the length of the file, it is filled with hexadecimal 0s from the end of the file to the specified position the next time a write is performed on it.

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.

Notes

  • For file sizes greater than 2 GB, a data object pos of data type i is not sufficient for entering all the possible positions of the file pointer.
  • Free specified positions are more suitable for binary files than for text files. In text files, positions depend on the character format, line-end markers, and in UTF-8 files, also on a Byte Order Mark (BOM). In text files, only place the file pointer in positions known precisely, for example positions obtained using GET DATASET.


Example

When a write is performed, the file is read from the start of the file until the first end-of-line marker, and then the new content is written starting from the end of the file. If the file pointer is not set explicitly after a read, the last TRANSFER statements would overwrite the file after the first end-of-line marker.

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

OPEN DATASET file FOR OUTPUT IN TEXT MODE
                             ENCODING DEFAULT
                             WITH SMART LINEFEED.

TRANSFER: 'Line1' TO file,
          'Line2' TO file,
          'Line3' TO file.

SET DATASET file POSITION 0.
READ DATASET file INTO text.
SET DATASET file POSITION END OF FILE.

TRANSFER: 'Line4' TO file,
          'Line5' TO file,
          'Line6' TO file.

CLOSE DATASET file.

Addition 2

... ATTRIBUTES attr

Effect

This addition can be used to change some of the attributes that were determined when the file was opened with the statement OPENDATASET. attr expects a data object of type dset_changeable_attributes from the type groupDSET (see the table below). The structure dset_changeable_attributes corresponds to the substructure changeable of the structure dset_attributes. Data objects of the structure dset_attributes can be filled using the statement GET DATASET.

ComponentMeaning
indicatorStructure with the components repl_char, conv_errors, code_page, endian, and linefeed_mode. If these components contain the value "X" in attr, the values are used in the components with the same names in the structure dset_changeable_attributes when changes are made.
repl_charIn this component of attr, a single-character character-like replacement character can be specified to overwrite the replacement character specified when the file was opened using the addition REPLACEMENT CHARACTER of the statement OPEN DATASET.
conv_errorsIn this component of attr, the value "I" or "R" can be specified to overwrite the setting made when the file was opened using the addition IGNORING CONVERSION ERRORS. The value "I" suppresses the exceptions, "R" raises the exceptions.
code_pageIn this component of attr, a code page from the column CPCODEPAGE of the database table TCP00 can be specified, to overwrite the code page specified when the file was opened using the addition CODE PAGE of the statement OPEN DATASET.
endianIn this component of attr, the value "B" or "L" can be specified to overwrite the setting made when the file was opened using the additions ${BIG$|LITTLE$} ENDIAN of the statement OPEN DATASET. The value "B" sets the byte order to Big Endian, the value "L" sets it to Little Endian.
linefeed_modeIn this component of attr, one of the values "N", "S", "U" or "W" can be entered to overwrite the setting made using the addition WITH NATIVE$|SMART$|UNIX$|WINDOWS LINEFEED of the statement OPEN DATASET as appropriate.

For some components, the possible input values are defined as constants in the type group DSET.

The values entered in attr must comply with the syntax rules for the relevant additions of the statement OPEN DATASET, otherwise this raises a handleable exception:

  • The components repl_char and conv_errors can only be used when making changes if the file is opened as a text file, legacy text file, or legacy binary file, but not if it is opened as a binary file

  • The components code_page and endian can only be used when making changes if the file is opened as a legacy text file or a legacy binary file.

  • The component linefeed_mode can only be used when making changes if the file is opened as a text file or a legacy text file and if the line-end marker has been set explicitly using the addition WITH LINEFEED.


Note

The modifiable attributes do not affect the attributes of the file in the operating system, but rather the attributes with which the file is opened in ABAP, and which affect how it is handled in ABAP.

Example

Depending on the non-modifiable attributes of the file test.dat, some of its modifiable attributes are changed.

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

OPEN DATASET dset FOR INPUT IN LEGACY TEXT MODE
                            WITH NATIVE LINEFEED.

...

GET DATASET dset ATTRIBUTES attr.

IF attr-fixed-mode = 'T' OR
   attr-fixed-mode = 'LT'.
  attr-changeable = VALUE #(
    indicator-conv_errors = 'X'
    conv_errors = 'I'
    indicator-linefeed_mode = 'X'
    linefeed_mode = 'S' ).
  IF attr-fixed-mode = 'LT'.
    attr-changeable = VALUE #( BASE attr-changeable
      indicator-code_page = 'X'
      code_page = '1100' ).
  ENDIF.
  SET DATASET dset ATTRIBUTES attr-changeable.
ENDIF.

CLOSE DATASET dset.

Exceptions

Catchable Exceptions

CX_SY_CODEPAGE_CONVERTER_INIT

  • Cause: The specified code page is not available for the current .
    Runtime Error:CONVT_CODEPAGE_INIT

CX_SY_CONVERSION_CODEPAGE

  • Cause: The escape character cannot be displayed in the target code page. Replacement characters and handling of conversion errors can only be changed in TEXT MODE or in LEGACY ... MODE.
    Runtime Error:CONVT_CODEPAGE

CX_SY_FILE_OPEN_MODE

  • Error Type: READ_ONLY
    Cause: File is only open for reads.
    Runtime Error:DATASET_READ_ONLY
  • Error Type: NOT_OPEN
    Cause: File is not open.
    Runtime Error:DATASET_NOT_OPEN
  • Error Type: INCOMPATIBLE_MODE
    Cause: File opened in incompatible mode.
    Runtime Error:DATASET_INCOMPATIBLE_MODE

CX_SY_FILE_POSITION

  • Error Type: SEEK_ERROR
    Cause: Error when positioning in file.
    Runtime Error:DATASET_SEEK_ERROR
  • Error Type: TELL_ERROR
    Cause: No access to current writing/reading position in the file.
    Runtime Error:DATASET_NO_POSITION
  • Error Type: OFFSET_TOO_LARGE
    Cause: The specified offset for the file exceeds the defined
    system limit for the platform.
    Runtime error: DATASET_OFFSET_TOO_LARGE


Non-Catchable Exceptions

  • Cause: An attempt was made to change the position in the case of a pipe. Pipes cannot, however, be positioned.
    Runtime Error:DATASET_PIPE_POSITION







ROGBILLS - Synchronize billing plans   General Material Data  
This documentation is copyright by SAP AG.

Length: 17561 Date: 20200219 Time: 054656     sap01-206 ( 97 ms )

Our Service

Looking for Support? Questions?

The

Consolut

Callback-Service

Leave us your contact details and we will call you back. Panels marked with * are mandatory.