This article introduces working with files on application server in SAP with ABAP.
Its covers the most used functions to Handle Files on Application Server in SAP with ABAP with ready to run ABAP program to handle file.
Table of Contents
OPEN DATASET is for accessing files in a storage mode.
Filename should be the name of the file ( with path ) on application server.
OPEN DATASET Filename FOR access IN mode [position] [os_addition] [error_handling].
FOR INPUT opens the file for reading.
if the file does not exist, the sy-subrc is set to 8.
FOR OUPUT opens the file for writing.
If the file exists, the content will be deleted and remplaced
If the file does not exist, the file will be created.
FOR APPENDING open the file for appending.
The new content will be added to the end of existing file or the file will be created if not exist.
sy-subrc = 4 will be triggered if appending is not successfull.
FOR UPDATE opens the file for changes to the existing content.
To handle file encoding, check this Abap Code Page
For the full documentation of OPEN DATASET, check this link
The Standard ABAP Statement READ DATASET exports data from the file specified in dset into the data object dobj.
READ DATASET Filename INTO dobj [MAXIMUM LENGTH mlen] [[ACTUAL] LENGTH alen].
ABAP Statement TRANSFER passes the content of data object dobj to the file specified in dset
TRANSFER dobj TO Filename [LENGTH len] [NO END OF LINE].
DELETE DATASET deletes file on application service.
The file must open for output ( OPEN DATASET Filename FOR OUTPUT ) before deleting the file.
You CAN NOT delete the file unless you open the file for output.
DATA: lv_file(255). OPEN DATASET lv_file FOR INPUT IN BINARY MODE. IF sy-subrc EQ 0. CLOSE DATASET lv_file. DELETE DATASET lv_file. CLOSE DATASET lv_file. ENDIF.
Function | Description |
---|---|
RZL_READ_DIR | Read directories of an application server |
FMCT_DELETE_UNIXFILE | Delete file on application server |
SMUM_XML_PARSE | Parse XML docment into a table structure |
PFL_CHECK_OS_FILE_EXISTENCE | Check if file exist |
PFL_COPY_OS_FILE | Move file on application |
/SAPDMC/LSM_F4_SERVER_FILE | Help Search for SAP application server folder selection |
EPS_GET_DIRECTORY_LISTING | Get list of files in folder/Directory in Application server |
EPS_GET_FILE_ATTRIBUTES | Get file details in SAP application server. |
In order to retrieve the list of all the directory in ABAP from Application server in ABAP, use the standard function module?RZL_READ_DIR.
An alternative to read application server Directory in ABAP is to use fm?EPS_GET_DIRECTORY_LISTING.
Utility Class for Supporting Files on GUI/App Server
Method | Description |
---|---|
F4_APP_SERVER | F4 Popup for Application Server Name |
F4 | F4 Help for Choosing File Name from GUI or App. Server |
Class Encapulating Block Reading from Application Server File
Method | Description |
---|---|
FREE | Free Resources |
OPEN | Open File |
CLOSE | Close File |
READ | Read Block of Lines |
Class Encapulating Block Writing to App. Server File
Method | Description |
---|---|
APPSERVER_FILE_WRITE | Write Data to Specified File on Application Server |
FREE | Free Resources |
OPEN | Open File |
CLOSE | Close File |
WRITE | Write Block of Lines |
July 12, 2018 January 21, 2020
December 21, 2017 January 21, 2022
December 19, 2017 January 21, 2020