0% found this document useful (0 votes)
192 views

Yexcel Upload IN ABAP

This function uploads data from an Excel file into an internal table by: 1. Opening the Excel file and selecting the specified range of cells. 2. Copying the selected range to the clipboard. 3. Importing the clipboard contents into an internal table. 4. Converting the internal table to separate rows using a separator character. 5. Closing the Excel application.

Uploaded by

SomnathChoudhury
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
192 views

Yexcel Upload IN ABAP

This function uploads data from an Excel file into an internal table by: 1. Opening the Excel file and selecting the specified range of cells. 2. Copying the selected range to the clipboard. 3. Importing the clipboard contents into an internal table. 4. Converting the internal table to separate rows using a separator character. 5. Closing the Excel application.

Uploaded by

SomnathChoudhury
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

FUNCTION yexcel_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
*" TABLES
*" INTERN STRUCTURE YALSMEX_TABLINE
*" EXCEPTIONS
*" INCONSISTENT_PARAMETERS
*" UPLOAD_OLE
*"----------------------------------------------------------------------
DATA : BEGIN OF is_excel ,
kcde_sender_line(16384) TYPE c,
END OF is_excel.
DATA: excel_tab LIKE TABLE OF is_excel.
DATA: separator TYPE c.
FIELD-SYMBOLS: <field> TYPE ANY.
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.
* set property of application 'Visible' = 1.
* 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.
* copy to Clippboard
CALL METHOD OF range 'COPY'.
m_message.
* free object application.
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 x000(ymscm). ENDIF..
* ASSIGN SEPARATOR TO <FIELD> TYPE 'X'. "H916967
* <FIELD> = C_HEX_TAB. "H916967
separator = cl_abap_char_utilities=>horizontal_tab. "H916967
PERFORM separated_to_intern_convert TABLES excel_tab intern
USING separator.
SET PROPERTY OF application 'CutCopyMode' = 0.
m_message.
CALL METHOD OF application 'QUIT'.
m_message.
FREE OBJECT application.
m_message.
ENDFUNCTION.
*Messages
*----------------------------------------------------------
*
* Message class: YMSCM
*000 & & & &
--------------------------------------------------------------------------------
--
Extracted by Direct Download Enterprise version 1.3.1 - E.G.Mellodew. 1998-2005
UK. Sap Release 701

You might also like