This Function Module is mainly used in Interface type of objects.
One specific selection screen frame must be added to feed the function module call for each file read (with file name and repository for archiving).
Function module ZFILE_ARCHIVE is created for that purpose.
Local Interface:
IMPORTING
VALUE(I_SFILE) TYPE LOCALFILE (Source Filepath)
VALUE(I_DPATH) TYPE LOCALFILE (Destination Filepath)
VALUE(I_FILENAME) TYPE LOCALFILE (Filename)
EXCEPTIONS
ERROR_OPENING_SOURCE_FILE
ERROR_OPENING_TARGET_FILE
In the source code write the below code:
* Variables
DATA : lv_data TYPE string,
lv_len TYPE char02,
lv_archvive TYPE localfile.
lv_len = strlen( i_filename ).
lv_len = lv_len - 4.
* Filename has extension or not
IF i_filename+lv_len(1) EQ '.'.
lv_archvive = i_dpath.
ELSE.
CONCATENATE i_dpath " Destination path
i_filename " File name without extension
sy-datum " Sys date
sy-uzeit " Sys time
INTO lv_archvive.
ENDIF.
OPEN DATASET i_sfile IN LEGACY TEXT MODE FOR INPUT IGNORING CONVERSION ERRORS.
IF sy-subrc NE 0.
RAISE error_opening_source_file.
ENDIF.
OPEN DATASET lv_archvive IN LEGACY TEXT MODE FOR APPENDING IGNORING CONVERSION ERRORS.
IF sy-subrc NE 0.
RAISE error_opening_target_file.
ENDIF.
* copy the file from source to destination
DO.
READ DATASET i_sfile INTO lv_data.
IF sy-subrc EQ 0.
TRANSFER lv_data TO lv_archvive.
CLEAR lv_data.
ELSE.
EXIT.
ENDIF.
ENDDO.
* Delete the source file after copy
DELETE DATASET i_sfile.
* Close all open dataset
CLOSE DATASET: i_sfile,
lv_archvive.
CLEAR : lv_data.
Eg:
Selection Screen
Logical Path for Source File is the path from where the file is retrieved from Application Server.
Logical Path for archieve file is the path to where the file is archieved to the Application Server using the Function Module 'ZFILE_ARCHIVE'.