Upload file excel to internal table SAP

here’s a piece of code to upload file excel to sap.

TYPE-POOLS: truxs.
DATA: BEGIN OF t_data OCCURS 0,
        name(30),
      END OF t_data.

DATA: t_raw TYPE truxs_t_text_data.

PARAMETERS: p_fname LIKE rlgrap-filename OBLIGATORY.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
  PERFORM f_get_filename.

START-OF-SELECTION.
  PERFORM f_upload_excel TABLES t_data USING p_fname.

  LOOP AT t_data.
    WRITE /: t_data-name.
  ENDLOOP.

*&---------------------------------------------------------------------*
*&      Form  F_GET_FILENAME
*&---------------------------------------------------------------------*
FORM f_get_filename .
  DATA: ld_rc TYPE i,
        lt_filetable TYPE filetable,
        lwa_filetable TYPE LINE OF filetable.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    CHANGING
      file_table = lt_filetable
      rc         = ld_rc.

  IF sy-subrc = 0.
    READ TABLE lt_filetable INTO lwa_filetable INDEX 1.
    IF sy-subrc = 0 .
      p_fname = lwa_filetable-filename .
    ENDIF.
  ENDIF.

ENDFORM.                    " F_GET_FILENAME

*&---------------------------------------------------------------------*
*&      Form  F_UPLOAD_EXCEL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_P_FNAME  text
*      -->P_T_DATA  text
*----------------------------------------------------------------------*
FORM f_upload_excel TABLES ft_data STRUCTURE t_data
                    USING  fu_fname LIKE rlgrap-filename.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR
*     I_LINE_HEADER
      i_tab_raw_data       = t_raw
      i_filename           = fu_fname
    TABLES
      i_tab_converted_data = ft_data[]
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.

ENDFORM.                    " F_UPLOAD_EXCEL

note.
format file dalam bentuk .xls (ms.excel 97-2003). Bila dalam bentuk .xlsx (ms. excel 2007-higher) makan akan muncul pop up message untuk verifikasi bahwa format file adalah benar.

Advertisements

3 comments

  1. Also excel-2003 format is throwing error while 2007 excel format is getting uploaded through presentation server

    • Hi Viviek,

      Thanks for stopping by.
      The format that I tried only M.O. Excel 97-2003 Worksheet & M.O. Excell Worksheet (excel 2007).
      I havent tried for Excel 1997 or 2003 since my excel didnt provide for those excel format.

      But thanks for your information.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s