ABAP File Interface

The statements

of the ABAP file interface enable files to be processed on computers on the application server using ABAP statements. For files on the presentation server, function modules or global classes are available.

Addressing files

In all statements of the file interface, files are addressed directly using the name under which they are known on the current platform. A file therefore cannot be opened more than once within a program. The name of a file is normally composed of a file path and the name of the file. The notation used depends on the operating system of the application server. If a file name is specified without a file path, the directory stored in the profile parameter DIR_HOME is used automatically.

If writing cross-platform programs, SAP recommends that you use the transaction FILE to create logical file names and logical paths, which can be linked to every platform using actual names. The function module FILE_GET_NAME can be used to determine a logical file name for the actual name that is valid for the current platform. This name can then be used in statements of the file interface.

In Unicode programs, file names that contain blank characters are permitted. If the specified file name in a non-Unicode program contains blank characters, it is cut off after the first blank character. In Unicode programs, the blank characters are a part of the file name.

Authorizations for file access

File access authorizations can be viewed on three different levels:

Operating system check

From the perspective of the operating system on the application server, all file accesses are executed by the ABAP system. As a consequence, the user of the operating system on which an ABAP-based SAP system is installed must have read and write access to all directories and files that are used by the ABAP file interface. If the user does not have an appropriate authorization, the statements of the file interface cannot be executed, or only partly. If a statement cannot be executed due to a missing authorization in the operating system, the return value sy-subrc is set to a value that is not 0.

Program-independent check of access authorizations

If files are accessed using the statements , OPEN DATASET, TRANSFER, and DELETE DATASET, the system automatically checks the entries in the database table SPTH. The entries in the database table SPTH control general read and write access from ABAP programs to files, and whether files should be included in a safety backup procedure.

In the database table SPTH, read and write access to generically specified files can be generally forbidden, regardless of authorization objects. For the remaining files (files for which read or write access is generally permitted in the database table SPTH, authorization checks can be performed based on authorization objects. For this, authorization groups for program-independent authorization checks can be defined in the database table SPTH. The following table shows the columns of the database table SPTH. If the check of the database table SPTH has a negative result, this leads to an untreatable exception.

Column Meaning
PATH Column for generic file names. The properties specified in the other columns of this line apply for all files of the application server for which the entry in this column is the most appropriate.
SAVEFLAG If this column contains the value "X", the files specified in the column PATH are saved in a backup procedure.
FS_NOREAD If this column contains the value "X", the files specified in the column PATH cannot be accessed from ABAP. This setting overrides the settings in the columns FS_NOWRITE and FS_BRGRU and the authorization check using the authorization object S_DATASET.
FS_NOWRITE If this column contains the value "X", no write access is permitted from ABAP to the files specified in the column PATH. This setting overrides the settings in the column FS_BRGRU and the authorization check using the authorization object S_DATASET.
FS_BRGRU In this column, you can define a name of your choice for an authorization group. The files of several lines can then be grouped into authorization groups. When the database table SPTH is evaluated, an authorization check for the current user is performed against the authorization object S_PATH. This authorization object contains an authorization field RS_BRGRU and an authorization field ACTVT, which are used to permit user-specific access to the files specified in PATH. If no name is specified, no authorization check against the authorization object S_PATH is performed.

Note

In contrast to the authorization check using the authorization object S_DATASET, the check against the authorization object S_PATH is independent of the ABAP program being used. This check is also not restricted to an individual file, instead it includes all generically specified files in the column PATH.

Authorization check for user and program for individual files.

Before each time a file is opened or deleted using the ABAP file interface, an authorization check is carried out for the current user and the current program with the predefined authorization object S_DATASET. This authorization object has the authorization fields PROGRAM for the program name, FILENAME for the file to be opened, and ACTVT with the activities delete, read, write, read with filter, and write with filter. If the user does not have the appropriate authorization, this leads to a treatable exception (as of release 6.10). To avoid this exception, the function AUTHORITY_CHECK_DATASET can be called before the relevant ABAP statement, to check whether the authorization exists.

Locks

The database interface does not have an integrated lock mechanism to ensure that only one ABAP program accesses a file at any one time. If several programs simultaneously gain write access to a file, this will have unpredictable results.

To avoid this situation, SAP locks can be assigned, or unique file names such as GUIDs can be used.

Note

If several application servers of an application layer access a file at the same time, conflicts may still arise even if SAP locks are used (for example, if the operating system buffers data before it is written to a file).

The file interface in Unicode programs

As the content of files often reflects the file structure in the working memory, the file interface in a Unicode system must satisfy the following requirements:

  1. It must be possible to exchange files between Unicode and non-Unicode systems.

  2. It must be possible to exchange files between different Unicode systems.

  3. It must be possible to exchange files between different non-Unicode systems that work with different code pages.

For this reason, Unicode programs must always specify which code page is used to encode character-type data that is written to or read from text files.

Further to these conditions, it must also be possible to execute a Unicode program in both Unicode and non-Unicode systems. Some syntax rules for the file interface have therefore been changed to programming file access in Unicode programs less prone to errors than in non-Unicode programs:

  1. A file must be opened explicitly before each read or write access. A file cannot be opened again once it is open. In non-Unicode programs, the first time a file is opened, it is opened implicitly using the standard settings. In non-Unicode programs, the statement for opening a file can be used on a file that is already open, although a file in a program can only be opened once.

  2. When opening the file, the access type and the type of data store must be specified explicitly. In non-Unicode programs, a file is opened implicitly with the standard settings, if not specified otherwise.

  3. If a file has been opened only with read access, it remains read-only. In non-Unicode programs, write access to the same file is also possible.

  4. If a file is opened as a text file, only the content of character-type data objects may be read or written. In non-Unicode programs, byte-type and numeric data objects are also permitted.

Essentially, instead of implicit programming with standard settings on which the developer has no influence, explicit programming is required in which all the important parameters must be specified. Mixed format files containing a combination of byte-type, character-type, and numeric data are prone to errors and are forbidden.

SAP therefore recommends that you always follow the syntax rules for Unicode programs when using the file interface, even if you are not using a Unicode system.

File size

As of release 6.10, files larger than 2 GB can be edited on all platforms that support this file size. Only the operating system OS/390 is still excluded from this.