Upload & Download internal table to excel

*&---------------------------------------------------------------------*

*& Report  Z_BARRY_UPLOAD_EXCEL

*&

*&---------------------------------------------------------------------*

*& 上传Excel文件到SAP内表

*& 除此方法,还可以使用FM: ALSM_EXCEL_TO_INTERNAL_TABLE

*&---------------------------------------------------------------------*

REPORT  z_barry_upload_excel.

TYPE-POOLS: truxs.

TYPES: BEGIN OF t_datatab,

      col1(30)    TYPE c,

      col2(30)    TYPE c,

      col3(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.

PARAMETERS: p_file TYPE  rlgrap-filename.

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.

  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.

  LOOP AT it_datatab INTO wa_datatab.

    WRITE:/ wa_datatab-col1,

            wa_datatab-col2,

            wa_datatab-col3.

  ENDLOOP.

 

如果有Excel内Cell内容过长情况,请参考:

http://blog.chinaunix.net/u1/40527/showart_1003904.html

 

 

以Excel格式下载内表到本机

**************

Report z_export_excel.

 

PARAMETERS: p_file LIKE rlgrap-filename DEFAULT 'C:\test4.xls'.

DATA: t100_lines TYPE STANDARD TABLE OF t001 WITH DEFAULT KEY.

 

SELECT * FROM t001 INTO TABLE t100_lines.

CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'

     EXPORTING

          i_filename     = p_file

     TABLES

          i_tab_sap_data = t100_lines.

 

posted @ 2008-10-24 16:45  elegant  阅读(776)  评论(0编辑  收藏  举报