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: 

How to select directory path in a selection screen

Former Member

Hi ,

We can select a file path using the below statement :

DATA : P_FILE TYPE RLGRAP-FILENAME.

But how can the similar be achieved for a directory, that is if one wants to select a folder.

Folder path can be retrieved from the function : "TMP_GUI_BROWSE_FOR_FOLDER" but this doesnt give us the privilege of displaying the path selected in a parameter form as is with the file type.

Any kind of help would be apprecialble.

Thanks!!!!

12 REPLIES 12

Former Member
0 Kudos

use this fm /SAPDMC/LSM_F4_SERVER_FILE

Former Member

Hi,

Check this



DATA : f_path TYPE string,
      f_pathname TYPE string.


  CALL METHOD cl_gui_frontend_services=>directory_browse
    CHANGING
      selected_folder      = f_path
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.

if sy-subrc eq 0.
f_pathname = f_path.
WRITE: f_pathname.
endif.

0 Kudos
parameters: path type string.

at selection screen on value request for path.

  CALL METHOD cl_gui_frontend_services=>directory_browse
    CHANGING
      INITIAL_FOLDER     = path
      selected_folder      = path
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.
 if sy-subrc eq 0.

endif.

0 Kudos

thanks for ur answer...

but my query remains the same....

i was already able to get the path via "TMP_GUI_BROWSE_FOR_FOLDER"...what is the requirement is that once user selects such a path...he could see it in the selection screen as it happens in the case of selecting a file using : P_FILE TYPE RLGRAP-FILENAME...while with the fuctions which i used and u suggested...only a box apppears for selecting a directory..and once directory is selected ...path can be retrived as a string...i want user to actually see the path selected...if this function is called after the even...at selection-screen...

thanks!!!!

0 Kudos

Hi,

Try this. I hope this fulfills your requirement. I have added 2 additional lines of code to my previous one.



DATA : f_path TYPE string,
      f_pathname TYPE string.


PARAMETERS: f_path1 TYPE string.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR f_path1.
  CALL METHOD cl_gui_frontend_services=>directory_browse
    CHANGING
      selected_folder      = f_path1
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.

  IF sy-subrc EQ 0.
    f_pathname = f_path1.
    WRITE: f_pathname.
  ENDIF.

0 Kudos

Hi,

Try with below Method

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS : p_file LIKE rlgrap-filename MODIF ID ccc.
SELECTION-SCREEN END OF BLOCK b2.



*---------------------------------------------------------------------*
*     AT SELECTION SCREEEN                                               *
*---------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST  FOR p_file.
  PERFORM f4_filename.


AT SELECTION-SCREEN ON p_file.

  IF p_file IS INITIAL.
    MESSAGE 'Please fill the path' TYPE 'E'.
  ENDIF.




*---------------------------------------------------------------------*
*     START OF SELECTION                                              *
*---------------------------------------------------------------------*

START-OF-SELECTION.



*&---------------------------------------------------------------------*
*&      Form  F4_FILENAME
*&---------------------------------------------------------------------*
*       Get the file from presenation server
*----------------------------------------------------------------------*
FORM f4_filename .

  DATA : lit_filetable TYPE filetable,
         lw_rc TYPE i.
*  Get file from presentation system
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            = 'Find File'                 "#EC NOTEXT
*    DEFAULT_EXTENSION       =
*    DEFAULT_FILENAME        =
      file_filter             = '*.*'
      initial_directory       = 'C:\'
*    MULTISELECTION          =
*    WITH_ENCODING           =
    CHANGING
      file_table              = lit_filetable
      rc                      = lw_rc
*    USER_ACTION             =
*    FILE_ENCODING           =
    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 SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

*  Read file name into variable
  READ TABLE lit_filetable INTO p_file INDEX 1.

ENDFORM.                    " F4_FILENAME

Regards

Bala Krishna

0 Kudos

well i had done this also...but still after selecting...though in the program directpry path can be achieved...but on the selection screen it remains blank for the directory parameter...which doent seem good at user-end...

Hope m clear abt my problem!!!

0 Kudos

Hi Bala...I was asking abt directory...not file...

thanks!!!!

0 Kudos

Hi,

This seems to be working fine for me. I mean your problem is that the directory path is not dispayed in the selection screen, but it seems to be working fine with me. Have you tried the same piece of code?

0 Kudos

Hi Nitwick,

the problem with ur code is that statement "PARAMETERS: f_path1 TYPE string." generates syntax error...n so further processing gets difficult as parameter cant be string and "selected_folder" is of string type...

btw i solved it using the function module :TMP_GUI_BROWSE_FOR_FOLDER...and in this "selected_folder" is of type C...so the problem gets solved...

thanks for ur help!!!

Former Member
0 Kudos

Hi,

Using the function module '/SAPDMC/LSM_F4_SERVER_FILE' will serve your purpose.

PARAMETERS: p_fname TYPE localfile.

CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
IMPORTING
      serverfile       = p_fname
EXCEPTIONS
      canceled_by_user = 1
      OTHERS = 2.

Edited by: sudipta86 on Jul 22, 2009 11:33 AM

Edited by: sudipta86 on Jul 22, 2009 11:34 AM

Former Member

Hi ,

use this

CALL METHOD cl_gui_frontend_services=>directory_browse

Please let me know if you still need any more help.

Thanks and regards,

Rajeshwar