如果select后的字段与into table的内表中的字段数量一样,且table中的字段类型与数据库表中的一样,用select XX into table YYY的时候不会Dump,但字段类型的顺序要一样。
例如:
DATA: BEGIN OF wa_a,
bname TYPE xubname,
spdb TYPE xuspdb,
col1 TYPE xuspda,
END OF wa_a,
it_a LIKE TABLE OF wa_a
SELECT bname
spdb
spda
FROM usr01
INTO TABLE it_a
这样可以取到3个字段的值
DATA: BEGIN OF wa_a,
bname TYPE xubname,
spdb TYPE xuspdb,
col1 TYPE xuspda,
END OF wa_a,
it_a LIKE TABLE OF wa_a
SELECT bname
spdb
spda
FROM usr01
INTO CORRESPONDING FIELDS OF TABLE it_a
这样可以取到前两个字段的值
DATA: BEGIN OF wa_a,
bname TYPE xubname,
spdb TYPE xuspdb,
END OF wa_a,
it_a LIKE TABLE OF wa_a
SELECT bname
spdb
spda
FROM usr01
INTO TABLE it_a
这样程序就会DumpSORT IT_DATA BY BNAME INCLUDE OLE2INCL "定义OLE变量DATA: EXCEL TYPE OLE2_OBJECT, SHEET TYPE OLE2_OBJECT, CELL TYPE OLE2_OBJECT, WORKBOOK TYPE OLE2_OBJECT, XLSNAME TYPE STRING VALUE 'C:\sap_usr02xls', LINE TYPE I VALUE 0 "行号CREATE OBJECT EXCEL 'EXCELAPPLICATION'"启动ExcelIF SY-SUBRC NE 0 WRITE: / '启动Excel失败。' STOPENDIFCALL METHOD OF EXCEL 'WORKBOOKS' = WORKBOOKSET PROPERTY OF EXCEL 'VISIBLE' = 1 "使excel 可视SET PROPERTY OF EXCEL 'SHEETSINNEWWORKBOOK' = 1 "如果是读取excel文件中的内容 则是直接打开工作簿第一页CALL METHOD OF WORKBOOK 'ADD' "例如:CALL METHOD OF EXCEL 'WORKSHEETS' = SHEET EXPORTING #1 = 1LOOP AT IT_DATA INTO MY_DATA LINE = LINE + 1 "Excel 中行号从1开始 CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = LINE #2 = 1 "指定单元格, SET PROPERTY OF CELL 'VALUE' = MY_DATA-MANDT "写入值 CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = LINE #2 = 2 "指定单元格, SET PROPERTY OF CELL 'VALUE' = MY_DATA-BNAME "写入值 CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = LINE #2 = 3 "指定单元格, SET PROPERTY OF CELL 'VALUE' = MY_DATA-ERDAT "写入值 CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = LINE #2 = 4 "指定单元格, SET PROPERTY OF CELL 'VALUE' = MY_DATA-LTIME "写入值ENDLOOPGET PROPERTY OF EXCEL 'ACTIVESHEET' = SHEET "激活工作簿GET PROPERTY OF EXCEL 'ACTIVEWORKBOOK' = WORKBOOK "激活工作区CALL METHOD OF WORKBOOK 'SAVEAS' EXPORTING #1 = XLSNAME #2 = 1 "将excel文件保存CALL METHOD OF WORKBOOK 'CLOSE' "关闭工作区CALL METHOD OF EXCEL 'QUIT' "退出excelWRITE:/ XLSNAME,'DONE' "退出成功,输出doneFREE OBJECT SHEET "释放 *** 作FREE OBJECT WORKBOOKFREE OBJECT EXCEL1动态内表的创建,首先要定义动态结构,然后再根据定义的动态结构利用系统一个标准的method:”cl_ALV_table_create=>create_dynamic_table“生成动态内表。
2动态内表的赋值,遍历动态结构,获取指定的字段,然后给指定的字段赋值。
3动态内表的读取显示,与赋值相似,遍历动态结构,获取指定的字段,然后读取对应字段的值。
这种方式得确简单,但是对日项目中因为过分谨慎,any table这种定义方式是不可以的
首先界面是这样的
FORM DOWNLOAD_TEMPLATE
CREATE OBJECT G_APPL 'EXCELAPPLICATION'
SET PROPERTY OF G_APPL 'VISIBLE' = 0
CALL METHOD OF
G_APPL
'WORKBOOKS' = G_WORK
CALL METHOD OF
G_WORK
'Add' = G_WORK
GET PROPERTY OF G_APPL 'ActiveSheet' = G_ACTIVESHEET
SET PROPERTY OF G_ACTIVESHEET 'Name' = '工艺路线模板'
PERFORM FILL_CELL USING: 1 1 '物料编码' 27 1, "行,列,值,颜色,加粗
1 2 '工厂' 27 1,
1 3 '物料描述' 27 1,
1 4 '工序号' 27 1,
1 5 '工作中心' 27 1,
1 6 '控制码' 27 1,
1 7 '工序名称' 27 1,
1 8 '基本数量' 27 1,
1 9 '准备' 27 1,
1 10 '机器' 27 1,
1 11 '人工' 27 1,
"EXCEL文件另存为
CALL METHOD OF
G_WORK
'SAVEAS'
EXPORTING
#1 = P_FILE
"关闭文件
CALL METHOD OF
G_WORK
'close'
"退出EXCEL
CALL METHOD OF
G_APPL
'QUIT'
FREE OBJECT G_APPL
MESSAGE S000(ZPEOPLE) WITH '文件:' P_FILE ' 下载成功'
ENDFORM " DOWNLOAD_TEMPLATE
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)