Vous êtes sur la page 1sur 5

An overview on file handling in sap

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.

1.2 Business Scenario-


We all know that different types of payments are made via banks. The requirement is
that we have to build logic for processing of inbound check payment file.i.e after the
cheque payment is made by bank a return file is uploaded on the application server.
We have to pick that file and according to the information contained in the file we
have to update the sap table. And after updating we have to archive that file to
specified target location and after archival delete that file.

1.3 Implementation of the scenario –


So, according to the business scenario and requirement for the inbound interface we
used some abap statements & function modules. And some of the basic abap
statements & function module that we use for such cases has been explained over
here.

* Get the file from the application server


OPEN DATASET lv_filenpath FOR INPUT IN TEXT MODE ENCODING DEFAULT.

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:-

CALL FUNCTION 'EPS_DELETE_FILE'


EXPORTING
file_name = lv_sfile_name
dir_name = lv_sdir_name
EXCEPTIONS
invalid_eps_subdir =1
sapgparam_failed =2
build_directory_failed = 3
no_authorization =4
build_path_failed =5
delete_failed =6
OTHERS = 7.
IF sy-subrc <> 0.
* Error Message: "File Delete Not Successful"
lv_errflag = c_true.
lv_error = text-045.
ENDIF.

Page - 3

Vous aimerez peut-être aussi