REPORT ZOYM_01_EXCEL_TO_ITAB.
TYPES: BEGIN OF T_DATATAB ,
F1(3) TYPE C,
F2(8) TYPE C,
F3(8) TYPE C,
F4(5) TYPE C,
F5(5) TYPE C,
F6(5) TYPE C,
F7(15) TYPE C,
F8(20) TYPE C,
F9(4) TYPE C,
F10(6) TYPE C,
F11(5) TYPE C,
F12(8) TYPE C,
END OF T_DATATAB.
DATA: IT_DATATAB TYPE STANDARD TABLE OF T_DATATAB INITIAL SIZE 0,
WA_DATATAB TYPE T_DATATAB.
DATA : GD_SCOL TYPE I VALUE '1',
GD_SROW TYPE I VALUE '1',
GD_ECOL TYPE I VALUE '256',
GD_EROW TYPE I VALUE '5000'.
DATA: IT_TAB TYPE FILETABLE,
GD_SUBRC TYPE I.
*Selection screen definition
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_FILE LIKE RLGRAP-FILENAME
DEFAULT 'c:이마트12월25일매출정보.xls' OBLIGATORY. " File Name
SELECTION-SCREEN END OF BLOCK B1.
***********************************************************************
* AT SELECTION-SCREEN
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
REFRESH: IT_TAB.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING
WINDOW_TITLE = 'Select File'
DEFAULT_FILENAME = '*.xls'
MULTISELECTION = ' '
CHANGING
FILE_TABLE = IT_TAB
RC = GD_SUBRC.
LOOP AT IT_TAB INTO P_FILE.
* so_fpath-sign = 'I'.
* so_fpath-option = 'EQ'.
* append so_fpath.
ENDLOOP.
***********************************************************************
* START-OF-SELECTION.
START-OF-SELECTION.
PERFORM UPLOAD_EXCEL_FILE TABLES IT_DATATAB
USING P_FILE
GD_SCOL
GD_SROW
GD_ECOL
GD_EROW.
***********************************************************************
* END-OF-SELECTION.
END-OF-SELECTION.
LOOP AT IT_DATATAB INTO WA_DATATAB.
WRITE:/ WA_DATATAB-F1,
WA_DATATAB-F2,
WA_DATATAB-F3,
WA_DATATAB-F4,
WA_DATATAB-F5,
WA_DATATAB-F6,
WA_DATATAB-F7,
WA_DATATAB-F8,
WA_DATATAB-F9,
WA_DATATAB-F10,
WA_DATATAB-F11,
WA_DATATAB-F12.
ENDLOOP.
*&--------------------------------------------------------------------*
*& Form UPLOAD_EXCEL_FILE
*&--------------------------------------------------------------------*
* upload excel spreadsheet into internal table
*---------------------------------------------------------------------*
* -->P_TABLE Table to return excel data into
* -->P_FILE file name and path
* -->P_SCOL start column
* -->P_SROW start row
* -->P_ECOL end column
* -->P_EROW end row
*---------------------------------------------------------------------*
FORM UPLOAD_EXCEL_FILE TABLES P_TABLE
USING P_FILE
P_SCOL
P_SROW
P_ECOL
P_EROW.
DATA : LT_INTERN TYPE KCDE_CELLS OCCURS 0 WITH HEADER LINE.
* Has the following format:
* Row number | Colum Number | Value
* ---------------------------------------
* i.e. 1 1 Name1
* 2 1 Joe
DATA : LD_INDEX TYPE I.
FIELD-SYMBOLS : <FS>.
* Note: Alternative function module - 'ALSM_EXCEL_TO_INTERNAL_TABLE'
CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = P_SCOL
I_BEGIN_ROW = P_SROW
I_END_COL = P_ECOL
I_END_ROW = P_EROW
TABLES
INTERN = LT_INTERN
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
FORMAT COLOR COL_BACKGROUND INTENSIFIED.
WRITE:/ 'Error Uploading file'.
EXIT.
ENDIF.
IF LT_INTERN[] IS INITIAL.
FORMAT COLOR COL_BACKGROUND INTENSIFIED.
WRITE:/ 'No Data Uploaded'.
EXIT.
ELSE.
SORT LT_INTERN BY ROW COL.
LOOP AT LT_INTERN.
MOVE LT_INTERN-COL TO LD_INDEX.
ASSIGN COMPONENT LD_INDEX OF STRUCTURE P_TABLE TO <FS>.
MOVE LT_INTERN-VALUE TO <FS>.
AT END OF ROW.
APPEND P_TABLE.
CLEAR P_TABLE.
ENDAT.
ENDLOOP.
ENDIF.
ENDFORM. "upload_excel_file
소스코드에 어떤 문제점이 있는지 좀 알려주세요
타입 선언문과 엑셀 실제 값의 길이 비교를 해보세요