Upload excel file 到 INTERNAL TABLE 的方法

qiujun發表於2007-07-23

FORM upload_data .
DATA:w_tab LIKE it_excel.
DATA:lt_excel TYPE TABLE OF alsmex_tabline WITH HEADER LINE.
DATA:l_tabix1 LIKE sy-tabix.

FIELD-SYMBOLS: TYPE ANY.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = 1
i_begin_row = 2
i_end_col = 16
i_end_row = 5000
TABLES
intern = lt_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE s398 WITH 'Error occurs when upload Excel file!'.
STOP.
ENDIF.

*&SORT lt_intern BY row col.
LOOP AT lt_excel.
AT NEW row.
l_tabix1 = sy-tabix.
ENDAT.

AT END OF row.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE w_tab TO .
IF sy-subrc = 0.
READ TABLE lt_excel INDEX l_tabix1.
IF sy-subrc = 0 AND lt_excel-col = sy-index.
TRANSLATE lt_excel-value TO UPPER CASE.
= lt_excel-value.
ADD 1 TO l_tabix1.
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDDO.
APPEND w_tab TO it_excel.
CLEAR w_tab.
ENDAT.
ENDLOOP.
ENDFORM. " upload_data

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90072/viewspace-927534/,如需轉載,請註明出處,否則將追究法律責任。

相關文章