Excel file to internal table gui_upload

Hi every 1,
I want to upload excel file to internal table through GUI_UPLOAD FM,
Will you please help me out.
Regards,

You might want to try the following function module.  This progam uploads an excel file to a dynamic internal table.
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: xcel type table of alsmex_tabline with header line.
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>.
* Upload the excel
  call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
       exporting
            filename                = p_file
            i_begin_col             = '1'
            i_begin_row             = '1'
            i_end_col               = '200'
            i_end_row               = '5000'
       tables
            intern                  = xcel
       exceptions
            inconsistent_parameters = 1
            upload_ole              = 2
            others                  = 3.
* Reformt to dynamic internal table
  loop at xcel.
    assign component xcel-col of structure <dyn_wa> to <dyn_field>.
    if sy-subrc = 0.
     <dyn_field> = xcel-value.
    endif.
    at end of row.
      append <dyn_wa> to <dyn_table>.
      clear <dyn_wa>.
    endat.
  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

Similar Messages

  • Upload excel file to internal table in web dynpro program

    Hi friend's
    In web dynpro program how to upload excel file into  internal table and finally data will be save Y table.

    hi,
    See the properties of File Upload UI element..
    Link: [http://help.sap.com/saphelp_nw70ehp1/helpdata/en/48/732f0510d83ff6e10000000a42189c/frameset.htm]
    Goto References -> User Interface Elements -> Integration Category -> File upload..
    After creating the 'FILE UPLOAD' element in a view.. Bind a datasource(a context attribute with STRING) with the data property..
    Double click on ONACTION_UPLOAD method. Write a code as given below.
    METHOD onactionon_upload .
    TYPES :   BEGIN OF str_itab,
           name(10) TYPE c,
           age(10) TYPE c,
           END OF str_itab.  DATA : t_table1 TYPE STANDARD TABLE OF str_itab,
             i_data TYPE STANDARD TABLE OF string,
             l_string TYPE string,
             fs_table TYPE str_itab,
             l_xstring TYPE xstring,
             fields TYPE string_table,
             lv_field TYPE string.
    DATA : t_table TYPE if_main=>elements_data_tab,
             data_table TYPE if_main=>elements_data_tab.
    * get single attribute 
    wd_context->get_attribute(  
    EXPORTING    
    name =  `DATASOURCE`  
    IMPORTING    
    value = l_xstring ).
      CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
        EXPORTING
          in_xstring = l_xstring
        IMPORTING
          out_string = l_string. 
    SPLIT l_string  AT cl_abap_char_utilities=>newline INTO TABLE i_data.
    * Bind With table Element.
    LOOP AT i_data INTO l_string.
        SPLIT l_string AT cl_abap_char_utilities=>horizontal_tab INTO TABLE fields.
       READ TABLE fields INTO lv_field INDEX 1.
        fs_table-name = lv_field.  
    READ TABLE fields INTO lv_field INDEX 2.
        fs_table-age = lv_field.   
    APPEND fs_table TO t_table1.     "Append to  the internal  table
      ENDLOOP.
    Edited by: Rameshkumar Raamasamy on Feb 9, 2010 9:39 AM

  • FROM EXCEL FILE TO INTERNAL TABLE

    HI GURU'S,
    i'm using the following code to conver the excel file into internal table.
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
        EXPORTING
         I_FIELD_SEPERATOR          = 'X'
        I_LINE_HEADER              =
          I_TAB_RAW_DATA             = IT_TAB_RAW_DATA
          I_FILENAME                 = P_FILE
        TABLES
          I_TAB_CONVERTED_DATA       = IT_MM01
       EXCEPTIONS
         CONVERSION_FAILED          = 1
         OTHERS                     = 2
    What is the exact format for the to send the Excel File.
    My requirement is the Excel file contains the several fields , that should be stored as a records in the internal table
    My problem is when i send the data in the excel file as one column, i'm getting all the data in the first column of the Internal Table.
    If i send the data in the excel file as a record it is not filling the internal table.
    what is the problem??/
    if the Excel files contain multiple records is it able to convert the data into internal table records.
    Regards,
    Adi.

    **Internal Table to hold the records in the text file
    Hello Adi,
    Put the fields in excel in the same format in which u want in ur internal table(here record)
    U can refer the following code.
    data: begin of record occurs 0,
          General Data
    data element: BUKRS
            bukrs_001(004), " Company Code
    data element: EKORG
            ekorg_002(004), " Purchase Orgn
    data element: KTOKK
            ktokk_003(004), " Account Group
        end of record.
    Internal Table
    data:it_excel like table of alsmex_tabline with header line.
    **SELECTION-SCREEN**
    selection-screen begin of  block blk.
    parameters: p_file like rlgrap-filename default 'c:\vendor_creation.xls'
    selection-screen end of block blk.
    A T   S E L E C T I O N - S C R E E N   O U T P U T
    ***************START*********************** F4 Help for field p_file
    at selection-screen on value-request for p_file.
    call function 'KD_GET_FILENAME_ON_F4'
    exporting
       program_name        = syst-repid
       dynpro_number       = syst-dynnr
      FIELD_NAME          = ' '
      STATIC              = ' '
      MASK                = ' '
      changing
        file_name           = p_file
    EXCEPTIONS
      MASK_TOO_LONG       = 1
      OTHERS              = 2
    if sy-subrc <>  0.
    message e006(zhnc).
    endif.
    S T A R T - O F - S E L E C T I O N
    start-of-selection.
    data : vf_index type i.
    data : vf_start_col type i value '1',      "start column
             vf_start_row type i value '4',    "start row
             vf_end_col   type i value '200',  "maximum column
             vf_end_row   type i value '2500', "maximum row
             p_text(20).                       "stores error messages
    */ Work Area
    data: wa_intern like it_excel.
    */ Field symbol
    field-symbols : <fs>.
    *********Fn Module to convert the excel file data into internal table
    call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
      exporting
        filename                      =  'c:\vendor_creation.xls'
        i_begin_col                   =  vf_start_col
        i_begin_row                   =  vf_start_row
        i_end_col                     =  vf_end_col
        i_end_row                     =  vf_end_row
      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.
      if it_excel[] is initial.
        p_text = 'No Data Uploaded'.
      else.
      sort it_excel by row col.
          loop at it_excel.
          move : it_excel-col to vf_index.
          assign component vf_index of structure record to <fs>.
          move : it_excel-value to <fs>.
          at end of row.
            append record.
            clear record.
          endat.
          endloop.
      endif.
    In case of any problem u  can revert back.
    Aastha

  • FM to upload the Excel file to internal table

    Hi
    Is any FM available to upload the Excel file to internal table.
    Thanks
    Anbu

    Hi
    se this code
    EXCEL to INTERNAL TABLE and then to APPLICATION SERVER
    *& Report  ZSD_EXCEL_INT_APP
    REPORT  ZSD_EXCEL_INT_APP.
    parameter: file_nm type localfile.
    types : begin of it_tab1,
            f1(20),
            f2(40),
            f3(20),
           end of it_tab1.
    data : it_tab type table of ALSMEX_TABLINE with header line,
           file type rlgrap-filename.
    data : it_tab2 type it_tab1 occurs 1,
           wa_tab2 type it_tab1,
           w_message(100)  TYPE c.
    at selection-screen on value-request for file_nm.
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      PROGRAM_NAME        = SYST-REPID
      DYNPRO_NUMBER       = SYST-DYNNR
      FIELD_NAME          = ' '
       STATIC              = 'X'
      MASK                = ' '
      CHANGING
       file_name           = file_nm
    EXCEPTIONS
       MASK_TOO_LONG       = 1
       OTHERS              = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    start-of-selection.
    refresh it_tab2[].clear wa_tab2.
    file = file_nm.
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
      EXPORTING
        filename                      = file
        i_begin_col                   = '1'
        i_begin_row                   =  '1'
        i_end_col                     = '10'
        i_end_row                     = '35'
      tables
        intern                        = it_tab
    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.
    loop at it_tab.
      case it_tab-col.
       when '002'.
        wa_tab2-f1 = it_tab-value.
       when '004'.
        wa_tab2-f2 = it_tab-value.
      when '008'.
        wa_tab2-f3 = it_tab-value.
    endcase.
    at end of row.
      append wa_tab2 to it_tab2.
    clear wa_tab2.
      endat.
    endloop.
    data : p_file TYPE  rlgrap-filename value 'TEST3.txt'.
    OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    *--- Display error messages if any.
      IF sy-subrc NE 0.
        MESSAGE e001(zsd_mes).
        EXIT.
      ELSE.
    *---Data is downloaded to the application server file path
        LOOP AT it_tab2 INTO wa_tab2.
          TRANSFER wa_tab2 TO p_file.
        ENDLOOP.
      ENDIF.
    *--Close the Application server file (Mandatory).
      CLOSE DATASET p_file.
    loop at it_tab2 into wa_tab2.
      write : / wa_tab2-f1,wa_tab2-f2,wa_tab2-f3.
    endloop.

  • Uploading excel file into internal table

    Hi,
    Any function module is there to upload an excel file into internal table in CRM 7.0 system?
    Thanks.

    Hi Ginger,
    If u have access to ECC R/3 make use FM 'TEXT_CONVERT_XLS_TO_SAP' source code which is existing to convert to Excel to Internal table.  It will work in CRM also.
    As of Now I don't have access to SAP S/m. Mean while u can try as above said.
    Regards,
    Lokesh B

  • Uploading excel file into internal table with field length more than 255

    I am trying to upload the data from an excel file through function module 'TEXT_CONVERT_XLS_TO_SAP'.
    I have tested by changing the field type from string, and char2000.
    But it is accepting only 255 chars from the cell content.
    How to get the total content of the field if it is more than 255 char.

    hi,
      you can use any of the following procedures:
    For uploading data from excel to internal table refer standard report  RC1TCG3Z  in se38 :
                                               or
    You can use the FM 'ALSM_EXCEL_TO_INTERNAL_TABLE' itself. Please check if you have done it this way . But,  this FM can be a little time consuming if the excel has large data, so you can use the FM u2018GUI_UPLOADu2019.
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
            EXPORTING
              filename                = p_file1
              i_begin_col          = l_b1
              i_begin_row        = l_c1
             i_end_col               = l_b2
             i_end_row             = l_c2
           TABLES
              intern                  = lt_data
            EXCEPTIONS
             inconsistent_parameters = 1
            upload_ole              = 2
              OTHERS                  = 3.
          IF sy-subrc <> 0.
            MESSAGE e018 DISPLAY LIKE 'i'.
         ENDIF.
    *---Removing the first heading fields from the file.
          IF NOT lt_data[] IS INITIAL.
            LOOP AT lt_data INTO lwa_data WHERE row = '0001'.
              DELETE lt_data.
              CLEAR lwa_data.
            ENDLOOP.
    *---Inserting the data from file the internal table
            LOOP AT lt_data INTO lwa_data.
              CASE lwa_data-col.
                WHEN 1.
                  wa_file_wicopa-serial = lwa_data-value.
                WHEN 2.
                  wa_file_wicopa-blart = lwa_data-value.
                WHEN 3.
                  wa_file_wicopa-bldat = lwa_data-value.
                WHEN 4.
                  wa_file_wicopa-budat = lwa_data-value.
              ENDCASE.
              AT END OF row.
                APPEND wa_file_wicopa TO gt_file_wicopa.
                CLEAR wa_file_wicopa.
              ENDAT.
              CLEAR lwa_data.
            ENDLOOP.
          ENDIF.
        ENDIF.
                                                or
    DATA: it_test TYPE STANDARD TABLE OF alsmex_tabline WITH HEADER LINE.
    DATA :v_start_col TYPE i VALUE '1',
          v_start_row TYPE i VALUE '1',
          v_end_col TYPE i VALUE '256',
          v_end_row TYPE i VALUE '65536',
          v_text TYPE repti.
    * Funtion Module to upload values from excel to the Internal table
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
        EXPORTING
          filename                = p_file
          i_begin_col             = v_start_col
          i_begin_row             = v_start_row
          i_end_col               = v_end_col
          i_end_row               = v_end_row
        TABLES
          intern                  = it_test
        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.
                             Or
    You can use FM u201CTEXT_CONVERT_XLS_TO_SAPu201D.
    DATA : i_raw TYPE truxs_t_text_data.
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
        EXPORTING
          i_field_seperator          = 'X'
          i_tab_raw_data             = i_raw
          i_filename                 = p_path
        TABLES
          i_tab_converted_data       = itab
    EXCEPTIONS
       conversion_failed          = 1
       OTHERS                     = 2
    hope it will help u
    regards
    rahul

  • Upload openoffice excel file into internal table

    Hi Everyone,
    I have a requirement where in we need to upload vendor master data into SAP.
    The data is available in excel format. But the excel sheet was created in openoffice s/w and client is not allowing
    us to install MS-Office so that we cut and paste the data by creating anexcel file.
    Now there is an option of saving the excel file in openoffice s/w as MS-Excel 95 format with .xls extension.
    But since we are saving this in openoffice enivoronment   the FM ALSM_EXCEL..... data is not improting this excel file into
    Did somebody faced this issue before. Pls share the approach to solve this issue.
    Regards,
    Vinay

    Hi !
    you can use the Function module TEXT_CONVERT_XLS_TO_SAP to upload xcel file to internal table
    please go through the code below.
    REPORT zupload_excel_to_itab.
    TYPE-POOLS: truxs.
    PARAMETERS: p_file TYPE rlgrap-filename.
    TYPES: BEGIN OF t_datatab,
    col1(30) TYPE c,
    col2(30) TYPE c,
    col3(30) TYPE c,
    END OF t_datatab.
    DATA: it_datatab type standard table of t_datatab,
    wa_datatab type t_datatab.
    DATA: it_raw TYPE truxs_t_text_data.
    At selection screen
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    CALL FUNCTION 'F4_FILENAME'
    EXPORTING
    field_name = 'P_FILE'
    IMPORTING
    file_name = p_file.
    *START-OF-SELECTION.
    START-OF-SELECTION.
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
    I_FIELD_SEPERATOR =
    i_line_header = 'X'
    i_tab_raw_data = it_raw " WORK TABLE
    i_filename = p_file
    TABLES
    i_tab_converted_data = it_datatab[] "ACTUAL DATA
    EXCEPTIONS
    conversion_failed = 1
    OTHERS = 2.
    IF sy-subrc 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    END-OF-SELECTION.
    END-OF-SELECTION.
    LOOP AT it_datatab INTO wa_datatab.
    WRITE:/ wa_datatab-col1,
    wa_datatab-col2,
    wa_datatab-col3.
    ENDLOOP.
    hope this will help you.
    Regards,
    Kiran

  • Upload long text from excel file into internal table

    I need to upload service master(T-code : AC02) data alongwith long text.Now i have data in excel as: Service no(ASMD-ASNUM) and corresponding long text for it.
    I am facing problem in getting entire lontext from excel into my internal table.It only takes till 255 characters i think.Any help in this regard woulg be highly appreciable.

    hi,
    what is the maximum length of your long text.
    and you can try with more than 255 chars. in the internal table it will take , if you want check it.
    i'm in 4.7 ,5.0 version, what about you ..
    please check , you can upload even more than 255.
    try
    regards
    vijay

  • Uploading EXCEL file into Internal Table Using GUI_UPLOAD

    Can any one please give me an example use of FM "GUI_UPLOAD" which to upload a EXCEL file????? (not .txt)

    Use the forum search option [GUI_UPLOAD FOR EXCEL|https://forums.sdn.sap.com/search.jspa?threadID=&q=GUI_UPLOADFOREXCEL&objID=c42&dateRange=all&numResults=15&rankBy=10001]) or sdn wiki/code gallery ([UPLOAD EXCEL|https://wiki.sdn.sap.com/wiki/dosearchsite.action?searchQuery.queryString=upload+Excel&searchQuery.spaceKey=conf_global])  - Same question already answered many time
    GUI_UPLOAD doesnt perform such conversion (Excel, Word, PDF) and wont give you a suitable result, use one of the FM mentioned above or [office integration|http://help.sap.com/saphelp_47x200/helpdata/en/21/b53138e1ba11d2bdbe080009b4534c/frameset.htm] or OLE or convert your Excel sheet to a simpler format : txt, csv, xml.
    Regards,
    Raymond

  • How can i read local excel file into internal table in webdynpro for abap a

    Could someone tell me how How can i read local excel file into an internal table in webdynpro for abap application.
    thank u for your reply

    Deep,
    File manuplations...............................
    1. At the presentation level:
    ->GUI_UPLOAD
    ->GUI_DOWNLOAD
    ->CL_GUI_FRONTEND
    2. At the application server level:
    ->OPEN DATASET : open a file in the application server for reading or writing.
    ->READ DATASET : used to read from a file on the application server that has been opened for reading
    -> TRANSFER DATASET : writing data to a file.
    -> CLOSE DATASET : closes the file
    -> DELETE DATASET : delete file
    If file is on the local PC,use the function module GUI_UPLOAD to upload it into an internal table by passing the given parameters......
    call function 'GUI_UPLOAD'
    exporting
    filename = p_file
    filetype = 'ASC'
    has_field_separator = '#'
    tables
    data_tab = t_data
    p_file : excel file path.
    t_data : internal table
    <b>reward points if useful.</b>
    regards,
    Vinod Samuel.

  • Uploading Excel file to Internal Table

    Hi,
    I need to upload an excel file into my internal table. Can we use GUI_UPLOAD Function module for this purpose? if Yes What are all the parameters we need to pass?
    Can anybody give the related function modules list.
    egards,
    Sudheer

    hi,
    check this,
    *& Report  ZTESTPROG002
    REPORT  ZTESTPROG002.
    tables: mara.
    PARAMETERS: p_file LIKE rlgrap-filename default 'C:\Documents and Settings\venkatapp\Desktop\venkat.xls'.
    data:begin of it_mara occurs 0,
         matnr like mara-matnr,
         meins like mara-meins,
         mtart like mara-mtart,
         mbrsh like mara-mbrsh,
         end of it_mara.
    SELECT matnr
           meins
           mtart
           mbrsh
           FROM mara
           INTO corresponding fields of TABLE it_mara.
    CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
      EXPORTING
        i_filename     = p_file
      TABLES
        i_tab_sap_data = it_mara.
    regards,
    venkat.

  • Uploading excell file to internal table

    HI every body,
           Here I am uploading the excel file into the internal table but it is uploading special
      charecters  ÐÏ#ࡱ#á##    like this  , what i have to do?
    my code is
    PARAMETERS:  fn LIKE rlgrap-filename OBLIGATORY.
    DATA: FN1 TYPE STRING,
         l .
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR fn. "p_file.
      CALL FUNCTION 'F4_FILENAME'
           EXPORTING
                field_name = 'FN'
           IMPORTING
                file_name  = fn.
       START-OF-SELECTION.
      FN1 = FN.
      PERFORM upload.
       FORM upload.
      CALL function 'GUI_UPLOAD'
      exporting
        filename                      = FN1
       FILETYPE                      = 'DAT'
      tables
        data_tab                      = ITAB.

    Hi Srinivasa ,
    Here is the solution with other FM . Its working fine with my application and also easy to use!
    REPORT  ztest_upload       .
    TYPE-POOLS : truxs.
    DATA : BEGIN OF i_data OCCURS 0,
              auart(4) TYPE c,
              vbeln(10) TYPE n,
              plant(4) TYPE c,
              item_no(6) TYPE c,
              qty TYPE p,
              uom_qty(3) TYPE c,
              value1 TYPE p DECIMALS 2,
              value2 TYPE p DECIMALS 2,
              text(20) TYPE c,
            END OF i_data.
    SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    PARAMETERS: p_fname LIKE rlgrap-filename OBLIGATORY.
    SELECTION-SCREEN: END OF BLOCK b1.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
        EXPORTING
          program_name = sy-repid
          static       = 'X'
        CHANGING
          file_name    = p_fname.
    START-OF-SELECTION.
      PERFORM get_excel_data.
    *&      Form  get_excel_data
          text
    -->  p1        text
    <--  p2        text
    FORM get_excel_data .
    <b>
      CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
          EXPORTING
        I_FIELD_SEPERATOR        =
            i_line_header            =  'X'
            i_tab_raw_data           =  it_raw       " WORK TABLE
            i_filename               =  p_fname
          TABLES
            i_tab_converted_data     = i_data[]    "ACTUAL DATA
         EXCEPTIONS
            conversion_failed        = 1
            OTHERS                   = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.</b>
    ENDFORM.                    " get_excel_data
    After That You can Use i_data internal table directly , you can loop on that and extract the data.
    It uploads the data same as in the excel format.
    Reward with points if usefull.
    Thanks & Regards,

  • FM to get Data from Sheet of an excel file to Internal table??

    Hello Champs!!!
    I have a problem in Excel File's Data Getting.
    There are diffrent Sheets in a single Excel file. I need data of a perticular sheet into an internal Table.
    Like there are 2 Sheets in an Excel file EXCEL1, Sheet1 & Sheet2. Both Sheet have diffrent Data in it.
    Now i only need Data of Sheet1 of this Excel FIle Excel1.
    How can i get it?
    Can you please help me in this?
    Thanks in Advance!!!!
    Girija Shankar

    Welcome to SCN
    Please search before you post next time:BDC, upload data from multi excel sheets

  • Excel File to Internal Table

    Hi,
    I need to export the content of a excel file to an internal table.
    I looked for it and I found some samples. But they opened the excel file.
    My excel file comes from upload and I have it in a xstring variable.
    The functions for excel expect for a file name, but I have the xstring only.
    Are there functions (to export the content to an internal table) that expect a xstring as a parameter?
    Thanks a lot.
    Best Regards,
    Jorge Luiz

    hi,
    I am uploading excel file. Ensure that columns in your excel are exactly present in the internal table structure that you use.
    I am using a TabDelimeted file as input for the  below mention case .
    Declare context node FILE
    with Attributes:
    Filename type String
    MimeType type String
    FILE type xstring.
    Place 'Fileupload UI element' on you view , bind DATA property to Attribute u2018FILEu2019 created in the context node.
    Create a Button lets call UPLOAD. on its click action put the following code.
    method upload_file .
      data: s_cont type string,
            x_cont type xstring,
            convt type ref to cl_abap_conv_in_ce,
            item_file type xstringval.
      data: input_string type string,
            fields  type string_table,
            fields2  type string_table,
            tbl_fields  type string_table,
            s_table type string_table,
            ls_table like line of s_table,
            ls like line of fields,
            lv_num_cols type i.
      data: lt_data type table of ZMYREC, "here
            ls_data like line of lt_data,
            lv_data type string.
      field-symbols: <wa_table> like line of s_table.
      wd_this->m_elem_file->get_attribute(
        exporting
          name =  `FILE`
        importing
          value = item_file ).
      convt = cl_abap_conv_in_ce=>create( input = item_file ).
      convt->read( importing data = s_cont ).
      "Column headers
      split s_cont at cl_abap_char_utilities=>cr_lf into table s_table.
      read table s_table into ls_table index 1.
      "Delete column header
      delete s_table index 1.
      split ls_table at cl_abap_char_utilities=>horizontal_tab into table fields.
      lv_num_cols = lines( fields ).
      refresh fields.
      loop at s_table assigning <wa_table>.
        split <wa_table> at cl_abap_char_utilities=>horizontal_tab into :
         ls_data-recordid
         ls_data-bstkd                                                                   
         ls_data-kunnr                                                                   
         ls_data-matnr                                                                   
         ls_data-candno                                                                  
         ls_data-fname                                                                   
         ls_data-inits                                                                   
         ls_data-lname                                                                   
         ls_data-gesch.                                                                   
         append ls_data to lt_data.
         clear ls_data.
      endloop.
    wd_this->m_node_data->bind_table(
       exporting
          new_items            = lt_data
          set_initial_elements = abap_true ).
    endmethod.
    I hope it helps.
    Thanx.

  • Problem in Creating excel file from internal table

    Hi Experts,
                here iam having a proble with creating an excel file from an internal table which is having around 15 records, when iam generating an excel file, its getting only upto 255 chars, after that its breaking and new record is being started in the next row. how should i get all the contents in one row of the excel or may be extended to the next line , how to resolve this issue, can anyone give me some idea or sample code.
    Thanks & Regards,
    poorna

    ur downloading to excel using a single field...then it will download only 255 chars....may be from internla table u can download the fields and the excel sheet gets downloaded with data....check below code....
    *& Report  ZETA_EXCEL_DOWNLOAD_CLIPBOARD                               *
    report  zeta_excel_download_clipboard           .
    include ole2incl.
    data:  w_cell1     type ole2_object,
           w_cell2     type ole2_object.
    *--- Ole data Declarations
    data: h_excel     type ole2_object,        " Excel object
          h_mapl      type ole2_object,        " list of workbooks
          h_map       type ole2_object,        " workbook
          h_zl        type ole2_object,        " cell
          h_f         type ole2_object,        " font
          gs_interior type ole2_object,        " Pattern
          worksheet   type ole2_object,
          h_cell      type ole2_object,
          h_cell1     type ole2_object,
          range       type ole2_object,
          h_sheet2    type ole2_object,
          h_sheet3    type ole2_object,
          gs_font     type ole2_object,
          flg_stop(1) type c.
              Internal table Declaration
    data: begin of t_excel occurs 0,
    vkorg(20) type c, "Sales Org
    vbtyp(20) type c, "Document Category
    auart(20) type c, "Document Type
    ernam(20) type c, "Created By
    vbeln(20) type c, "Document Number
    posnr(20) type c, "Item Number
    erdat(20) type c, "Created Date
    vdatu(20) type c, "Header Requested Delivery Date
    reqdat(20) type c, "Request date
    condat(20) type c, "Confirm date
    lifsk(20) type c, "Header Block
    txt30(30) type c, "Order User Status Description
    lifsp(20) type c, "Line Block
    dispo(20) type c, "MRP Controller
    dsnam(20) type c, "MRP Controller Description
    vmsta(20) type c, "Material Sales Status
    kunnr(20) type c, "Sold To
    cname(35) type c, "Sold To Name
    regio(20) type c, "State
    cufd(10) type c, "CUD
    bstnk(20) type c, "PO#
    bsark(20) type c, "Ordering Method
    matnr(20) type c, "Material
    maktx(35) type c, "Material Description
    t200(20) type c, "T200
    vtext(20) type c, "T200 Description
    matkl(20) type c, "Material Group
    zzbomind(7) type c, "BOM Indicator
    ostat(20) type c, "Order Status
    cmgst(20) type c, "CRD
    inco1(20) type c, "Incoterms
    oqty(20) type c, "Order Quantity
    pqty(20) type c, "Open Quantity
    unit(20) type c, "UOM
    onet(20) type c, "Order Value
    pnet(20) type c, "Open Value
    curr(20) type c, "Currency key
    so_bezei like tvkbt-bezei,"Sales Office
    sg_bezei like tvgrt-bezei,"Sales Group
    bname(20) type c, "Ordering Party
    contact(20) type c, "Contact Name
    telf1(20) type c, "Contact telf1
    reqqty(20) type c, "Item Request qty
    reqval(20) type c, "Item Request value
    conqty(20) type c, "Item Confirm qty
    conval(20) type c, "Item Confirm value
    zzrev(02) type c, "Revenue recognition acceptance
    bezei(20) type c, "Revenue recognition text
    vgbel(20) type c, "Reference Order for RETURNS
    0008text(255) type c, "Internal Order Comment Text
    end of t_excel.
    data: t_excel_bckord like t_excel occurs 0 with header line,
          t_excel_bcklog like t_excel occurs 0 with header line,
          t_excel_blkord like t_excel occurs 0 with header line.
      types: data1(1500) type c,
             ty          type table of data1.
      data:  it          type ty with header line,
    it_2          type ty with header line,
    it_3          type ty with header line,
             rec         type sy-tfill,
             deli(1)     type c,
             l_amt(18)   type c.
    data: begin of hex,
             tab type x,
            end of hex.
      field-symbols: <fs>      .
      constants cns_09(2) type n value 09.
      assign deli to <fs> type 'X'.
      hex-tab = cns_09.
      <fs> = hex-tab.
    data gv_sheet_name(20) type c .
    M A C R O Declaration
    define ole_check_error.
      if &1 ne 0.
        message e001(zz) with &1.
        exit.
      endif.
    end-of-definition.
    t_excel_bckord-vkorg = 'ABC'.
    t_excel_bckord-vbtyp = 'DEF'.
    t_excel_bckord-auart = 'GHI'.
    t_excel_bckord-ernam = 'JKL'.
    t_excel_bckord-vbeln = 'MNO'.
    t_excel_bckord-0008text = 'XYZ'.
    append t_excel_bckord.
    t_excel_bckord-vkorg = 'ABC1'.
    t_excel_bckord-vbtyp = 'DEF1'.
    t_excel_bckord-auart = 'GHI1'.
    t_excel_bckord-ernam = 'JKL1'.
    t_excel_bckord-vbeln = 'MNO1'.
    t_excel_bckord-0008text = 'XYZ1'.
    append t_excel_bckord.
    t_excel_bckord-vkorg = 'ABC2'.
    t_excel_bckord-vbtyp = 'DEF2'.
    t_excel_bckord-auart = 'GHI2'.
    t_excel_bckord-ernam = 'JKL2'.
    t_excel_bckord-vbeln = 'MNO2'.
    t_excel_bckord-0008text = 'XYZ2'.
    append t_excel_bckord.
    t_excel_bcklog-vkorg = 'ABC'.
    t_excel_bcklog-vbtyp = 'DEF'.
    t_excel_bcklog-auart = 'GHI'.
    t_excel_bcklog-ernam = 'JKL'.
    t_excel_bcklog-vbeln = 'MNO'.
    t_excel_bcklog-0008text = 'XYZ'.
    append t_excel_bcklog.
    t_excel_bcklog-vkorg = 'ABC1'.
    t_excel_bcklog-vbtyp = 'DEF1'.
    t_excel_bcklog-auart = 'GHI1'.
    t_excel_bcklog-ernam = 'JKL1'.
    t_excel_bcklog-vbeln = 'MNO1'.
    t_excel_bcklog-0008text = 'XYZ1'.
    append t_excel_bcklog.
    t_excel_bcklog-vkorg = 'ABC2'.
    t_excel_bcklog-vbtyp = 'DEF2'.
    t_excel_bcklog-auart = 'GHI2'.
    t_excel_bcklog-ernam = 'JKL2'.
    t_excel_bcklog-vbeln = 'MNO2'.
    t_excel_bcklog-0008text = 'XYZ2'.
    append t_excel_bcklog.
    t_excel_bcklog-vkorg = 'ABC3'.
    t_excel_bcklog-vbtyp = 'DEF3'..
    t_excel_bcklog-auart = 'GHI3'.
    t_excel_bcklog-ernam = 'JKL3'.
    t_excel_bcklog-vbeln = 'MNO3'.
    t_excel_bcklog-0008text = 'XYZ3'.
    append t_excel_bcklog.
    t_excel_blkord-vkorg = 'ABC'.
    t_excel_blkord-vbtyp = 'DEF'.
    t_excel_blkord-auart = 'GHI'.
    t_excel_blkord-ernam = 'JKL'.
    t_excel_blkord-vbeln = 'MNO'.
    t_excel_blkord-0008text = 'XYZ'.
    append t_excel_blkord.
    t_excel_blkord-vkorg = 'ABC1'.
    t_excel_blkord-vbtyp = 'DEF1'.
    t_excel_blkord-auart = 'GHI1'.
    t_excel_blkord-ernam = 'JKL1'.
    t_excel_blkord-vbeln = 'MNO1'.
    t_excel_blkord-0008text = 'XYZ1'.
    append t_excel_blkord.
    t_excel_blkord-vkorg = 'ABC2'.
    t_excel_blkord-vbtyp = 'DEF2'.
    t_excel_blkord-auart = 'GHI2'.
    t_excel_blkord-ernam = 'JKL2'.
    t_excel_blkord-vbeln = 'MNO2'.
    t_excel_blkord-0008text = 'XYZ2'.
    append t_excel_blkord.
    t_excel_blkord-vkorg = 'ABC3'.
    t_excel_blkord-vbtyp = 'DEF3'..
    t_excel_blkord-auart = 'GHI3'.
    t_excel_blkord-ernam = 'JKL3'.
    t_excel_blkord-vbeln = 'MNO3'.
    t_excel_blkord-0008text = 'XYZ3'.
    append t_excel_blkord.
    t_excel_blkord-vkorg = 'ABC4'.
    t_excel_blkord-vbtyp = 'DEF4'..
    t_excel_blkord-auart = 'GHI4'.
    t_excel_blkord-ernam = 'JKL4'.
    t_excel_blkord-vbeln = 'MNO4'.
    t_excel_blkord-0008text = 'XYZ4'.
    append t_excel_blkord.
    loop at t_excel_bckord.
    concatenate
    t_excel_bckord-vkorg
    t_excel_bckord-vbtyp
    t_excel_bckord-auart
    t_excel_bckord-ernam
    t_excel_bckord-vbeln
    t_excel_bckord-posnr
    t_excel_bckord-erdat
    t_excel_bckord-vdatu
    t_excel_bckord-reqdat
    t_excel_bckord-condat
    t_excel_bckord-lifsk
    t_excel_bckord-txt30
    t_excel_bckord-lifsp
    t_excel_bckord-dispo
    t_excel_bckord-dsnam
    t_excel_bckord-vmsta
    t_excel_bckord-kunnr
    t_excel_bckord-cname
    t_excel_bckord-regio
    t_excel_bckord-cufd
    t_excel_bckord-bstnk
    t_excel_bckord-bsark
    t_excel_bckord-matnr
    t_excel_bckord-maktx
    t_excel_bckord-t200
    t_excel_bckord-vtext
    t_excel_bckord-matkl
    t_excel_bckord-zzbomind
    t_excel_bckord-ostat
    t_excel_bckord-cmgst
    t_excel_bckord-inco1
    t_excel_bckord-oqty
    t_excel_bckord-pqty
    t_excel_bckord-unit
    t_excel_bckord-onet
    t_excel_bckord-pnet
    t_excel_bckord-curr
    t_excel_bckord-so_bezei
    t_excel_bckord-sg_bezei
    t_excel_bckord-bname
    t_excel_bckord-contact
    t_excel_bckord-telf1
    t_excel_bckord-reqqty
    t_excel_bckord-reqval
    t_excel_bckord-conqty
    t_excel_bckord-conval
    t_excel_bckord-zzrev
    t_excel_bckord-bezei
    t_excel_bckord-vgbel
    t_excel_bckord-0008text
    into it
    separated by deli.
    append it.
        clear it.
    endloop.
    loop at t_excel_bcklog.
    concatenate
    t_excel_bcklog-vkorg
    t_excel_bcklog-vbtyp
    t_excel_bcklog-auart
    t_excel_bcklog-ernam
    t_excel_bcklog-vbeln
    t_excel_bcklog-posnr
    t_excel_bcklog-erdat
    t_excel_bcklog-vdatu
    t_excel_bcklog-reqdat
    t_excel_bcklog-condat
    t_excel_bcklog-lifsk
    t_excel_bcklog-txt30
    t_excel_bcklog-lifsp
    t_excel_bcklog-dispo
    t_excel_bcklog-dsnam
    t_excel_bcklog-vmsta
    t_excel_bcklog-kunnr
    t_excel_bcklog-cname
    t_excel_bcklog-regio
    t_excel_bcklog-cufd
    t_excel_bcklog-bstnk
    t_excel_bcklog-bsark
    t_excel_bcklog-matnr
    t_excel_bcklog-maktx
    t_excel_bcklog-t200
    t_excel_bcklog-vtext
    t_excel_bcklog-matkl
    t_excel_bcklog-zzbomind
    t_excel_bcklog-ostat
    t_excel_bcklog-cmgst
    t_excel_bcklog-inco1
    t_excel_bcklog-oqty
    t_excel_bcklog-pqty
    t_excel_bcklog-unit
    t_excel_bcklog-onet
    t_excel_bcklog-pnet
    t_excel_bcklog-curr
    t_excel_bcklog-so_bezei
    t_excel_bcklog-sg_bezei
    t_excel_bcklog-bname
    t_excel_bcklog-contact
    t_excel_bcklog-telf1
    t_excel_bcklog-reqqty
    t_excel_bcklog-reqval
    t_excel_bcklog-conqty
    t_excel_bcklog-conval
    t_excel_bcklog-zzrev
    t_excel_bcklog-bezei
    t_excel_bcklog-vgbel
    t_excel_bcklog-0008text
    into it_2
    separated by deli.
    append it_2.
        clear it_2.
    endloop.
    loop at t_excel_blkord.
    concatenate
    t_excel_blkord-vkorg
    t_excel_blkord-vbtyp
    t_excel_blkord-auart
    t_excel_blkord-ernam
    t_excel_blkord-vbeln
    t_excel_blkord-posnr
    t_excel_blkord-erdat
    t_excel_blkord-vdatu
    t_excel_blkord-reqdat
    t_excel_blkord-condat
    t_excel_blkord-lifsk
    t_excel_blkord-txt30
    t_excel_blkord-lifsp
    t_excel_blkord-dispo
    t_excel_blkord-dsnam
    t_excel_blkord-vmsta
    t_excel_blkord-kunnr
    t_excel_blkord-cname
    t_excel_blkord-regio
    t_excel_blkord-cufd
    t_excel_blkord-bstnk
    t_excel_blkord-bsark
    t_excel_blkord-matnr
    t_excel_blkord-maktx
    t_excel_blkord-t200
    t_excel_blkord-vtext
    t_excel_blkord-matkl
    t_excel_blkord-zzbomind
    t_excel_blkord-ostat
    t_excel_blkord-cmgst
    t_excel_blkord-inco1
    t_excel_blkord-oqty
    t_excel_blkord-pqty
    t_excel_blkord-unit
    t_excel_blkord-onet
    t_excel_blkord-pnet
    t_excel_blkord-curr
    t_excel_blkord-so_bezei
    t_excel_blkord-sg_bezei
    t_excel_blkord-bname
    t_excel_blkord-contact
    t_excel_blkord-telf1
    t_excel_blkord-reqqty
    t_excel_blkord-reqval
    t_excel_blkord-conqty
    t_excel_blkord-conval
    t_excel_blkord-zzrev
    t_excel_blkord-bezei
    t_excel_blkord-vgbel
    t_excel_blkord-0008text
    into it_3
    separated by deli.
    append it_3.
        clear it_3.
    endloop.
      if h_excel-header = space or h_excel-handle = -1.
    start Excel
        create object h_excel 'EXCEL.APPLICATION'.
      endif.
    PERFORM err_hdl.
    *--- get list of workbooks, initially empty
      call method of h_excel 'Workbooks' = h_mapl.
    PERFORM err_hdl.
      set property of h_excel 'Visible' = 1.
    add a new workbook
      call method of h_mapl 'Add' = h_map.
    PERFORM err_hdl.
    *GV_SHEET_NAME = '1st SHEET'.
    gv_sheet_name = 'Back Orders'.
      get property of  h_excel 'ACTIVESHEET' = worksheet.
    set property of worksheet 'Name' = gv_sheet_name .
    *--Formatting the area of additional data 1 and doing the BOLD
    call method of h_excel 'Cells' = w_cell1
    exporting
    #1 = 1
    #2 = 1.
    call method of h_excel 'Cells' = w_cell2
    exporting
    #1 = 1
    #2 = 50.
    call method of h_excel 'Range' = h_cell
    exporting
    #1 = w_cell1
    #2 = w_cell2.
    *CALL METHOD OF gs_cells 'Select' .
    get property of h_cell 'Font' = gs_font .
    set property of gs_font 'Bold' = 1 .
            data l_rc type i.
      call method cl_gui_frontend_services=>clipboard_export
        importing
          data                 = it[]
        changing
          rc                   = l_rc
        exceptions
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          others               = 4.
      call method of h_excel 'Cells' = w_cell1
        exporting
          #1 = 1
          #2 = 1.
      call method of h_excel 'Cells' = w_cell2
        exporting
          #1 = 1
          #2 = 1.
    PERFORM err_hdl.
       call method of h_excel 'Range' = range
        exporting
          #1 = w_cell1
          #2 = w_cell2.
      call method of range 'Select'.
    PERFORM err_hdl.
      call method of worksheet 'Paste'.
    PERFORM err_hdl.
    CALL METHOD OF h_excel 'QUIT'.
    *GV_SHEET_NAME = '2ND SHEET'.
    gv_sheet_name = 'Backlog'.
    get property of h_excel 'Sheets' = h_sheet2 .
      call method of h_sheet2 'Add' = h_map.
    set property of h_map 'Name' = gv_sheet_name .
      get property of  h_excel 'ACTIVESHEET' = worksheet.
    *--Formatting the area of additional data 1 and doing the BOLD
    call method of h_excel 'Cells' = w_cell1
    exporting
    #1 = 1
    #2 = 1.
    call method of h_excel 'Cells' = w_cell2
    exporting
    #1 = 1
    #2 = 50.
    call method of h_excel 'Range' = h_cell
    exporting
    #1 = w_cell1
    #2 = w_cell2.
    get property of h_cell 'Font' = gs_font .
    set property of gs_font 'Bold' = 1 .
      call method cl_gui_frontend_services=>clipboard_export
        importing
          data                 = it_2[]
        changing
          rc                   = l_rc
        exceptions
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          others               = 4.
      call method of h_excel 'Cells' = w_cell1
        exporting
          #1 = 1
          #2 = 1.
      call method of h_excel 'Cells' = w_cell2
        exporting
          #1 = 1
          #2 = 1.
    PERFORM err_hdl.
       call method of h_excel 'Range' = range
        exporting
          #1 = w_cell1
          #2 = w_cell2.
      call method of range 'Select'.
    PERFORM err_hdl.
      call method of worksheet 'Paste'.
    *GV_SHEET_NAME = '3rd SHEET'.
    gv_sheet_name = 'Blocked Orders'.
    get property of h_excel 'Sheets' = h_sheet3 .
      call method of h_sheet3 'Add' = h_map.
    set property of h_map 'Name' = gv_sheet_name .
      get property of  h_excel 'ACTIVESHEET' = worksheet.
    *--Formatting the area of additional data 1 and doing the BOLD
    call method of h_excel 'Cells' = w_cell1
    exporting
    #1 = 1
    #2 = 1.
    call method of h_excel 'Cells' = w_cell2
    exporting
    #1 = 1
    #2 = 50.
    call method of h_excel 'Range' = h_cell
    exporting
    #1 = w_cell1
    #2 = w_cell2.
    get property of h_cell 'Font' = gs_font .
    set property of gs_font 'Bold' = 1 .
      call method cl_gui_frontend_services=>clipboard_export
        importing
          data                 = it_3[]
        changing
          rc                   = l_rc
        exceptions
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          others               = 4.
      call method of h_excel 'Cells' = w_cell1
        exporting
          #1 = 1
          #2 = 1.
      call method of h_excel 'Cells' = w_cell2
        exporting
          #1 = 1
          #2 = 1.
    PERFORM err_hdl.
       call method of h_excel 'Range' = range
        exporting
          #1 = w_cell1
          #2 = w_cell2.
      call method of range 'Select'.
    PERFORM err_hdl.
      call method of worksheet 'Paste'.
    *--- disconnect from Excel
      free object h_zl.
      free object h_mapl.
      free object h_map.
      free object h_excel.

Maybe you are looking for