‎2008 Sep 11 1:07 PM
Hi,
I have a file is located on local disk, what is the FM that I can use to upload it into the SAP system, I want a Pop Up window so that i can browse through to upload the file and store the name of the file in a variable in the SAP Code.
Code Snippet Would Help Me.
Thanks
Harsha Ch.
‎2008 Sep 11 1:10 PM
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_rfname LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_rfname.
PERFORM get_desktop_file_help.
START-OF-SELECTION.
PERFORM upload_file_from_desktop CHANGING g_error.
----
Form get_desktop_file_help
----
FORM get_desktop_file_help.
DATA : v_file LIKE rlgrap-filename.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
program_name = syst-repid
dynpro_number = syst-dynnr
field_name = 'P_RFNAME'
CHANGING
file_name = v_file
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE i368(00) WITH 'Enter Correct File'.
STOP.
ELSE.
MOVE : v_file TO p_rfname.
ENDIF.
ENDFORM. " get_desktop_file_help
----
Form upload_file_from_desktop
----
FORM upload_file_from_desktop CHANGING p_error.
IF NOT sy-batch IS INITIAL.
MESSAGE e368(00) WITH 'Files can only be uploaded'
'in foreground'.
ELSE.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p_rfname
filetype = 'DAT'
TABLES
data_tab = it_data
EXCEPTIONS
conversion_error = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
OTHERS = 7.
IF sy-subrc NE 0.
MESSAGE i368(00) WITH 'Error while reading data from file'.
MOVE : 'X' TO p_error.
ENDIF.
ENDIF.
ENDFORM. "upload_file_from_desktop
‎2008 Sep 11 1:09 PM
use FM GUI_UPLOAD to upload the file from presentation layer
and
PARAMETER: pfile LIKE rlgrap-filename OBLIGATORY.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
FIELD_NAME = ' '
IMPORTING
file_name = pfile.
‎2008 Sep 11 1:10 PM
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_rfname LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_rfname.
PERFORM get_desktop_file_help.
START-OF-SELECTION.
PERFORM upload_file_from_desktop CHANGING g_error.
----
Form get_desktop_file_help
----
FORM get_desktop_file_help.
DATA : v_file LIKE rlgrap-filename.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
program_name = syst-repid
dynpro_number = syst-dynnr
field_name = 'P_RFNAME'
CHANGING
file_name = v_file
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE i368(00) WITH 'Enter Correct File'.
STOP.
ELSE.
MOVE : v_file TO p_rfname.
ENDIF.
ENDFORM. " get_desktop_file_help
----
Form upload_file_from_desktop
----
FORM upload_file_from_desktop CHANGING p_error.
IF NOT sy-batch IS INITIAL.
MESSAGE e368(00) WITH 'Files can only be uploaded'
'in foreground'.
ELSE.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p_rfname
filetype = 'DAT'
TABLES
data_tab = it_data
EXCEPTIONS
conversion_error = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
OTHERS = 7.
IF sy-subrc NE 0.
MESSAGE i368(00) WITH 'Error while reading data from file'.
MOVE : 'X' TO p_error.
ENDIF.
ENDIF.
ENDFORM. "upload_file_from_desktop
‎2008 Sep 11 1:11 PM
‎2008 Sep 11 1:21 PM
SELECTION-SCREEN BEGIN OF BLOCK A2 WITH FRAME TITLE text-000.
PARAMETERS: filename LIKE RLGRAP-FILENAME OBLIGATORY
DEFAULT 'c:\sapmoveA1.txt'.
SELECTION-SCREEN END OF BLOCK A2.
write this under AT selection-screen event
AT SELECTION-SCREEN on value-request for filename.
To select the file to upload
call function 'WS_FILENAME_GET'
EXPORTING
def_filename = ' '
def_path = 'C:\'
mask = ',.,..'
mode = 'O'
title = 'Choose A File To Upload - AMEX'
IMPORTING
filename = filename
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
others = 5.
‎2008 Sep 11 1:12 PM
Hi,
for navigating to the folder in your system the following code snippet will help you
*Get the filename from user
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Title'
default_extension = 'XLS'
file_filter = cl_gui_frontend_services=>filetype_excel
CHANGING
filename = lv_filename
path = lv_path
fullpath = lv_fullpath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.