Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 2806

Re: Sample code for upload files -

$
0
0

Please try searching SCN before posting, i am sure you will find many many examples online.

 

Anyways, try as below

  DATA: lv_window_title type string,
   lt_file_path TYPE filetable,

  lv_rc               TYPE i.


SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS p_file TYPE localfile.
SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
   lv_window_title = 'Open Dialog'.
   CALL METHOD cl_gui_frontend_services=>file_open_dialog
     EXPORTING
       window_title            = lv_window_title

        initial_directory       = 'C:\Users\test\Desktop'
     CHANGING
       file_table              = lt_file_path
       rc                      = lv_rc
     EXCEPTIONS
       file_open_dialog_failed = 1
       cntl_error              = 2
       error_no_gui            = 3
       not_supported_by_gui    = 4
       OTHERS                  = 5.

   IF lv_rc <> - 1 AND sy-subrc = 0.
     READ TABLE lt_file_path INTO ls_file_path INDEX 1.
     p_file = ls_file_path-filename.
   ENDIF.


  START-OF-SELECTION.

    TYPES: BEGIN OF lty_tab,
            line(1200) TYPE c,
          END OF lty_tab.

   DATA: ls_tab TYPE lty_tab.
   DATA: lt_tab TYPE TABLE OF lty_tab.
   DATA: ls_data TYPE gty_data.
   DATA: lv_filename TYPE string.

   lv_filename = p_file.
   CALL METHOD cl_gui_frontend_services=>gui_upload
     EXPORTING
       filename            = lv_filename
       filetype            = 'ASC'
       has_field_separator = abap_true
     CHANGING
       data_tab            = lt_tab
     EXCEPTIONS
       file_open_error     = 1
       file_read_error     = 2
       invalid_type        = 3
       no_batch            = 4
       unknown_error       = 5
       OTHERS              = 6.


Viewing all articles
Browse latest Browse all 2806

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>