2012 Jun 21 5:54 PM
Dear Experts,
I want to read a file from the ftp server and want to delete it from the server after reading it.
I know only the folder in which this will contain for example "/from_X"
The files in the folder have the following naming convention :
ddmmyyyyhhmm.txt which is date (first 8 digits) and last 4 digits are time in (hhmm).
Want to read each file(the oldest first and the latest last).After reading each file I want to delete it also from the server.
I want to use the Functionmodule "FTP_SERVER_TO_R3" for this purpose.
In the wrk_file,we have to give the file name as well here apart from the folder,but as I said I dont know the filename.
How should I go about it to get the list of files from the folder and delete it.
wrk_file = '/from_X'.
CALL FUNCTION 'FTP_SERVER_TO_R3'
EXPORTING
handle = w_hdl
fname = wrk_file
character_mode = 'X'
* IMPORTING
* BLOB_LENGTH =
TABLES
text = text_tab
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.
Any pointers are welcome.
Thanks
K
2012 Jun 21 8:06 PM
First get all the files from the FTP file directorry using the followimg code:
DATA: filelist TYPE STANDARD TABLE OF sdokpath,
dirlist TYPE STANDARD TABLE OF sdokpath,
w_filelist TYPE sdokpath,
w_path LIKE p_file,
w_dest LIKE p_dest,
w_leng TYPE i.
DATA: filelists TYPE STANDARD TABLE OF emg_fileinfo,
w_filelists TYPE emg_fileinfo.
DATA: w_servdir LIKE temfile-dirname.
DATA: w_dir LIKE epsf-epsdirnam,
w_file LIKE epsf-epsfilnam.
w_leng = STRLEN( p_file ) - 1.
IF p_file+w_leng(1) NE '\'.
CONCATENATE p_file
'\'
INTO p_file.
ENDIF.
w_servdir = p_file(75).
CALL FUNCTION 'ISU_M_GET_FILES_OF_DIR'
EXPORTING
x_path = w_servdir
* X_APPEND = ' '
* X_DISPLAY = ' '
* IMPORTING
* Y_FILEINFO =
TABLES
xy_filetab = filelists
EXCEPTIONS
no_start = 1
no_next = 2
no_finish = 3
general_error = 4
OTHERS = 5
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF p_email IS NOT INITIAL.
PERFORM f_begin_mail TABLES itab_objtxt.
ENDIF.
MOVE p_file TO w_path.
w_leng = STRLEN( p_dest ) - 1.
LOOP AT filelists
INTO w_filelists.
REFRESH:itab_upload.
CLEAR: itab_upload,
p_file,
g_error.
MOVE: w_path TO p_file,
w_dest TO p_dest.
CONCATENATE p_file
w_filelists-name
INTO p_file.
MOVE p_file TO g_source.
CONDENSE p_file.
CONDENSE p_dest.
g_dest = p_dest.
g_source = p_file.
OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
DO.
READ DATASET p_file INTO itab_upload.
IF sy-subrc NE 0.
EXIT.
ELSE.
APPEND itab_upload.
CLEAR itab_upload.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET p_file.
ENDLOOP.
Delete DATASET P_file.
2012 Jun 21 8:06 PM
First get all the files from the FTP file directorry using the followimg code:
DATA: filelist TYPE STANDARD TABLE OF sdokpath,
dirlist TYPE STANDARD TABLE OF sdokpath,
w_filelist TYPE sdokpath,
w_path LIKE p_file,
w_dest LIKE p_dest,
w_leng TYPE i.
DATA: filelists TYPE STANDARD TABLE OF emg_fileinfo,
w_filelists TYPE emg_fileinfo.
DATA: w_servdir LIKE temfile-dirname.
DATA: w_dir LIKE epsf-epsdirnam,
w_file LIKE epsf-epsfilnam.
w_leng = STRLEN( p_file ) - 1.
IF p_file+w_leng(1) NE '\'.
CONCATENATE p_file
'\'
INTO p_file.
ENDIF.
w_servdir = p_file(75).
CALL FUNCTION 'ISU_M_GET_FILES_OF_DIR'
EXPORTING
x_path = w_servdir
* X_APPEND = ' '
* X_DISPLAY = ' '
* IMPORTING
* Y_FILEINFO =
TABLES
xy_filetab = filelists
EXCEPTIONS
no_start = 1
no_next = 2
no_finish = 3
general_error = 4
OTHERS = 5
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF p_email IS NOT INITIAL.
PERFORM f_begin_mail TABLES itab_objtxt.
ENDIF.
MOVE p_file TO w_path.
w_leng = STRLEN( p_dest ) - 1.
LOOP AT filelists
INTO w_filelists.
REFRESH:itab_upload.
CLEAR: itab_upload,
p_file,
g_error.
MOVE: w_path TO p_file,
w_dest TO p_dest.
CONCATENATE p_file
w_filelists-name
INTO p_file.
MOVE p_file TO g_source.
CONDENSE p_file.
CONDENSE p_dest.
g_dest = p_dest.
g_source = p_file.
OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
DO.
READ DATASET p_file INTO itab_upload.
IF sy-subrc NE 0.
EXIT.
ELSE.
APPEND itab_upload.
CLEAR itab_upload.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET p_file.
ENDLOOP.
Delete DATASET P_file.
2012 Jun 28 4:54 PM