SAP OPEN DATASET ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID OPEN-DATASET
• OPEN DATASET ABAP Statement
• IN OPEN DATASET
• FOR OPEN DATASET

OPEN DATASET
Short Reference

ABAP_SYNTAX
OPEN DATASET dset FOR access IN mode $[ position$]
$[ os_additions$]
$[ error_handling$].

What does it do?
This statement opens the file specified in dset on the host computer of the current ABAP_ASINSTANCE 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 catchable exception is raised.
The additions positions, os_addition, and error_handling can be used to determine the position at which file is opened, specify platform-dependent additions, and can be used for error handling.



Latest notes:

Up to 100 files can be opened per ABAP_ISESS . The actual maximum number of simultaneously open files may be less, depending on the platform. If the maximum number of open files is exceeded, a catchable exception is raised.
When a file is opened, automatic authorization checks are performed, but self-programmed checks may also be necessary.
ABAP_HINT_END

ABAP_HINT_SEC
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.
ABAP_HINT_END
ABAP_SUBRC_GENERAL sy-subrcMeaning 0The file was opened. 8The operating system could not open the file.
In order to find the reason, why the operating system could not open a file, the addition MESSAGE should always be used for the statement OPEN DATASET. In case of an error, a message is also written to the developer trace, but only if the trace level is 2 at least.



Example ABAP Coding

The example demonstrates the following:
Opening a file for writes
Writing binary XML data to the file
Closing the open file
Opening the file for reads
Reading the binary XML data from the file
Closing the open file
Deleting the file
The XML data is created by transforming an internal table to the asXML format.
ABEXA 00459
ABAP_EXAMPLE_END



Runtime Exceptions



Catchable Exceptions
CX_SY_FILE_OPEN
Reason for error:
The file is already open.
Runtime error:
DATASET_REOPEN
CX_SY_CODEPAGE_CONVERTER_INIT
Reason for error:
The required conversion is not supported. (Due to specification of invalid code page or of language not supported in the conversion, with SET LOCALE LANGUAGE.)
Runtime error:
CONVT_CODEPAGE_INIT
CX_SY_CONVERSION_CODEPAGE
Reason for error:
Internal error in the conversion.
Runtime error:
CONVT_CODEPAGE
CX_SY_FILE_AUTHORITY
Reason for error:
No authorization for access to file
Runtime error:
OPEN_DATASET_NO_AUTHORITY
Reason for error:
Authorization for access to this file is missing in OPEN DATASET with the addition FILTER.
Runtime error:
OPEN_PIPE_NO_AUTHORITY
CX_SY_PIPES_NOT_SUPPORTED
Reason for error:
The operating system does not support pipes.
Runtime error:
DATASET_NO_PIPE
CX_SY_TOO_MANY_FILES
Reason for error:
Maximum number of open files exceeded.
Runtime error:
DATASET_TOO_MANY_FILES

Non-catchable Exceptions
Reason for error:
An attempt was made to open a pipe that is already open.
Runtime error:
DATASET_PIPE_POSITION
ABAP_NONCAT_END

Return to menu