Skip to Content

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

excel to internal table

Hi

I am using the below code to upload the excel data into internal table but only one record is stored in internal table but excel shheet contains more

  • CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

  • EXPORTING

  • I_FIELD_SEPERATOR =

  • i_line_header = 'X'

  • i_tab_raw_data = it_raw

  • i_filename = p_file

  • TABLES

  • i_tab_converted_data = it_datatab[]

  • EXCEPTIONS

  • conversion_failed = 1

  • OTHERS = 2.

*

what could be the reason is there any other FM to do this

thanks

sai

Tags:
Former Member
Former Member replied

hii

you can loop like below code

*Upload data from Excel sheet to internal table.
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = p_pfile
      i_begin_col             = 1
      i_begin_row             = 2
      i_end_col               = 13
      i_end_row               = 8
    TABLES
      intern                  = it_excel
    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.


*Populate data to internal tables and structures

  SORT it_excel BY row col.

  LOOP AT it_excel INTO ls_excel.

    CASE ls_excel-col.
      WHEN 1.
        ls_data-rec_no = ls_excel-value.
        IF ls_data-rec_no NE w_docno.
          WRITE:
            'You Have Entered wrong Document Number'.
        ELSE.
          WRITE:
            'Document Number Same'.
        ENDIF.                         " IF ls_data-rec_no NE w_docno.
      WHEN 2.
        ls_data-doc_type = ls_excel-value.
      WHEN 3.
        ls_data-doc_part = ls_excel-value.
      WHEN 4.
        ls_data-doc_ver = ls_excel-value.
      WHEN 5.
        ls_data-application = ls_excel-value.
      WHEN 6.
        ls_data-data_car = ls_excel-value.
      WHEN 7.
        ls_data-file_path = ls_excel-value.
      WHEN 8.
        ls_data-matnr = ls_excel-value.

    ENDCASE.                           " CASE ls_excel-col.

regards

twinkal

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