Application Development and Automation 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: 
Read only

Open File Functionality

Former Member
0 Likes
848

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
788

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

5 REPLIES 5
Read only

Former Member
0 Likes
788

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.

Read only

Former Member
0 Likes
789

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

Read only

0 Likes
788

i have uploaded the file...i just want code for the pop-up

Read only

0 Likes
788

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.

Read only

Former Member
0 Likes
788

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.