Handling Files on Application Server in SAP: DATASET Statement and other tools

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.

Files on application server in sap with DATASET functions

OPEN DATASET

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 Access Mode

INPUT

FOR INPUT opens the file for reading.
if the file does not exist, the sy-subrc is set to 8.

OUTPUT

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.

APPENDING

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.

UPDATE

FOR UPDATE opens the file for changes to the existing content.

Encoding

To handle file encoding, check this Abap Code Page

For the full documentation of OPEN DATASET, check this link

READ DATASET

READ DATASET exports data from the file specified in dset into the data object dobj.

TRANSFER

TRANSFER passes the content of data object dobj to the file specified in dset

DELETE DATASET

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.

More tools for handling Files on application server

File Functions

Function Description
RZL_READ_DIRRead directories of an application server
FMCT_DELETE_UNIXFILEDelete file on application server
SMUM_XML_PARSEParse XML docment into a table structure
PFL_CHECK_OS_FILE_EXISTENCECheck if file exist
PFL_COPY_OS_FILEMove 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.

Application Server File with CL_RSAN_UT_APPSERV_*

CL_RSAN_UT_FILES

Utility Class for Supporting Files on GUI/App Server

Method Description
F4_APP_SERVERF4 Popup for Application Server Name
F4F4 Help for Choosing File Name from GUI or App. Server

CL_RSAN_UT_APPSERV_FILE_READER

Class Encapulating Block Reading from Application Server File

Method Description
FREEFree Resources
OPENOpen File
CLOSEClose File
READRead Block of Lines

CL_RSAN_UT_APPSERV_FILE_WRITER

Class Encapulating Block Writing to App. Server File

Method Description
APPSERVER_FILE_WRITEWrite Data to Specified File on Application Server
FREEFree Resources
OPENOpen File
CLOSEClose File
WRITEWrite Block of Lines

Sab125

Hi. I have been working as SAP Technical and functional for a decade. Through this blog, I am trying to share with you my experience. Hopefull, it makes your ways easier path ...Sab