REPORT  ZEXCELFILEUPLOAD.
TYPE-POOLS: truxs.

type-pools : slis.
data:   it_fieldcat type slis_t_fieldcat_alv,
        lt_top_of_page type slis_t_listheader,
        ls_layout      type slis_layout_alv,
        gt_events      type slis_t_event.

data :  wa_fieldcat like line of it_fieldcat.

PARAMETERS: p_file TYPE  rlgrap-filename.

TYPES: BEGIN OF t_datatab,
      col1(30)    TYPE c,
      col2(30)    TYPE c,
      col3(30)    TYPE c,
      col4(30)    TYPE c,
      END OF t_datatab.
DATA: it_datatab type standard table of t_datatab,
      wa_datatab type t_datatab.

DATA: it_raw TYPE truxs_t_text_data.

* At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = p_file.


***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR        =
      i_line_header            =  'X'
      i_tab_raw_data           =  it_raw       " WORK TABLE
      i_filename               =  p_file
    TABLES
      i_tab_converted_data     = it_datatab[]    "ACTUAL DATA
   EXCEPTIONS
      conversion_failed        = 1
      OTHERS                   = 2.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


***********************************************************************
* END-OF-SELECTION.
END-OF-SELECTION.
*  LOOP AT it_datatab INTO wa_datatab.
*    WRITE:/ wa_datatab-col1,
*            wa_datatab-col2,
*            wa_datatab-col3.
*  ENDLOOP.


  wa_fieldcat-fieldname = 'COL1'.
  wa_fieldcat-ref_tabname = 'IT_DATATAB'.
  wa_fieldcat-seltext_l = 'NAME'.
  wa_fieldcat-outputlen = 20.
  wa_fieldcat-col_pos     = '1'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-fieldname = 'COL2'.
  wa_fieldcat-ref_tabname = 'IT_DATATAB'.
  wa_fieldcat-seltext_l = 'ADDRESS'.
  wa_fieldcat-outputlen = 20.
  wa_fieldcat-col_pos     = '2'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-fieldname = 'COL3'.
  wa_fieldcat-ref_tabname = 'IT_DATATAB'.
  wa_fieldcat-seltext_l = 'PHONE'.
  wa_fieldcat-outputlen = 20.
  wa_fieldcat-col_pos     = '3'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-fieldname = 'COL4'.
  wa_fieldcat-ref_tabname = 'IT_DATATAB'.
  wa_fieldcat-seltext_l = 'EMAIL'.
  wa_fieldcat-outputlen = 20.
  wa_fieldcat-col_pos     = '4'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  clear wa_fieldcat.

  call function 'REUSE_ALV_GRID_DISPLAY'

  exporting
    i_callback_program                = sy-cprog
    is_layout                         = ls_layout
    it_fieldcat                       = it_fieldcat[]

   it_events                         = gt_events[]
   tables
     t_outtab                          = it_datatab[]
 exceptions
  program_error                     = 1
  others                            = 2
           .
  if sy-subrc <> 0.

  endif.



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