• 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.

  • 相关阅读:
    在HTML网页中巧用URL
    技术不是第一位,商业模式是第一位[转帖]
    SQL Server日期计算
    Ms XmlDom 异步装载Xml文件
    陆游词全集
    陈慧娴 3 In 1 MV珍藏集
    下大雪啦
    用Asp+XmlHttp实现RssReader功能
    双绞线的标准接法
    巧把Hotmail邮箱2M轻易扩容到25M
  • 原文地址:https://www.cnblogs.com/elegantok/p/1318904.html
Copyright © 2020-2023  润新知