Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

FM for getting teh file name with path

Hi guys,

Is there an fm getting the file name with path given the physical path and file name? Thanks!

Former Member
Former Member replied

Hi Mark,

Function Module WS_FILENAME_GET is obsolete, dont use it.

Use the Method file_open_dialog of class cl_gui_frontend_services as given below.

    lt_filetable TYPE filetable,
    lf_rc        TYPE i,
    lv_filename(50) TYPE c,
    lv_fileext(3) TYPE c,
    ls_file TYPE file_table,
    lv_file TYPE localfile,
    lv_title TYPE string.

  lv_title = sy-title.
  lv_progname = sy-cprog.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
      window_title            = lv_title
      file_filter             = '*.txt'
      multiselection          = abap_false
      file_table              = lt_filetable
      rc                      = lf_rc
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
               DISPLAY LIKE 'E'
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

* Number of selected filed must be equal to one.
  CHECK lf_rc = 1.

* Access selected file
  READ TABLE lt_filetable INTO ls_file INDEX 1.

  CHECK sy-subrc = 0.

  lv_file = ls_file-filename.

  SPLIT lv_file AT '.' INTO lv_filename lv_fileext.

Revert back if you need clarifications.


Karthik D

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question