主要涉及到一个函数的使用:CALL FUNCTION 'WS_EXCEL'
但目前有一问题还未解决,即,使用此函数调用后,产生一个Excel,但如果你不关闭此Excel,并再次运行你的程序,再次调用此函数时,系统就会报错,此问题暂时还不知如何解决。也就是调用一次后,必须关闭其打开的Excel, 然后才能再次调用,否则就出错。或者称为:不可连续两次调用。
实例如下:
FORM output_excel .
*" for testing
if chk_Dtl eq 'X'.
CLEAR out_excel[].
out_excel-field01 = 'Company code'.
out_excel-field02 = 'Employee no'.
out_excel-field03 = 'Eligible (Y/N)'.
out_excel-field04 = 'Rating'.
out_excel-field05 = 'Salary Increase %'.
append out_excel.
loop at it_detail.
out_excel-field01 = it_detail-bukrs.
out_excel-field02 = it_detail-pernr.
out_excel-field03 = it_detail-eligible.
out_excel-field04 = it_detail-rating.
out_excel-field05 = it_detail-percentage.
append out_excel.
clear out_excel.
endloop.
CALL FUNCTION 'WS_EXCEL'
EXPORTING
FILENAME = 'd:/emprating.xls'
TABLES
DATA = out_excel.
endif.
ENDFORM. " output_excel