Skip to Content
author's profile photo Former Member
Former Member

Uploading data from excel file to a dynamically created internal table

Hi,

I have a requirement where i have to upload data from an excel file into a database table. I would be able to determine the structure of the table only at runtime based on the user input.. so i have created an internal table dynamically.

Could you please tell me if its possible to upload data from an excel file to the dynamically created internal table using any function modules?

I thought of doing this by declaring a generic internal table of one field and then uploading the *.csv file into it and then splitting it based on "," and then assigning it to the field symbol referencing the internal table.. but my file length exceeds 132 characters and i'm only able to get data of lenght 132 char's in my internal table ( generic one).

Could anyone please show me a way around this.

Thanks in advance,

Harsha

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Mar 14, 2006 at 07:39 PM

    try out FM 'ALSM_EXCEL_TO_INTERNAL_TABLE'

    Regards,

    Bikash

    Add a comment
    10|10000 characters needed characters exceeded

    • Sure, check this out.

      
      report zrich_0002.
      
      type-pools: slis.
      
      field-symbols: <dyn_table> type standard table,
                     <dyn_wa>,
                     <dyn_field>.
      
      data: it_fldcat type lvc_t_fcat,
            wa_it_fldcat type lvc_s_fcat.
      
      type-pools : abap.
      
      data: new_table type ref to data,
            new_line  type ref to data.
      
      data: iflat type table of string.
      data: xflat type string.
      
      
        data: irec type table of string with header line.
        data: tabix type sy-tabix.
      
      data: file type string.
      
      selection-screen begin of block b1 with frame title text .
      parameters: p_file type  rlgrap-filename default 'c:Test.csv'.
      parameters: p_flds type i.
      selection-screen end of block b1.
      
      start-of-selection.
      
      * Add X number of fields to the dynamic itab cataelog
        do p_flds times.
          clear wa_it_fldcat.
          wa_it_fldcat-fieldname = sy-index.
          wa_it_fldcat-datatype = 'C'.
          wa_it_fldcat-inttype = 'C'.
          wa_it_fldcat-intlen = 10.
          append wa_it_fldcat to it_fldcat .
        enddo.
        .
      * Create dynamic internal table and assign to FS
        call method cl_alv_table_create=>create_dynamic_table
                     exporting
                        it_fieldcatalog = it_fldcat
                     importing
                        ep_table        = new_table.
      
        assign new_table->* to <dyn_table>.
      
      * Create dynamic work area and assign to FS
        create data new_line like line of <dyn_table>.
        assign new_line->* to <dyn_wa>.
      
      
        file = p_file.
      
        call method cl_gui_frontend_services=>gui_upload
          exporting
            filename                = file
          changing
            data_tab                = iflat
          exceptions
            file_open_error         = 1
            file_read_error         = 2
            no_batch                = 3
            gui_refuse_filetransfer = 4
            invalid_type            = 5
            no_authority            = 6
            unknown_error           = 7
            bad_data_format         = 8
            header_not_allowed      = 9
            separator_not_allowed   = 10
            header_too_long         = 11
            unknown_dp_error        = 12
            access_denied           = 13
            dp_out_of_memory        = 14
            disk_full               = 15
            dp_timeout              = 16
            others                  = 17.
      
      
        loop at iflat into xflat.
          clear irec. refresh irec.
          split xflat at ',' into table irec.
          loop at irec.
            tabix = sy-tabix.
            assign component tabix of structure <dyn_wa> to <dyn_field>.
            <dyn_field> = irec.
          endloop.
          append <dyn_wa> to <dyn_table>.
        endloop.
      
      
      * Write out data from table.
        loop at <dyn_table> into <dyn_wa>.
          do.
            assign component  sy-index  of structure <dyn_wa> to <dyn_field>.
            if sy-subrc <> 0.
              exit.
            endif.
            if sy-index = 1.
              write:/ <dyn_field>.
            else.
              write: <dyn_field>.
            endif.
          enddo.
        endloop.
      
      

      Regards,

      Rich Heilman

  • author's profile photo Former Member
    Former Member
    Posted on Mar 14, 2006 at 07:43 PM

    Try this fm -

    call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

    exporting

    filename = p_path

    i_begin_col = 1

    i_begin_row = 2

    i_end_col = 70

    i_end_row = 10000

    tables

    intern = i_data

    exceptions

    inconsistent_parameters = 1

    upload_ole = 2

    others = 3.

    I_DATA contains data. You need to popualte final itnernal table using this.

    I_DATA will contain details for each cell - respective row, column and value of respective cell.

    This should help you out.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 29, 2016 at 07:02 AM

    This message was moderated.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.