标签:小数 自己 table code number line ber standard sap
01. 在SE38模块,创建一个程序
02.ABAP代码如下:
*&---------------------------------------------------------------------* *& Report Z_TIANPAN_20190716_HELLO *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* * 此条为系统自动生成,为程序名 REPORT z_tianpan_20190716_hello 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, "字段名 keyflag(4), "KEY rollname(12), "数据元素 datatype(8), "数据类型 leng(6), "长度 decimals(6), "小数位 fieldtext LIKE dfies-fieldtext, "字段简短描述 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 ‘G:\‘. "默认存放地址 SELECTION-SCREEN END OF BLOCK blk1. START-OF-SELECTION. PERFORM read_data."从表中读取数据 END-OF-SELECTION. PERFORM write_data."输出数据 *--从表中读取数据---------------------------------------- FORM read_data . *****CALL FUNCTION***** CALL FUNCTION ‘DDIF_FIELDINFO_GET‘ EXPORTING tabname = table "自己输的表名 fieldname = field "字段 langu = sy-langu "语言码 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. *将内表数据下载到本地,类型为Excel CONCATENATE p_dnfile table ‘.xls‘ INTO g_file. CALL FUNCTION ‘WS_DOWNLOAD‘ EXPORTING filename = g_file filetype = ‘DAT‘ TABLES data_tab = itab1. "被下载的内表 ENDFORM. *--输出数据---------------------------------------- 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
03.代码执行一下
04.文件已经被保存了,很完美
原创不易,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦,谢谢。
116、SAP导出表结构并保存到Excel,方便写代码时复制粘贴
标签:小数 自己 table code number line ber standard sap
原文地址:https://www.cnblogs.com/tianpan2019/p/12888597.html