[转帖]ABAP实践学习--将excel表读入ABAP内表

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.

 

你可能感兴趣的:([转帖]ABAP实践学习--将excel表读入ABAP内表)