FORM f_download_sample_file .
  DATA : lv_fname TYPE string.
  DATA : lv_file_name TYPE string.
  DATA : lv_i TYPE i ,
         lv_path TYPE string,
         lv_fullpath TYPE string.

  DATA : BEGIN OF lt_samp_line OCCURS 0,
       field01 TYPE char40,
       field02 TYPE char40,
       field03 TYPE char40,
       field04 TYPE char40,
       field05 TYPE char40,
       field06 TYPE char40,
       field07 TYPE char40,
       field08 TYPE char40,
       field09 TYPE char40,
       field10 TYPE char40,
       field11 TYPE char40,
       field12 TYPE char40,
       field13 TYPE char40,
       field14 TYPE char40,
       field15 TYPE char40,
       field16 TYPE char40,
       field17 TYPE char40,
       field18 TYPE char40,
    END OF lt_samp_line.

*Bu tablo excelimiz 18 alanlı olduğunu belirtiyor.
*Burada bu methodu çağırarak user'a uygun yer seçtirtiyoruz.
  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
      window_title         = 'Select path..'
      default_extension    = '.XLS'
      default_file_name    = 'Customer-material_info_file'
    CHANGING
      filename             = lv_fname
      path                 = lv_path
      fullpath             = lv_fullpath
          .
*Eğer uygun seçilmişse

  IF lv_fname NE space.

    lt_samp_line-field01 = text-k01.
    APPEND lt_samp_line.
    lt_samp_line-field01 = text-k02.
    APPEND lt_samp_line.

    lt_samp_line-field01 = text-004.
    lt_samp_line-field02 = text-005.
    lt_samp_line-field03 = text-006.
    lt_samp_line-field04 = text-007.
    lt_samp_line-field05 = text-009.
    lt_samp_line-field06 = text-008.
    lt_samp_line-field07 = text-010.
    lt_samp_line-field08 = text-011.
    lt_samp_line-field09 = text-012.
    lt_samp_line-field10 = text-013.
    lt_samp_line-field11 = text-014.
    lt_samp_line-field12 = text-015.
    lt_samp_line-field13 = text-016.
    lt_samp_line-field14 = text-017.
    lt_samp_line-field15 = text-018.
    lt_samp_line-field16 = text-019.
    lt_samp_line-field17 = text-020.
    lt_samp_line-field18 = text-021.
    APPEND lt_samp_line.

CALL METHOD cl_gui_frontend_services=>gui_download
      EXPORTING
        filename                = lv_fname
        write_field_separator   = 'X'
      CHANGING
        data_tab                = lt_samp_line[]
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        not_supported_by_gui    = 22
        error_no_gui            = 23
        OTHERS                  = 24.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDIF.


ENDFORM.




Serkan AKKAVAK
Computer Engineer
ABAP Developer & SAP S/4 HANA Logistics Team Lead
Contact : serkurumsal@yandex.com