cancel
Showing results for 
Search instead for 
Did you mean: 

How to upload an .xls file from a presentation server to an internal table?

Former Member
0 Kudos

Hi,

I need to know how to upload an excel file <b>without</b> changing its format in to .csv or any other format from a presentation server into an internal table?

Thanks & Regards

Amrutha.

Edited by: Wilian Segatto on Jan 25, 2010 4:28 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Dear Amrutha,

Use FM ALSM_EXCEL_TO_INTERNAL_TABLE - It uploads the data from presentation server (excel file).

data : it_intern type ALSMEX_TABLINE.
 
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
  EXPORTING
    filename                      = 'C:TEST.XLS'
    i_begin_col                   = 1        "as per your requirement
    i_begin_row                   = 2        "as per your requirement  
    i_end_col                     = 6        "as per your requirement
    i_end_row                     = 500      "as per your requirement
  TABLES
    intern                        = it_intern 
* EXCEPTIONS
*   INCONSISTENT_PARAMETERS       = 1
*   UPLOAD_OLE                    = 2
*   OTHERS                        = 3
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Regards,

Naveen.

Former Member
0 Kudos

Hi Naveen,

I am working in SCM system and the FM which u have mentioned is not present in SCM.

Former Member
0 Kudos

Hi Amrutha...i guess you must convert it into *.CSV format before you can upload it....you can use the normal GUI_UPLOAD FM for this purpose...

Thanks!

Former Member
0 Kudos

Dear Amrutha,

You can copy the code from Function Module 'ALSM_EXCEL_TO_INTERNAL_TABLE', if you have access to ECC or R/3. You would need to take help from ABAPer for the same.

For your reference, below is the code:

function alsm_excel_to_internal_table .
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  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  ALSMEX_TABLINE
*"  EXCEPTIONS
*"      INCONSISTENT_PARAMETERS
*"      UPLOAD_OLE
*"----------------------------------------------------------------------

  data: excel_tab     type  ty_t_sender.
  data: ld_separator  type  c.
  data: application   type  ole2_object,
        workbook      type  ole2_object,
        range         type  ole2_object,
        worksheet     type  ole2_object.
  data: h_cell        type  ole2_object,
        h_cell1       type  ole2_object.
  data:
    ld_rc             type i.
*   Rückgabewert der Methode "clipboard_export     "

* Makro für Fehlerbehandlung der Methods
  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.


* check parameters
  if i_begin_row > i_end_row. raise inconsistent_parameters. endif.
  if i_begin_col > i_end_col. raise inconsistent_parameters. endif.

* Get TAB-sign for separation of fields
  class cl_abap_char_utilities definition load.
  ld_separator = cl_abap_char_utilities=>horizontal_tab.

* open file in Excel
  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.

* mark whole spread sheet
  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 marked area (whole spread sheet) into Clippboard
  call method of range 'COPY'.
  m_message.

* read clipboard into 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.

  perform separated_to_intern_convert tables excel_tab intern
                                      using  ld_separator.

* clear 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
          .

* quit Excel and free ABAP Object - unfortunately, this does not kill
* the Excel process
  call method of application 'QUIT'.
  m_message.

* >>>>> Begin of change note 575877
* to kill the Excel process it's necessary to free all used objects
  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 application.  m_message.
* <<<<< End of change note 575877
endfunction.

Regards,

Naveen.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello Amrutha -

There is <b>no way</b> to upload an excel file without changing the format to .csv (BW gurus correct me if i am wrong). You have to develop a customized program to convert the excel file into the file extension that SAP accepts.

Hope this helps.

Regards,

Suresh Garg