Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Open File Functionality

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.

Tags:
Former Member
Former Member replied

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

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question