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 WS_FILENAME_GET

Former Member
0 Kudos

i use this fm with a <b>parameter:</b> i choose the file by browse and i want that in the next time that i will enter the program i will get defualt the <b>last path</b> of my choosen

12 REPLIES 12

Former Member
0 Kudos

Hi,

The FM 'WS_FILENAME_GET' is flagged as obsolete in 4.7 version

Use Class

CL_GUI_FRONTEND_SERVICES

For saving:

cl_gui_frontend_services=>file_save_dialog

and for opening file

cl_gui_frontend_services=>file_open_dialog

sample code:

FORM f1003_f4_hlp_for_pc_file.

  DATA: li_filetable TYPE STANDARD TABLE OF file_table,
        lv_return TYPE i,
        lw_filetable TYPE file_table.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
     EXPORTING
       window_title            = 'Select file for download'
       default_extension       = '.txt'
*       DEFAULT_FILENAME        = '.txt'
*       file_filter             = '*.txt ,*.txt.'
       initial_directory       =  'C:'
     CHANGING
       file_table              = li_filetable
       rc                      = lv_return
     EXCEPTIONS
       file_open_dialog_failed = 1
       cntl_error              = 2
       error_no_gui            = 3
       OTHERS                  = 4
           .
  IF sy-subrc <> 0.
    MESSAGE e003 WITH text-015.
  ELSE.
    READ TABLE li_filetable INTO lw_filetable INDEX 1.
    p_fnam2 = lw_filetable-filename.
  ENDIF.

For 'WS_FILENAME_GET':

CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_FILENAME = 'xyz.TXT'
DEF_PATH = 'C:TEMP'
MASK = ', File,*.txt.'
MODE = '0'
TITLE = 'Save File As'
IMPORTING
FILENAME = FILENAME
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.

Regards,

Anjali

0 Kudos

hi Rani,

FM 'WS_FILENAME_GET' is flagged as obsolete in 4.7 version and in higher versions ... so as an alternative for that use <b>cl_gui_frontend_services=>file_save_dialog</b> for saving a file and <b>cl_gui_frontend_services=>file_open_dialog</b> for opening a file ...

Hope this Helps,

Santosh

0 Kudos

Rani do you want this to check for the last path you personally chose or the last path anyone using this program used?

I think you'll either have to do this via Local History on your GUI or saving information to a table (and I can't really see a return on storing it, unless it's a very vital part of the design).

Rgds

Rosie Brent

0 Kudos

i have problem becuase i want to save it in the desktop

and now we have xp next year we wil xp222222

so the path is diffrent

Former Member
0 Kudos

Hi Rani,

In one of the import parameters of WS_FILENAME_GET, you have DEF_PATH,which specifies the default path which will be shown when the dialog box opens. Also there is an output parameter FILENAME , which specifies the selected filename.

If you want your requirement to be satisfied , you have to set the DEF_PATH with the FILENAME value, so that when the dialog box opens, the previously selected folder will be shown.

Regards,

Sylendra.

0 Kudos

you say i can not have this in the next time

file : c/temp/temp.txt

0 Kudos

Hi,

It will work Rani:

SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.
PARAMETERS  p_fnam2 LIKE rlgrap-filename <b>memory id pid.</b>
SELECTION-SCREEN END OF BLOCK b4.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fnam2.

  DATA: li_filetable TYPE STANDARD TABLE OF file_table,
        lv_return TYPE i,
        lw_filetable TYPE file_table.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
     EXPORTING
       window_title            = 'Select file for download'
       default_extension       = '.txt'
*       DEFAULT_FILENAME        = '.txt'
*       file_filter             = '*.txt ,*.txt.'
       initial_directory       =  'C:'
     CHANGING
       file_table              = li_filetable
       rc                      = lv_return
     EXCEPTIONS
       file_open_dialog_failed = 1
       cntl_error              = 2
       error_no_gui            = 3
       OTHERS                  = 4
           .
  IF sy-subrc <> 0.
*    MESSAGE e003 WITH text-015.
  ELSE.
    READ TABLE li_filetable INTO lw_filetable INDEX 1.
    p_fnam2 = lw_filetable-filename.
  ENDIF.

END-OF-SELECTION.

  write :'hi'.

Execute this code and enter file name. Whn u excute it fresh the last file name will be there.

Regards,

Anjali

Former Member
0 Kudos

Hi,


REPORT ztest .

SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.
PARAMETERS  p_fnam2 LIKE rlgrap-filename <b>MEMORY ID pid.</b>
SELECTION-SCREEN END OF BLOCK b4.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fnam2.

data: filename type string.

  CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
      def_filename     = 'xyz.TXT'
      def_path         = 'C:TEMP'
      mask             = ', File,*.txt.'
      mode             = '0'
      title            = 'Save File As'
    IMPORTING
      filename         = filename
    EXCEPTIONS
      inv_winsys       = 1
      no_batch         = 2
      selection_cancel = 3
      selection_error  = 4
      OTHERS           = 5.

