Saturday, March 15, 2014
  
CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES method retrieves a list of the directories and/or files on the client PC in the specified directory.

REPORT ZTEST_FRONT_END_SERVICES.
*&----------------------------------------------------*
* Declaration
*&----------------------------------------------------*
DATA: lt_file_table   TYPE TABLE OF file_info,
      ls_file_table   LIKE LINE OF lt_file_table.
DATA: lv_count        TYPE i.
data: lv_last_char    TYPE c.
data  lv_filename     TYPE string.
*&----------------------------------------------------*
* Selection-screen
*&----------------------------------------------------*
PARAMETERS: p_dir type string.

*&----------------------------------------------------*
* Start-of-selection
*&----------------------------------------------------*
START-OF-SELECTION.

  CALL METHOD cl_gui_frontend_services=>directory_list_files
    EXPORTING
      directory                   = p_dir
*     filter                      = '*.*'
      files_only                  = 'X'
    CHANGING
      file_table                  = lt_file_table
      count                       = lv_count
    EXCEPTIONS
      cntl_error                  = 1
      directory_list_files_failed = 2
      wrong_parameter             = 3
      error_no_gui                = 4
      not_supported_by_gui        = 5
      OTHERS                      = 6.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    LOOP AT lt_file_table INTO ls_file_table.
      IF lv_last_char = '\'.
        CONCATENATE p_dir ls_file_table-filename INTO lv_filename.
      ELSE.
        CONCATENATE p_dir '\' ls_file_table-filename INTO lv_filename.
      ENDIF.
      WRITE lv_filename.
    ENDLOOP.
  ENDIF.

1 comment:

  1. Nice Blog..
    I just want to know the class and method to get AL11 dictionary files.

    ReplyDelete

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.