Data Interfaces: Working With Files On The Applications Server Working With Files On The Presentation Server
Data Interfaces: Working With Files On The Applications Server Working With Files On The Presentation Server
Data Interfaces: Working With Files On The Applications Server Working With Files On The Presentation Server
The data with which the ABAP programs work, is mostly stored in the central databank of the SAP System. However ABAP programs can also access the file systems of the other two layers of the client-server architecture. That means they can also save or read persistent data from the workstations of the application layer or the desktop computers of the presentation layer. A common use of this possibility is the transfer of data within the SAP system. You can import files into an ABAP program, regardless of what format they have in the file system of the server, edit them there and then save them to the databank. You can also write data from a databank to be edited further in these file systems, as for example with desktop applications for presentation purposes.
Working with Files on the Applications Server Working with Files on the Presentation Server
As the names of files and directory paths vary from operating system to operating system, it is usually the case that programs that access files directly are not platform-independent. The SAP Web AS ABAP System contains a function module and a range of transactions that allow you to work with platform-independent filenames. Using Platform-Independent Filenames
OPEN DATASET opens a file for a particular type of access and storage. TRANSFER transfers the contents of a data object to a file.
READ DATASET transfers data from a file to a data object. GET DATASET using the addition POSITION the current position of the file pointer in a file is ascertained. Using the addition ATTRIBUTES further characteristics of the file are obtained.
SET DATASET using the addition POSITION the position of the file pointer is specified. Using the addition ATTRIBUTES further characteristics of the file can be specified.
TRUNCATE DATASET sets the end of a file to a specified value, thereby changing the size of the file.
For further details about these statements and their additions, see the keyword documentation.
During sequential file operations, the system performs a range of automatic checks, some of which may lead to runtime errors. Refer also to the chapter: Automatic Checks in File Operations.
the system automatically checks the users authorization against the authorization object S_DATASET. This object allows you to assign authorization for particular files from particular programs. You can also assign the authorization to use operating system commands as a file filter.
Do not use S_DATASET to control general access rights to files from ABAP, or user-dependent authorization checks. Instead, use table SPTH (see also General Checks for Accessing Files).
The Authorization Object S_DATASET The object S_DATASET consists of the following fields:
ABAP program name Name of the ABAP program from which access is allowed. This allows you to restrict file access to a few programs specifically for that task. Activity Possible values are: Read file normally Write to or delete file normally Read file with filter (operating system command) Write to file with filter (operating system command) File Name Name of the operating system file. This allows you to restrict the files to which the user has access.
Users and
If the result of the automatic authorization check is negative, a runtime error occurs. You should therefore check the authorization in your ABAP program before accessing the file using the function module AUTHORITY_CHECK_DATASET.
The Function Module AUTHORITY_CHECK_DATASET This function module allows you to check whether the user is authorized to access a file before the system tries to open it. This preempts a possible runtime error that can otherwise occur in the automatic authorization check. The function module has the following import parameters:
PROGRAM Name of the ABAP program from which the file is to be opened. If you do not specify a program name, the system assumes the current program. ACTIVITY Access type, with the following possible values:
SABC_ACT_INIT(4) SABC_ACT_ACCEPT(6) SABC_ACT_CALL(4) FILENAME Name of the file that you want to access.
TYPE-POOLS SABC. ..... CALL FUNCTION 'AUTHORITY_CHECK_DATASET' EXPORTING PROGRAM ACTIVITY FILENAME EXCEPTIONS NO_AUTHORITY = SY-REPID = SABC_ACT_READ = '/tmp/sapv01' = 1
ACTIVITY_UNKNOWN = 2. ...... This function module call finds out whether the current program may access the file /tmp/sapv01.
the system automatically checks against table SPTH. This table regulates general read and write access from ABAP to files, and whether files should be included in security procedures. In table SPTH, you can prevent read or write access to genericallyspecified files, independently of the SAP authorization concept. For all other files (that is, those for which read and write access is allowed according to table SPTH), you can execute authorization checks with the SAP authorization concept. To enable you to do this, you can specify authorization groups in table SPTH for program-independent user authorization checks.
Suppose SPTH contains the following three entries in the column PATH: * /tmp /tmp/myfile The entries are then valid as follows: First line: All files on the application server apart from the path /tmp Second line: All files on the application server in the path /tmp apart from the file /tmp/myfile Third line: The application server file /tmp/myfile SAVEFLAG This column is a flag that you set using X. If the flag is set, the files specified in the PATH column are included in security procedures. FS_NOREAD This column is a flag that you set using X. If the flag is set, this means that no access to the files specified in the PATH column is allowed from ABAP. This flag overrides all user authorizations. If you set FS_NOREAD, FS_NOWRITE is also automatically set. If the flag is not set, it is possible to access the files from ABAP if the authorization checks are successful (see also the FSBRGRU column and Authorization Check for Particular Programs and Files). FS_NOWRITE This column is a flag that you set using X. If the flag is set, this means that no write access is allowed to the files specified in the PATH column. This flag overrides all user authorizations. If the flag is not set, it is possible to change the files from ABAP if the authorization checks are successful (see also the FSBRGRU column and Authorization Check for Particular Programs and Files). FSBRGRU
This column contains the names of authorization groups. An authorization group corresponds to the first field (RS_BRGRU) of the authorization object S_PATH. You can use the second field of the authorization object S_PATH (ACTVT) to check whether the user has authorization to read (value 3) or change (value 2) the files in he authorization group. Entries in FSBRGRU specify groups of files on the application server. You can control the access to files by assigning authorizations for the authorization object S_PATH.
Unlike authorization checks using the authorization object S_DATASET (see Authorization Checks for Particular Programs and Files), the authorization check against the authorization object S_PATH is independent of the ABAP program used to access the files. Furthermore, the check is not restricted to individual files. Instead, it extends to all of the generically-specified files in the PATH column. If there is no entry in the column FSBRGRU, the files in the column PATH are not assigned to an authorization group, and there is no authorization check against the authorization object S_PATH.
If the automatic check for a file access fails, a runtime error occurs.
Suppose the table SPTH contains the following entries: PATH * /tmp /tmp/files X SAVEFLAG FS_NOREAD X
FS_NOWR X
With these settings, ABAP programs cannot access any files on the application server apart from those in the path (/tmp). All ABAP programs can read from and write to the files in that path. Only users with authorizations for the authorization group FILE can use ABAP program that read from or write to files in the path /tmp/files. These files are also included in the security procedure. With the above table entries, the following program extract would cause a runtime error for any user: DATA: fname(60) TYPE c. fname = '/system/files'.
Basis Components System Administration Platform-independent File Names. For a more detailed description of the function module FILE_GET_NAME, enter its name on the initial screen of the Function Builder and choose Goto Documentation. On the next screen, choose Function module doc. Another way of maintaining platform-independent filenames is to use the Transaction refer to the FILE. For information about platform-dependent filenames, Platform Independent Filename Assignment section of the