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: 

Filedialog / Download / Upload

Former Member
0 Kudos

Hi all,

i have a couple of files which are located on my local Desktop.

Now i want to import this files (10) to internal tabels.

I (or the User) don't know where the files are located on the Desktop.

I have a Selection Screen with a field called (lv_path).

Now i want something similar to WS_FILENAME_GET that allows me to locate the path where the files are stored.

Any idea ?

Henning

8 REPLIES 8

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I assume that this is what you want. You want a filename field on the selection screen. When the user wants F4 value help - you want a file open dialog to help them find their files. The following should do just that.

----


  • SELECTION-SCREEN *

----


parameter: ifile type file_table-filename obligatory.

----


  • SELECTION SCREEN - VALUE REQUES FOR FILENAME *

----


at selection-screen

on value-request for ifile.

data: window_title type string.

data: path type string.

data: filename type string.

data: fullpath type string.

move 'Source Data File'(001) to window_title.

call method cl_gui_frontend_services=>file_save_dialog

exporting

window_title = window_title

changing

filename = filename

path = path

fullpath = fullpath

exceptions

cntl_error = 1

error_no_gui = 2

others = 3.

if sy-subrc <> 0.

else.

move fullpath to ifile.

endif.

This would do a file-save dialog. If you want a file-open dialog the following example would work:

----


  • SELECTION SCREEN - VALUE REQUES FOR FILENAME

----


at selection-screen

on value-request for ofile.

data: window_title type string.

move 'Destination Data File'(002) to window_title.

call method cl_gui_frontend_services=>file_open_dialog

exporting

window_title = window_title

  • DEFAULT_EXTENSION =

  • DEFAULT_FILENAME =

  • FILE_FILTER =

  • INITIAL_DIRECTORY =

  • MULTISELECTION =

changing

file_table = ifile_tab

rc = rc

  • USER_ACTION =

exceptions

file_open_dialog_failed = 1

cntl_error = 2

error_no_gui = 3

others = 4.

if sy-subrc <> 0 or rc < 1.

else.

loop at ifile_tab into ifile_tab_line.

move ifile_tab_line-filename to ifile.

endloop.

endif.

0 Kudos

Hi

thx for the reply.

But the problem is that when i use this method i allways have to give or choose a filename.

I only want to select the directory name (click or double click on the directory name and ok). Not the filename.

I only need to know in which directory the files are located. I don't want to pick a filename for this and than exclude the path of the file.

Henning

0 Kudos

No problem. What you need is in the same class, CL_GUI_FRONTEND_SERVICES, but a different method: DIRECTORY_BROWSE. It works very similar and does exactly what I believe you want it to do.

0 Kudos

Thx for you help.

It works.

Henning

Former Member
0 Kudos

hi,

try this

parameters: lv_path LIKE RLGRAP-FILENAME.

at selection-screen on value-request for p_file.

Perform get_filename.

form get_filename.

call function 'F4_FILENAME'

  • EXPORTING

  • PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = mara-matnr

IMPORTING

FILE_NAME = p_file.

endform. " get_filename

Former Member
0 Kudos

Is there a similar way to pop-up unix directories too?

-Bala

0 Kudos

By UNIX I assume that you mean directories on your SAP application server. I don't know of anything quite as nice as what is available for the front-end tools. However you might want to check out the function module EPS_GET_DIRECTORY_LISTING and other function modules in the same function group. By default this only returns files. I copied the function module and made a few changes to return both files and directories. With this you could code a pop-up of your own. I also made some of the variables for files and directories larger. The following is my copy of EPS_GET_DIRECTORY_LISTING from a 46C system.

function z_e_get_directory_listing.

*"----


""Local interface:

*" IMPORTING

*" VALUE(DIR_NAME) TYPE ZZ_UNIX_DIR_NAME

*" VALUE(FILE_MASK) LIKE EPSF-EPSFILNAM DEFAULT SPACE

*" EXPORTING

*" VALUE(DIR_NAME1) LIKE EPSF-EPSDIRNAM

