1. 程式人生 > >[轉帖]ABAP實踐學習--ABAP中將SAP資料按格式儲存到EXCEL(OLE)

[轉帖]ABAP實踐學習--ABAP中將SAP資料按格式儲存到EXCEL(OLE)

REPORT YTEST015 .
*定義讀入EXCEL的內表,ABAP本身已經定義格式
DATA:BEGIN OF IEXCEL OCCURS 0.
     INCLUDE STRUCTURE ALSMEX_TABLINE.
DATA:END OF IEXCEL.
*輸入檔名引數
PARAMETERS: FN1 LIKE RLGRAP-FILENAME MEMORY ID M01.
*從已知檔名讀入內表,限100列1000行
CALL FUNCTION ’ALSM_EXCEL_TO_INTERNAL_TABLE’
 EXPORTING
  FILENAME = FN1
  I_BEGIN_COL = 1
  I_BEGIN_ROW = 1
  I_END_COL = 1000
  I_END_ROW = 1000
TABLES
  INTERN = IEXCEL
 EXCEPTIONS
  INCONSISTENT_PARAMETERS = 1
  UPLOAD_OLE = 2
  OTHERS = 3.
 
 IF SY-SUBRC <> 0.
   WRITE:/ ’讀入檔案錯誤!’,fn1.
 ELSE.
*迴圈讀取內表並列印
LOOP AT IEXCEL.
  WRITE IEXCEL-VALUE(2).
  AT END OF ROW.
  WRITE:/ .
  ENDAT.
ENDLOOP.
ENDIF.