zoukankan      html  css  js  c++  java
  • SAP 將表或結構導出到Excel

    *&---------------------------------------------------------------------*
    *& Report ZTEXT
    *&---------------------------------------------------------------------*
    *&
    *&---------------------------------------------------------------------*
    REPORT ZTEXT no standard page heading
                     message-id y2
                     line-size  200
                     line-count 65 .
     
    tables: dfies, x030l,rlgrap.
     
    data: begin of itab occurs 0.
            include structure dfies.
    data: end of itab.
    data: g_file like rlgrap-filename.   "下载保存路径
    data:begin of itab1 occurs 0,
         fieldname like dfies-fieldname,  "Fieldname
         keyflag(4),    "KEY
         rollname(12),   "Data Element
         datatype(8),   "Data Type
         leng(6),       "Length
         decimals(6),   "Decimal Place
         fieldtext like dfies-fieldtext,  "Short Description
    end of itab1.
     
    *********************定义屏幕
    selection-screen begin of block blk1 with frame title text-001.
    parameters:table type ddobjname default 'VBAK',
               field type dfies-fieldname,
               p_dnfile like rlgrap-filename default 'D:/'.
    selection-screen end of block blk1.
     
    start-of-selection.
      perform read_data."从表中读取数据
     
    end-of-selection.
      perform write_data."输出数据
    *&---------------------------------------------------------------------*
    *&      Form  read_data
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    form read_data .
    *****CALL FUNCTION*****
      call function 'DDIF_FIELDINFO_GET'
        exporting
          tabname        = table
          fieldname      = field
          langu          = sy-langu "这个可以改成别的语言,For Short Descriptions
        tables
          dfies_tab      = itab " like table dfies.
        exceptions
          not_found      = 1
          internal_error = 2
          others         = 3.
      if sy-subrc <> 0.
    *    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    *           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
     
      itab1-fieldname = '字段'.  "Fieldname
      itab1-keyflag = '主键'.    "KEY
      itab1-rollname = '数据元素'.   "Data Element
      itab1-datatype = '数据类型'.   "Data Type
      itab1-leng = '长度'.       "Length
      itab1-decimals = '小数位'.  "Decimal Place
      itab1-fieldtext = '短文本'.  "Short Description
      append itab1.
      clear itab1.
     
      loop at itab.
        itab1-fieldname = itab-fieldname.
        itab1-keyflag = itab-keyflag.
        itab1-rollname = itab-rollname.
        itab1-datatype = itab-datatype.
        itab1-leng = itab-leng.
        itab1-decimals = itab-decimals.
        itab1-fieldtext = itab-fieldtext.
        append itab1.
        clear itab1.
      endloop.
     
      concatenate p_dnfile table '.xls' into g_file. "这里为将内表数据下载到本地D盘,名字为表名,类型为EXCEL
      call function 'WS_DOWNLOAD'
        exporting
          filename = g_file
          filetype = 'DAT'
        tables
          data_tab = itab1.  "被下载的内表
     
    endform.                    " read_data
    *&---------------------------------------------------------------------*
    *&      Form  write_data
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    form write_data .
      loop at itab1.
        write:/ itab1-fieldname,  "Fieldname
                itab1-keyflag,    "KEY
                itab1-rollname,   "Data Element
                itab1-datatype,   "Data Type
                itab1-leng,       "Length
                itab1-decimals,   "Decimal Place
                itab1-fieldtext.  "Short Description
      endloop.
    endform.                    " write_data

  • 相关阅读:
    BZOJ1409 : Password
    BZOJ2862 : 分糖果
    BZOJ2093 : [Poi2010]Frog
    BZOJ2506 : calc
    BZOJ3290 : Theresa与数据结构
    BZOJ1397 : Ural 1486 Equal squares
    BZOJ2789 : [Poi2012]Letters
    BZOJ3417 : Poi2013 Tales of seafaring
    BZOJ3251 : 树上三角形
    BZOJ3262 : 陌上花开
  • 原文地址:https://www.cnblogs.com/coderfarmer/p/13424444.html
Copyright © 2011-2022 走看看