*" VALUE(FILE_COUNTER) LIKE EPSF-EPSFILSIZ

*" VALUE(ERROR_COUNTER) LIKE EPSF-EPSFILSIZ

*" TABLES

*" DIR_LIST STRUCTURE ZES_EPSFILI

*" EXCEPTIONS

*" INVALID_EPS_SUBDIR

*" SAPGPARAM_FAILED

*" BUILD_DIRECTORY_FAILED

*" NO_AUTHORIZATION

*" READ_DIRECTORY_FAILED

*" TOO_MANY_READ_ERRORS

*" EMPTY_DIRECTORY_LIST

*"----


data: begin of file,

dirname(175) type c, "name of directory. (possibly truncated.)

name(175) type c, " name of entry. (possibly truncated.)

type(10) type c, " type of entry.

len(8) type p, " length in bytes.

owner(8) type c, " owner of the entry.

mtime(6) type p, " last modification date, seconds since 1970

mode(9) type c, " like "rwx-r-x--x": protection mode.

errno(3) type c,

errmsg(40) type c,

end of file.

data: lv_eps_subdir like epsf-epssubdir.

  • expand EPS subdirectory names

if dir_name = space. " assume files in EPS/in

raise invalid_eps_subdir.

endif.

if dir_name = gc_eps_in or " get full directory name

dir_name = gc_eps_out or

dir_name = gc_eps_log or

dir_name(4) = gc_trans_dir.

lv_eps_subdir = dir_name.

call function 'EPS_GET_DIRECTORY_PATH'

exporting

eps_subdir = lv_eps_subdir

dir_name = dir_name

importing

dir_name = dir_name

exceptions

invalid_eps_subdir = 01

sapgparam_failed = 02

build_directory_failed = 03.

case sy-subrc.

when 01.

raise invalid_eps_subdir.

when 02.

raise sapgparam_failed.

when 03.

raise build_directory_failed.

endcase.

endif.

  • get directory listing

call 'C_DIR_READ_FINISH' " just to be sure

id 'ERRNO' field file-errno

id 'ERRMSG' field file-errmsg.

call 'C_DIR_READ_START'

id 'DIR' field dir_name

id 'FILE' field file_mask

id 'ERRNO' field file-errno

id 'ERRMSG' field file-errmsg.

if sy-subrc <> 0.

raise read_directory_failed.

endif.

refresh dir_list.

clear file_counter.

clear error_counter.

do.

clear file.

clear dir_list.

call 'C_DIR_READ_NEXT'

id 'TYPE' field file-type

id 'NAME' field file-name

id 'LEN' field file-len

id 'OWNER' field file-owner

id 'MTIME' field file-mtime

id 'MODE' field file-mode

id 'ERRNO' field file-errno

id 'ERRMSG' field file-errmsg.

dir_list-size = file-len.

dir_list-name = file-name.

if sy-subrc = 0.

if file-type(1) = 'f' or " regular file

file-type(1) = 'F' or

file-type(1) = 'd'.

add 1 to file_counter.

if file-type(1) = 'f'.

dir_list-rc = 0.

else.

dir_list-rc = 1.

endif.

append dir_list.

endif.

elseif sy-subrc = 1.

exit.

else.

if error_counter > gc_1000.

call 'C_DIR_READ_FINISH'

id 'ERRNO' field file-errno

id 'ERRMSG' field file-errmsg.

raise too_many_read_errors.

endif.

add 1 to error_counter.

dir_list-rc = 18.

append dir_list.

endif.

enddo.

call 'C_DIR_READ_FINISH'

id 'ERRNO' field file-errno

id 'ERRMSG' field file-errmsg.

if file_counter > 0.

sort dir_list by name ascending.

else.

raise empty_directory_list.

endif.

endfunction.

0 Kudos

Hello,

This function module seems to work with the aplication server's files.

/SAPDMC/LSM_F4_SERVER_FILE

I am using a WebAS 6.40.

Regards,

Vasco

Message was edited by: Vasco Dionisio