File Handling in Sap Basic
File Handling in Sap Basic
Table of Contents
1 FILE HANDLING.........................................................................................................................1
1.1 OVERVIEW- .............................................................................................................................1
1.2 BUSINESS SCENARIO-.................................................................................................................1
1.3 IMPLEMENTATION OF THE SCENARIO –..............................................................................................1
1 FILE HANDLING
1.1 Overview-
This document has been prepared keeping in mind the target group who are
new to file handling in SAP. It deals with the basic abap statements & function
modules that we can use for opening, closing , reading or deleting any file. It
also deals with the function module that we can use for archival of file from
the application server. So, basically this document is for beginners, who are
completely new to this file handling.
IF sy-subrc <> 0.
* Error Message: "Unable to read file"
lv_errflag = c_true.
lv_error = text-042.
EXIT.
ELSE.
DO.
* Move the input file data to internal table
READ DATASET lv_filenpath INTO l_wa_record.
IF sy-subrc = 0.
APPEND l_wa_record TO lt_record.
CLEAR l_wa_record.
Page - 1
ELSE.
EXIT.
ENDIF.
* Close Files
CLOSE DATASET lv_filenpath.
File archival
For file archiving we can use this function module.
In the exporting parameter we have to pass the source path and the target path.
Source path is the path where file lies before archival and the target path is the
one where we have to archive the file.
CALL FUNCTION 'FI_SG_ARCHIVE_FILE'
EXPORTING
sourcepath = lv_sfile
targetpath = lv_dfile
EXCEPTIONS
error file = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Error Message: "File Archive Not Successful"
lv_errflag = c_true.
lv_error = text-044.
ENDIF.
Page - 2
File deletion.
After archival of the file we were supposed to delete the file from the archived
location.
The function module that we used for this purpose is following:-
Page - 3