导出SAP表结构到EXCEl
將SE11中看到的數據表結構,制作成EXCEL文件,以便查閱。CPOY的話得一個字段一個元素的COPY再一個個粘過去,不僅麻煩,如果一個結構有上百個元素,工作量也是很大的。
研究整理了一下各位達人的程序,寫了一個新的導出程序。本程序只需在選擇界面輸入要導出的結構名及保存路徑,就在該路徑下生成一個以該結構命名的EXCEL文件。也可以指定輸出結構的單獨字段。代碼如下:
REPORT? YTABLE 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
總結
以上是生活随笔為你收集整理的导出SAP表结构到EXCEl的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: TC(Table Control)自定义
- 下一篇: MR21批量修改物料价格-BDC