Application Development 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: 

FM for getting teh file name with path

Former Member
0 Kudos

Hi guys,

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

DATA:
    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
    EXPORTING
      window_title            = lv_title
      file_filter             = '*.txt'
      multiselection          = abap_false
    CHANGING
      file_table              = lt_filetable
      rc                      = lf_rc
    EXCEPTIONS
      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.
    EXIT.
  ENDIF.

* 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.

Regards

Karthik D

6 REPLIES 6

Former Member
0 Kudos

Hi,

Please check the below code.

PARAMETERS : p_flnm LIKE rlgrap-filename.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FLNM.

perform F4_HELP.


FORM F4_HELP.

  IF SY-UCOMM <> 'onli'.
    CALL FUNCTION 'WS_FILENAME_GET'
         EXPORTING
              DEF_FILENAME     = P_FLNM
              DEF_PATH         = 'c:\my documents'
              MASK             = ',*.*,*.*.'
              MODE             = 'O'
              TITLE            = 'Open PC File for Upload'
         IMPORTING
              FILENAME         = P_FLNM
         EXCEPTIONS
              INV_WINSYS       = 01
              NO_BATCH         = 02
              SELECTION_CANCEL = 03
              SELECTION_ERROR  = 04.
    IF SY-SUBRC <> 0.
      MESSAGE E000(0) WITH 'error locating upload file on PC' P_FLNM.
    ENDIF.
  ENDIF.

ENDFORM.

Regards,

Former Member
0 Kudos

HI,

just use function module 'WS_FILENAME_GET'

it will definately help you.

THANKS AND REGARDS

Rahul Sharma

Former Member
0 Kudos

Hi...

can be down like this,,,

PARAMETERS: p_file TYPE ibipparms-path OBLIGATORY

DEFAULT 'C:\'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

field_name = 'P_FILE'

IMPORTING

file_name = p_file.

Regards,

sg

Former Member
0 Kudos

Hi,

The Function Module FILE_GET_NAME

Platform-independent file names are used in applications programs by the function module FILE_GET_NAME. For a given logical file name, the function module generates the corresponding platform-specific file name at runtime, based on definitions stored in customizing tables for converting platform-independent file names.

Hope this helps.

Thanks,

Rashmi.

Former Member
0 Kudos

Hi,

Try: CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

Regards, Dieter

Former Member
0 Kudos

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.

DATA:
    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
    EXPORTING
      window_title            = lv_title
      file_filter             = '*.txt'
      multiselection          = abap_false
    CHANGING
      file_table              = lt_filetable
      rc                      = lf_rc
    EXCEPTIONS
      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.
    EXIT.
  ENDIF.

* 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.

Regards

Karthik D