Quickly perform file uploads using the following code.
types: begin of ts_upload_file,
filename type string,
data type xstring,
end of ts_upload_file.
data : lv_desktop_directory type string,
lv_rc type i,
lt_selected_file_list type filetable,
lt_bin_file type soli_tab,
lv_length type i,
ls_upload_file type ts_upload_file,
lt_upload_files type standard table of ts_upload_file.
cl_gui_frontend_services=>get_desktop_directory(
changing
desktop_directory = lv_desktop_directory
).
cl_gui_frontend_services=>file_open_dialog(
exporting
initial_directory = lv_desktop_directory
window_title = 'Select Files'
multiselection = abap_true
file_filter = cl_gui_frontend_services=>filetype_excel
changing
rc = lv_rc " file count or if -1 error
file_table = lt_selected_file_list
).
loop at lt_selected_file_list into data(ls_selected_file).
call method cl_gui_frontend_services=>gui_upload
exporting
filename = conv string( ls_selected_file-filename )
filetype = 'BIN'
importing
filelength = lv_length
changing
data_tab = lt_bin_file.
data(lv_filex) = cl_bcs_convert=>raw_to_xstring( lt_bin_file ).
split ls_selected_file-filename at '\' into table data(lt_split).
data(lv_filename) = value #( lt_split[ lines( lt_split ) ] optional ).
ls_upload_file-filename = lv_filename.
ls_upload_file-data = lv_filex.
append ls_upload_file to lt_upload_files.
endloop.