엑셀 / 텍스트 파일 업로드
FUNCTION Z_FI_EXCEL_UPLOAD.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(FILENAME) LIKE RLGRAP-FILENAME
*" VALUE(I_BEGIN_COL) TYPE I
*" VALUE(I_BEGIN_ROW) TYPE I
*" VALUE(I_END_COL) TYPE I
*" VALUE(I_END_ROW) TYPE I
*" EXPORTING
*" REFERENCE(SEPARATOR) TYPE C
*" TABLES
*" EXCEL_TAB TYPE KCDE_SENDER
*" EXCEPTIONS
*" INCONSISTENT_PARAMETERS
*" UPLOAD_OLE
*"----------------------------------------------------------------------
constants: c_hex_tab type x value 9.
field-symbols: <field>.
data: application type ole2_object,
workbook type ole2_object,
range type ole2_object,
worksheet type ole2_object.
data: h_cell type ole2_object.
data: h_cell1 type ole2_object.
define m_message.
case sy-subrc.
when 0.
when 1.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
when others. raise upload_ole.
endcase.
end-of-definition.
if i_begin_row > i_end_row. raise inconsistent_parameters. endif.
if i_begin_col > i_end_col. raise inconsistent_parameters. endif.
if application-header = space or application-handle = -1.
create object application 'Excel.Application'.
m_message.
endif.
call method of application 'Workbooks' = workbook.
m_message.
call method of workbook 'Open'
exporting
#1 = filename.
m_message.
get property of application 'ACTIVESHEET' = worksheet.
m_message.
call method of worksheet 'Cells' = h_cell
exporting
#1 = i_begin_row
#2 = i_begin_col.
m_message.
call method of worksheet 'Cells' = h_cell1
exporting
#1 = i_end_row
#2 = i_end_col.
m_message.
call method of worksheet 'RANGE' = range
exporting
#1 = h_cell
#2 = h_cell1.
m_message.
call method of range 'SELECT'.
m_message.
call method of range 'COPY'.
m_message.
m_message.
* Without flush, CLPB_IMPORT does not find the data "SEVERING 5/99
call function 'CONTROL_FLUSH' "SEVERING 5/99
exceptions others = 3. "SEVERING 5/99
call function 'CLPB_IMPORT'
tables
data_tab = excel_tab
exceptions
clpb_error = 1
others = 2.
if sy-subrc <> 0. message x001(kx). endif.
assign separator to <field> type 'X'.
<field> = c_hex_tab.
set property of application 'CutCopyMode' = 0.
m_message.
call method of application 'QUIT'.
m_message.
free object application.
m_message.
ENDFUNCTION.
TYPE-POOLS: kcde.
DATA: g_execl_t TYPE kcde_sender,
l_tab TYPE kcde_sender_struc.
DATA: separator TYPE c.
DATA: BEGIN OF gt_upload OCCURS 0,
fld01(50),
fld02(50),
fld03(50),
fld04(50),
fld05(50),
END OF gt_upload.
LOOP AT g_execl_t INTO l_tab.
CHECK NOT l_tab IS INITIAL.
SPLIT l_tab-line AT separator INTO gt_upload-fld01
gt_upload-fld02.
IF gt_upload-fld01 CS 'Header'.
CLEAR gt_upload.
CONTINUE.
ENDIF.
APPEND gt_upload.CLEAR gt_upload.
ENDLOOP.