[ABAP] Dateien eines Verzeichnises auf dem Applikationsserver auflisten

Variante 1 (EPS2_GET_DIRECTORY_LISTING)

PARAMETERS: p_fdir TYPE eps2filnam DEFAULT '/usr/sap/tmp'.
PARAMETERS: p_mask TYPE eps2filnam DEFAULT '*.xml'.

START-OF-SELECTION.

  DATA: it_files TYPE STANDARD TABLE OF eps2fili WITH DEFAULT KEY.

  DATA: lv_dir_name TYPE epsf-epsdirnam.
  DATA: lv_file_counter TYPE epsf-epsfilsiz.
  DATA: lv_error_counter TYPE epsf-epsfilsiz.

* Alle Dateien im Verzeichnis lesen
* file_mask ist fehlerhaft implementiert, daher muss im Nachgang manuell gefiltert werden, s.u.
  CALL FUNCTION 'EPS2_GET_DIRECTORY_LISTING'
    EXPORTING
      iv_dir_name            = p_fdir
*     file_mask              = ''
    IMPORTING
      dir_name               = lv_dir_name
      file_counter           = lv_file_counter
      error_counter          = lv_error_counter
    TABLES
      dir_list               = it_files
    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.
    WRITE: / lv_dir_name, lv_file_counter, lv_error_counter.

* Dateiliste Filtern
    DELETE it_files WHERE NOT name CP p_mask.

    LOOP AT it_files ASSIGNING FIELD-SYMBOL(<f>).
      WRITE: / <f>-name, <f>-size, <f>-mtim, <f>-owner, <f>-rc.
    ENDLOOP.
  ENDIF.

Variante 2 (EPS_GET_DIRECTORY_LISTING)

* nicht mehr Verwenden, da Übergabeparameter zu kurze Datentypen haben