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
Syntax
OPEN DATASET dset FOR access IN
mode [position]
[os_additions]
[error_handling].
Effect
This statement opens the file specified in dset for the access specified in access in a storage mode specified in mode. dset expects a character-like data object containing the physical name of the file. The file must not yet be open in the current program; otherwise a handleable exception is raised.
Use the additions positions,
os_addition,
and error_handling
to determine the position at which file is opened, specify platform-specific additions, and influence error handling.
Notes
Security Note
Access to a file whose name dset is injected into a program from outside is a serious security risk. Any names passed to a program from outside must be checked thoroughly before being used. See
Directory Traversal.
Return Value
| sy-subrc | Meaning |
| 0 | The file was opened. |
| 8 | The operating system could not open the file. |
Example
The example demonstrates the following:
The XML data is created by transforming an internal table to the asXML format.
SELECT *
FROM scarr
INTO TABLE @DATA(itab).
CALL TRANSFORMATION id SOURCE scarr = itab
RESULT XML DATA(xml).
DATA(dset) = 'scarr.dat'.
OPEN DATASET dset FOR OUTPUT IN BINARY MODE.
TRANSFER xml TO dset.
CLOSE DATASET dset.
...
CLEAR xml.
OPEN DATASET dset FOR INPUT IN BINARY MODE
READ DATASET dset INTO xml.
CLOSE DATASET dset.
CALL TRANSFORMATION id SOURCE XML xml
RESULT scarr = itab.
cl_demo_output=>display( itab ).
DELETE DATASET dset.
Handleable Exceptions
CX_SY_FILE_OPEN
CX_SY_CODEPAGE_CONVERTER_INIT
CX_SY_CONVERSION_CODEPAGE
CX_SY_FILE_AUTHORITY
CX_SY_PIPES_NOT_SUPPORTED
CX_SY_TOO_MANY_FILES
Non-Handleable Exceptions