05-11-2006 12:05 PM
Kindly explain the statement
CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
what is 'EXCEL.APPLICATION'
05-11-2006 12:07 PM
Hi,
that means..
what ever the object which is going to create is of type EXCEL.
Regards
vijay
05-11-2006 12:09 PM
This is what the sap documentation says:
go to se38 editor.
Press on the 'i' button on the apllication tool bar.
Enter string "create object".
Press Enter.
It gives a pop up with related syntaxes.
Click on "Creating an OLE2 Automation Object " link.
This would take you to this.
<i><b>CREATE
Basic form 2
CREATE OBJECT obj class.
Addition:
1.... NO FLUSH 2.... QUEUE-ONLY
Effect
Creates an external object of the class class.
The CREATE statement creates the initial object of the class, which you can use in other OLE statements.
The return code SY-SUBRC indicates whether the required object could be created:
The Return Code is set as follows:
SY-SUBRC = 0: Object created successfully. SY-SUBRC = 1: Error in communication with the SAPgui. SY-SUBRC = 2: Error in function call in the SAPgui. OLE function modules are only implemented for use under Windows. SY-SUBRC = 3: The OLE-API call returned an error. You may have memory problems.
Note
If the automation server has a CLSID or PROGID entry in table TOLE that is flagged for authorization checks, the system automatically runs them. If the authorization check fails, a runtime error occurs. To avoid this, you can check the authorization in advance using the function module AUTHORITY_CHECK_OLE. To maintain table TOLE use Transaction SOLE.
Addition 1
... NO FLUSH
Effect
If you use this addition, CREATE OBJECT calls are collected, and not sent to the SAPgui for further processing until you explicitly call the function module FLUSH.
Addition 2
... QUEUE-ONLY
Effect
If you use this addition, the objects created using CREATE OBJECT can be used by subsequent calls within the automation queue, but are not written into the corresponding ABAP variables under the following conditions:
1.) If the queue contains only CREATE OBJECT, CALL METHOD, and GET PROPERTY calls with return values and the QUEUE-ONLY addition.
2.) If the flush mode in the Debugger is deactivated.
If you use this addition, you still have to ensure that you use FREE OBJECT to destroy any frontend objects you create using CREATE OBJECT. Otherwise, you may cause memory shortages, or crashes in the application you are controlling.
CREATE OBJECT belongs to a group of key words that allows you to process external objects with ABAP/4. At present, only the object model OLE2 is supported, i.e. all objects must be of type OLE2_OBJECT. This type and other necessary data are defined in the include program OLE2INCL.
Example
Creating an EXCEL object.
TYPE-POOLS OLE2.
DATA EXCEL TYPE OLE2_OBJECT.
CREATE OBJECT EXCEL 'Excel.Application'.</b></i>
05-11-2006 12:10 PM
Hi Rajesh,
Check the standard Program <b>RSDEMO01</b> . It is having good example for your requirement.
Like that check help for DOI <a href="http://help.sap.com/saphelp_erp2005/helpdata/en/e9/0be775408e11d1893b0000e8323c4f/frameset.htm">link</a>
<i>Hope This Info Helps YOU.</i>
Regards,
Raghav
05-11-2006 12:59 PM
Excel is the Microsoft spreadsheet application used throughout businesses.
This statement reads the registry of your local computer's operating system and gets the registry info to create an instance of Microsoft Excel on your local (client) computer.
05-30-2006 9:22 PM
Hi,
Can anybody pls help to read a particular work-sheet from an excel file. By default, my FM is reading from active work-sheet only.
pls respond to me ASAP.
Thanks in advance
Raghav
05-30-2006 9:30 PM
Hi Raghav. To read a specific worksheet in Excel:
*&-- Crio objeto Excel
CREATE OBJECT excel 'Excel.Application' .
*&-- Coloco propriedade NÃO VISÍVEL
SET PROPERTY OF excel 'Visible' = 0.
*&-- Crio objeto del arquivo
CALL METHOD OF excel 'Workbooks' = workbook.
*&-- Abro arquivo
CALL METHOD OF workbook 'Open'
EXPORTING
#1 = filename.
*&-- Crio objeto de folhas
CALL METHOD OF excel 'ActiveWorkbook' = aw.
*&-- Seleciono folha SHEETNAME
CALL METHOD OF aw 'Sheets' = worksheet
EXPORTING
#1 = sheetname.
CALL METHOD OF aw 'Sheets' = sheets.
*&-- Ativo folha SHEETNAME
CALL METHOD OF worksheet 'Activate'.
*&-- Seleciono os dados da folha (desde)
CALL METHOD OF worksheet 'Cells' = h_cell
EXPORTING
#1 = i_begin_row
#2 = i_begin_col.
m_message.
*&-- Seleciono os dados da folha (hasta)
CALL METHOD OF worksheet 'Cells' = h_cell1
EXPORTING
#1 = i_end_row
#2 = i_end_col.
m_message.
*&-- Seleciono rango de folha
CALL METHOD OF worksheet 'RANGE' = range
EXPORTING
#1 = h_cell
#2 = h_cell1.
m_message.
CALL METHOD OF range 'SELECT'.
m_message.
*&-- Copio seleção de rango a clipboard
CALL METHOD OF range 'COPY'.
m_message.
*&-- Leo clipboard ABAP
CALL METHOD cl_gui_frontend_services=>clipboard_import
IMPORTING
data = excel_tab
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE a037(alsmex).
ENDIF.
ld_separator = cl_abap_char_utilities=>horizontal_tab.
*&-- Cheio tabela interna con dados da folha excel
*&-- Rutina estandar de função ALSM_EXCEL_TO_INTERNAL_TABLE
PERFORM separated_to_intern_convert TABLES excel_tab intern
USING ld_separator.
*&-- Limpo clipboard
REFRESH excel_tab.
CALL METHOD cl_gui_frontend_services=>clipboard_export
IMPORTING
data = excel_tab
CHANGING
rc = ld_rc
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
*&-- Fecho os objetos de excel
CALL METHOD OF excel 'QUIT'.
m_message.
FREE OBJECT h_cell. m_message.
FREE OBJECT h_cell1. m_message.
FREE OBJECT range. m_message.
FREE OBJECT worksheet. m_message.
FREE OBJECT workbook. m_message.
FREE OBJECT excel. m_message.
*&----
*
*& Form separated_to_intern_convert
*&----
*
FORM separated_to_intern_convert TABLES i_tab TYPE ty_t_sender
i_intern TYPE ty_t_itab
USING i_separator TYPE c.
DATA: l_sic_tabix LIKE sy-tabix,
l_sic_col TYPE kcd_ex_col.
DATA: l_fdpos LIKE sy-fdpos.
REFRESH i_intern.
LOOP AT i_tab.
l_sic_tabix = sy-tabix.
l_sic_col = 0.
WHILE i_tab CA i_separator.
l_fdpos = sy-fdpos.
l_sic_col = l_sic_col + 1.
PERFORM line_to_cell_separat TABLES i_intern
USING i_tab l_sic_tabix l_sic_col
i_separator l_fdpos.
ENDWHILE.
IF i_tab <> space.
CLEAR i_intern.
i_intern-row = l_sic_tabix.
i_intern-col = l_sic_col + 1.
i_intern-value = i_tab.
APPEND i_intern.
ENDIF.
ENDLOOP.
ENDFORM. " separated_to_intern_convert
*&----
*
*& Form line_to_cell_separat
*&----
*
FORM line_to_cell_separat TABLES i_intern TYPE ty_t_itab
USING i_line
i_row LIKE sy-tabix
ch_cell_col TYPE kcd_ex_col
i_separator TYPE c
i_fdpos LIKE sy-fdpos.
DATA: l_string TYPE ty_s_senderline.
DATA l_sic_int TYPE i.
CLEAR i_intern.
l_sic_int = i_fdpos.
i_intern-row = i_row.
l_string = i_line.
i_intern-col = ch_cell_col.
csv Dateien mit separator in Zelle: --> ;"abc;cd";
IF ( i_separator = ';' OR i_separator = ',' ) AND
l_string(1) = gc_esc.
PERFORM line_to_cell_esc_sep USING l_string
l_sic_int
i_separator
i_intern-value.
ELSE.
IF l_sic_int > 0.
i_intern-value = i_line(l_sic_int).
ENDIF.
ENDIF.
IF l_sic_int > 0.
APPEND i_intern.
ENDIF.
l_sic_int = l_sic_int + 1.
i_line = i_line+l_sic_int.
ENDFORM. " line_to_cell_separat
*&----
*
*& Form line_to_cell_esc_sep
*&----
*
FORM line_to_cell_esc_sep USING i_string
i_sic_int TYPE i
i_separator TYPE c
i_intern_value TYPE ty_d_itabvalue.
DATA: l_int TYPE i,
l_cell_end(2).
FIELD-SYMBOLS: .
l_int = l_int + 2.
i_sic_int = l_int.
i_string = i_string+l_int.
ELSEIF i_string CS gc_esc.
letzte Celle
l_int = sy-fdpos.
ASSIGN i_string(l_int) TO 0 . MESSAGE x001(kx) . ENDIF.
ELSE.
MESSAGE x001(kx) . "was ist mit csv-Format
ENDIF.
ENDIF.
ENDFORM. " line_to_cell_esc_sep
Hope it Helps
Jesus
05-30-2006 10:07 PM
Hi Friend,
Thanks for a quick response. I am still facing some problems. Can you pls let me know what should be the type of "sheetname" in the following code
*&-- Seleciono folha SHEETNAME
CALL METHOD OF aw 'Sheets' = worksheet
EXPORTING
#1 = sheetname.
And also, I have an excel file with 2 work sheets. after execution of the program, i am getting the output of both the worksheets. can you pls tell why is this happend?
Thank you very much for your help
Regards
Raghav
05-30-2006 10:53 PM
Hi Raghav. Actually, the code I send was for a FM i developed. Create a FM with the following parameters:
IMPORTING
REFERENCE(FILENAME) LIKE RLGRAP-FILENAME
REFERENCE(SHEETNAME) TYPE CHAR100
REFERENCE(I_BEGIN_COL) TYPE I
REFERENCE(I_BEGIN_ROW) TYPE I
REFERENCE(I_END_COL) TYPE I
REFERENCE(I_END_ROW) TYPE I
TABLES
INTERN STRUCTURE ALSMEX_TABLINE
EXCEPTIONS
INCONSISTENT_PARAMETERS
UPLOAD_OLE
And call the FM for every worksheet you want to read on an internal table. Every time you call the FM, it will fill the internal table you pass to it with the data on the worksheet you specify.
Hope it Helps
Jesus
05-31-2006 7:06 AM
Hi Jesus,
Thank you. I did the same and the function module started fetching from a particular work sheet. But I have a new problem now. When I call this function module inside my BSP application, it is not giving any values. Could you pls let me know, if you have any information.
Thanks in advance.
Regards
Raghav