p_fnam2 = filename.

END-OF-SELECTION.

WRITE :'hi'.

Note: Please reward points once the problem is solved.

Regards,

Anjali

Former Member
0 Kudos

Hi Rani,

In newer versions, WS_FILENAME_GET will be considered as obsolete. So u can use CL_GUI_FRONTEND_SERVICES class methods like file_open_dialog.

Here is a sample program.

data: it_tab type filetable with header line,

gd_subrc type i.

tables: rlgrap.

parameters file_nam type rlgrap-filename .

data: user_act type i.

at selection-screen on value-request for file_nam.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

WINDOW_TITLE = 'select a file'

  • DEFAULT_EXTENSION =

DEFAULT_FILENAME = 'D:\sp\'

FILE_FILTER = '*.txt'

INITIAL_DIRECTORY = ''

  • MULTISELECTION = 'X'

  • WITH_ENCODING =

CHANGING

file_table = it_tab[]

rc = gd_subrc

USER_ACTION = user_act

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

if user_act = '0'.

loop at it_tab.

file_nam = it_tab-filename.

endloop.

endif.

You can set the default path as the value returned by the table it_tab so that everytime the function is executed , the previous folder is selected.

I suppose your query is satisfied.

Regards,

Sylendra.

Former Member
0 Kudos

hi rani,

p_fnam2 LIKE rlgrap-filename default 'C:\COMPQU.xls' MODIF ID D1.

like this if we give a default value to ur parameter then that will do if u want to maintain the same id all the way for ur program .

with the parametrs id that will be stored.

regards,

vikky.

Former Member
0 Kudos

Hi Rani,

SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.

PARAMETERS p_fnam2 LIKE rlgrap-filename .

SELECTION-SCREEN END OF BLOCK b4.

data: my_path type string.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fnam2.

import my_path from memory id 'text'.

DATA: li_filetable TYPE STANDARD TABLE OF file_table,

lv_return TYPE i,

lw_filetable TYPE file_table.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

window_title = 'FIle open'

default_extension = '.txt'

  • DEFAULT_FILENAME = '.txt'

  • file_filter = '*.txt'

initial_directory = my_path

CHANGING

file_table = li_filetable

rc = lv_return

EXCEPTIONS

file_open_dialog_failed = 1

cntl_error = 2

error_no_gui = 3

OTHERS = 4

.

IF sy-subrc <> 0.

  • MESSAGE e003 WITH text-015.

ELSE.

READ TABLE li_filetable INTO lw_filetable INDEX 1.

p_fnam2 = lw_filetable-filename.

my_path = lw_filetable-filename.

export my_path to memory id 'text1'.

ENDIF.

END-OF-SELECTION.

write :'hello'.

I think this satisfies your question.

Just check this code and tell us if ur requirement is not satisfied.

Regards,

Sylendra.

Former Member
0 Kudos

Hi Rani,

I suppose your new requirement is as follows.

When you click on the parameter search help, a "Save as" dialog box appears and you saves a file in a particular folder. Now you execute and come back to the program.

Again u execute the program. Now when u click on the search help, the "Save As " dialog box appears again , but this time the default directory(folder which shows immediately) should be the one you saved before.

If that is right, then here is the code.

REPORT ZJAYRA_FILEPROG1 .

SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.

PARAMETERS p_fnam2 LIKE rlgrap-filename .

SELECTION-SCREEN END OF BLOCK b4.

data: my_path type string.

data: file_name type string,

file_path type string,

file_full type string.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fnam2.

import my_path from memory id 'text'.

DATA: li_filetable TYPE STANDARD TABLE OF file_table,

lv_return TYPE i,

lw_filetable TYPE file_table.

CALL METHOD cl_gui_frontend_services=>file_save_dialog

EXPORTING

WINDOW_TITLE = 'Save As'

DEFAULT_EXTENSION = ' '

DEFAULT_FILE_NAME = ' '

  • FILE_FILTER =

INITIAL_DIRECTORY = my_path

  • WITH_ENCODING =

  • PROMPT_ON_OVERWRITE = 'X'

CHANGING

filename = file_name

path = file_path

fullpath = file_full

  • USER_ACTION =

  • FILE_ENCODING =

EXCEPTIONS

CNTL_ERROR = 1

ERROR_NO_GUI = 2

NOT_SUPPORTED_BY_GUI = 3

others = 4

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

p_fnam2 = file_full.

export file_full to memory id 'text1'.

END-OF-SELECTION.

write :'hello'.

Tell us if this doesn't satisfy your requirement.

Otherwise, close the thread by awarding points to helpful answers.

Regards,

Sylendra.