Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Function ALSM_EXCEL_TO_INTERNAL_TABLE

Hy guys , im using this function in order to read a excel file , however , I m Getting exception upload_ole = 2 , why is that ? , here some code :

FORM match_archivo USING p_archivo CHANGING archivo.

DATA:lt_files TYPE filetable,

l_file TYPE file_table,

l_title TYPE string,

l_subrc TYPE i,

l_usr_act TYPE i,

l_def_file TYPE string.

l_def_file = p_archivo.

CLEAR lt_files. REFRESH lt_files.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

window_title = ''

default_extension = '*.xls'

default_filename = '*.xls'

initial_directory = 'c:\'

multiselection = ' '

CHANGING

file_table = lt_files

rc = l_subrc

EXCEPTIONS

file_open_dialog_failed = 1

cntl_error = 2

error_no_gui = 3

OTHERS = 5

.

IF sy-subrc EQ 0.

LOOP AT lt_files ASSIGNING <fs>.

fic_inl = <fs>.

EXIT.

ENDLOOP.

ELSE.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM.

----


  • FORM read_fi_in *

  • *

----


  • ........ *

----


FORM read_fi_in.

CLEAR: fic_inl1, var.

MOVE fic_inl TO fic_inl1 .

REPLACE '.' WITH '~' INTO fic_inl1.

IF sy-subrc EQ 0.

SET LOCALE LANGUAGE sy-langu.

TRANSLATE fic_inl1 TO UPPER CASE.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = fic_inl1

i_begin_col = '1'

i_begin_row = '1'

i_end_col = '256'

i_end_row = '65536'

TABLES

intern = excel

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

IF sy-subrc = 0.

LOOP AT excel.

ENDLOOP.

ENDIF.

ENDIF.

ENDFORM.

thank you very much for your help .

Tags:
Former Member
Former Member replied

Hi Ali Sanchez,

First Close your excel sheet before executing your code.

Example code to upload excel file.

FORM get_filddata .

  file = 'C:\Documents and Settings\maheswari.chegu\Desktop\Materialtype.XLS'.

  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = file
      i_begin_col             = '1'
      i_begin_row             = '1'
      i_end_col               = '5'
      i_end_row               = '6000'
    TABLES
      intern                  = xcel
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.

  LOOP AT xcel.

    CASE xcel-col.
      WHEN '0001'.
        itab-fld1 = xcel-value.
      WHEN '0002'.
        itab-fld2 = xcel-value.
      WHEN '0003'.
        itab-fld3 = xcel-value.
      WHEN '0004'.
        itab-fld4 = xcel-value.
      WHEN '0005'.
        itab-fld5 = xcel-value.
    ENDCASE.

    AT END OF row.
      APPEND itab.
      CLEAR itab.
    ENDAT.

  ENDLOOP.

ENDFORM.                    " GET_FILDDATA

Regards,

Mahi

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question