2016 Jan 26 4:32 PM
Hey Guys,
i would like to get all XML-Files from a Path on the Application Server. (From one Directory)
How can i read all XML-Files from one Directory of the Application Server.
And how can i read the XML-Files with OPEN DATASET?
My actual Code is:
OPEN DATASET file FOR INPUT
IN BINARY MODE." ENCODING UTF-8.
WHILE sy-subrc = 0.
READ DATASET file INTO g_xml_line.
APPEND g_xml_line to g_xml_table.
ENDWHILE.
CLOSE DATASET file.
My goal is to read all XML-Files and put them into a xstring variable.
I belive in you guys!
2016 Jan 26 5:36 PM
Hi,
Please use the below FM:
DATA lv_pfile TYPE epsdirnam. "Give the Application server path here
DATA lv_filecnt LIKE epsf-epsfilsiz.
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
dir_name = lv_pfile "
file_mask = '*.*'
IMPORTING
file_counter = lv_filecnt
TABLES
dir_list = gt_file " Contains the list of all files on the Appl. Server
EXCEPTIONS
invalid_eps_subdir = 1
sapgparam_failed = 2
build_directory_failed = 3
no_authorization = 4
read_directory_failed = 5
too_many_read_errors = 6
empty_directory_list = 7
OTHERS = 8.
IF sy-subrc <> 0.
"Suitable messages
ENDIF.
The number of lines in the gt_file are the number of files available on Appl. server.
You can later check for XML files as :
loop at gt_file into ls_file where name cs '.xml'.
" Here you can process all the XML files.
endloop.
Regards,
Pallavi
2016 Jan 26 5:36 PM
Hi,
Please use the below FM:
DATA lv_pfile TYPE epsdirnam. "Give the Application server path here
DATA lv_filecnt LIKE epsf-epsfilsiz.
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
dir_name = lv_pfile "
file_mask = '*.*'
IMPORTING
file_counter = lv_filecnt
TABLES
dir_list = gt_file " Contains the list of all files on the Appl. Server
EXCEPTIONS
invalid_eps_subdir = 1
sapgparam_failed = 2
build_directory_failed = 3
no_authorization = 4
read_directory_failed = 5
too_many_read_errors = 6
empty_directory_list = 7
OTHERS = 8.
IF sy-subrc <> 0.
"Suitable messages
ENDIF.
The number of lines in the gt_file are the number of files available on Appl. server.
You can later check for XML files as :
loop at gt_file into ls_file where name cs '.xml'.
" Here you can process all the XML files.
endloop.
Regards,
Pallavi
2016 Jan 27 8:16 AM
Thank you pallavi! this is the function that i have searched
And i can use the filemask for filtering xml files
2016 Jan 26 6:44 PM
Hi Julian,
You can read the XML file in the same way as normal file. In your code just put the following condition after Read statement in the While loop otherwise you will get a blank line at the end of the file.
if sy-subrc <> 0.
exit.
endif.
-Chandra