Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

OPEN DATASET XML-File from Application Server

Former Member
0 Likes
5,389

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!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,394

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

3 REPLIES 3
Read only

Former Member
0 Likes
2,395

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

Read only

0 Likes
2,394

Thank you pallavi! this is the function that i have searched
And i can use the filemask for filtering xml files

Read only

Former Member
0 Likes
2,394

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