How to upload  a excel file in webdynpro? Please help!

Hi Experts,
    I have a requirement where I need to upload a  excel file in my webdynpro for ABAP report.
    I have used the fileupload UI element in my view and a upload button.
    However when I test the application I found that it is getting file data as some junk value like below:
    ###ࡱ#################>########################################################################################################################################################################################################################################
  Why is that so?
  Is there any limitation with fileuplaod reading excel file?
  Do i have to use any encoding option?
  What is the alternative option to read excel file in ABAP webdynpro?
Thanks
Gopal

Hi,
Check this.. Write this code in Upload button 's method
********** Reading data from flat file ****************
  DATA lo_el_context TYPE REF TO if_wd_context_element.
  DATA ls_context    TYPE wd_this->element_context.
  DATA lv_datasource type xstring.
* get element via lead selection
  lo_el_context = wd_context->get_element(  ).
* get single attribute
  lo_el_context->get_attribute(
    EXPORTING
      name =  `DATASOURCE`
    IMPORTING
      value = lv_datasource ).
   CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
    EXPORTING
*   FROM_CODEPAGE       = '8500'
      IN_XSTRING          = LV_DATASOURCE
*   OUT_LEN             = '1'
   IMPORTING
     OUT_STRING          = LV_STRING.
SPLIT LV_STRING AT CL_ABAP_CHAR_UTILITIES=>NEWLINE INTO TABLE IT_STR.
  LOOP AT IT_STR INTO LV_STRING.
    SPLIT LV_STRING AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO TABLE FIELDS.
    READ TABLE FIELDS INTO LV_FIELD INDEX 1.                 " Reading 1st field
    ls_header-STATU = LV_FIELD.
     clear LV_FIELD.
    READ TABLE FIELDS INTO LV_FIELD INDEX 2.                " Reading 2st field
     ls_header-LIFNR = LV_FIELD.
     clear LV_FIELD.
    READ TABLE FIELDS INTO LV_FIELD INDEX 3.
     ls_header-BSART = LV_FIELD.
     clear LV_FIELD.
    READ TABLE FIELDS INTO LV_FIELD INDEX 4.
     ls_header-EKORG = LV_FIELD.
     clear LV_FIELD.
    READ TABLE FIELDS INTO LV_FIELD INDEX 5.
     ls_header-EKGRP = LV_FIELD.
     clear LV_FIELD.
    READ TABLE FIELDS INTO LV_FIELD INDEX 6.
     ls_header-BUKRS = LV_FIELD.
     clear LV_FIELD.
     APPEND wa to it.
    append ls_header to lt_header.
    clear: ls_header,wa.
    endloop.
    lo_nd_header->BIND_TABLE( lt_header ).
Thanks,
Ramesh
Edited by: Rameshkumar Raamasamy on Dec 20, 2010 11:16 AM

Similar Messages

  • How to upload an excel file using ABAP.

    Hi,
    Can anyone please help me in understanding how to upload an excel file using ABAP.
    Thanks!!

    http://diocio.wordpress.com/2007/02/12/sap-upload-excel-document-into-internal-table/
    check the link
    TYPES: Begin of t_record,
    name1 like itab-value,
    name2 like itab-value,
    age   like itab-value,
    End of t_record.
    DATA: it_record type standard table of t_record initial size 0,
    wa_record type t_record.
    DATA: gd_currentrow type i.
    *Selection Screen Declaration
    PARAMETER p_infile like rlgrap-filename.
    *START OF SELECTION
    call function ‘ALSM_EXCEL_TO_INTERNAL_TABLE’
    exporting
    filename                = p_infile
    i_begin_col             = ‘1′
    i_begin_row             = ‘2′  “Do not require headings
    i_end_col               = ‘14′
    i_end_row               = ‘31′
    tables
    intern                  = itab
    exceptions
    inconsistent_parameters = 1
    upload_ole              = 2
    others                  = 3.
    if sy-subrc <> 0.
    message e010(zz) with text-001. “Problem uploading Excel Spreadsheet
    endif.
    Sort table by rows and colums
    sort itab by row col.
    Get first row retrieved
    read table itab index 1.
    Set first row retrieved to current row
    gd_currentrow = itab-row.
    loop at itab.
      Reset values for next row
    if itab-row ne gd_currentrow.
    append wa_record to it_record.
    clear wa_record.
    gd_currentrow = itab-row.
    endif.
    case itab-col.
    when ‘0001&#8242;.                              “First name
    wa_record-name1 = itab-value.
    when ‘0002&#8242;.                              “Surname
    wa_record-name2 = itab-value.
    when ‘0003&#8242;.                              “Age
    wa_record-age   = itab-value.
    endcase.
    endloop.
    append wa_record to it_record.
    *!! Excel data is now contained within the internal table IT_RECORD
    Display report data for illustration purposes
    loop at it_record into wa_record.
    write:/     sy-vline,
    (10) wa_record-name1, sy-vline,
    (10) wa_record-name2, sy-vline,
    (10) wa_record-age, sy-vline.
    endloop.

  • CRM ABAP How to upload an Excel file into an internal table?

    How to upload an Excel file using GUI_UPLOAD?? what should be the values of the parameters? The function modules ALSM_EXCEL_TO_INTERNAL_TABLE and KCD_EXCEL_OLE_TO_INT are not present in CRM. Please suggest me a way out!

    Hi saurabh,
    you can try the folowing sample..
    and make modifications according to your requirement..
    TYPE-POOLS: truxs.
    DATA: i_text_data TYPE truxs_t_text_data,
    v_filename_string TYPE string.
    DATA: BEGIN OF itab OCCURS 0,
    Name(30),
    Phone(15),
    Fax(500).
    DATA: END OF itab.
    PARAMETERS: p_file LIKE rlgrap-filename.
    START-OF-SELECTION.
    v_filename_string = p_file.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = v_filename_string
    filetype = 'ASC'
    has_field_separator = 'X'
    * HEADER_LENGTH = 0
    * READ_BY_LINE = 'X'
    dat_mode = ''
    * IMPORTING
    * FILELENGTH =
    * HEADER =
    TABLES
    data_tab = i_text_data
    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.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
    i_field_seperator = 'X'
    * I_LINE_HEADER =
    i_tab_raw_data = i_text_data
    i_filename = p_file
    TABLES
    i_tab_converted_data = itab
    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.
    this is a sample code that uploads a excel file using GUI_UPLOAD, but uses another function module to convert that uploaded data into an internal table..
    regards
    satesh

  • How to upload normal excell file to ztable

    Hi All there,
    Can anybody tell me how to upload normal excell file to ztable directly.
    pl provide detail coding
    Regards
    Sagar

    Hi Sagar,
       first upload the excel data into your internal table using a FM than upload the data to your ZTABLE using BDC.
    parameters:
      p_file type rlgrap-filename          " File name
      data:
        lw_file  type string.              " File Path
    data:
      t_bdcdata type
       standard table
             of bdcdata,
      fs_bdcdata type bdcdata.             " Work area for bdcdata
    * Messages of call transaction
    data:
      t_messtab type
       standard table
             of bdcmsgcoll,
      fs_messtab type bdcmsgcoll.          " Work area for messtab
    at selection-screen on value-request for p_file.
      call function 'F4_FILENAME'
       exporting
         program_name        = syst-cprog
         dynpro_number       = syst-dynnr
         field_name          = ' '
       importing
         file_name           = p_file.
      lw_file = p_file.
      call function 'GUI_UPLOAD'
        exporting
          filename                    = lw_file
          filetype                    = 'ASC'
          has_field_separator         = 'X'
          dat_mode                    = 'X'
        tables
          data_tab                    = t_final_data
        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.
      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 SY-SUBRC <> 0
      if t_final_data is initial.
        message 'File not found'(003) type 'E'.
      endif.                               " IF T_FINAL_DATA IS INITIAL
    end-of-selection.
      perform upload_0585_data_using_bdc.  " populate the bdcdata table using tcode SHDB
      call transaction 'PA30' using t_bdcdata
                               mode 'A'
                           messages into t_messtab.
    form upload_0585_data_using_bdc.
      loop at t_final_data into fs_final_data.
    perform bdc_field       using 'Q0585-ACNTR(07)'
                                   w_curr.
    perform bdc_field       using 'Q0585-ACOPC'
                                   lw_flag.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=UPD'.
    perform bdc_dynpro      using 'MP058500' '2000'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '/EBCK'.
    perform bdc_dynpro      using 'SAPMP50A' '1000'.
    endloop.
    *        Start new screen                                              *
    form bdc_dynpro using program dynpro.
      clear fs_bdcdata.
      fs_bdcdata-program  = program.
      fs_bdcdata-dynpro   = dynpro.
      fs_bdcdata-dynbegin = 'X'.
      append fs_bdcdata to t_bdcdata.
    endform.                               " Form bdc_dynpro using program...
    *        Insert field                                                  *
    form bdc_field using fnam fval.
        clear fs_bdcdata.
        fs_bdcdata-fnam = fnam.
        fs_bdcdata-fval = fval.
        append fs_bdcdata to t_bdcdata.
    endform.                               " Form bdc_field using fnam fval
    With luck,
    Pritam.

  • How to read the excel file using webdynpro abap?

    Hi,
    how to read and modify excel file using webdynpro abap?
    Regards,
    Pavani

    For reading excel file follow the steps :
    1. Use a File upload UI element and bind it with xstring.
    2. Now your excel will be uploaded and stored in Xstring.
    3. Convert Xstring to String data using FM 'HR_KR_XSTRING_TO_STRING'.
    4. Now split the string at new line so as to make an internal table .
      Ex . SPLIT l_string  AT cl_abap_char_utilities=>newline INTO TABLE it_table.
      here it_table is type table of string.
    5.now loop at the internal table and separate the content of this table separated by tab.
      Ex. SPLIT wa_table AT cl_abap_char_utilities=>horizontal_tab INTO TABLE it_new.
    it_new type string_table.
    6. For more info , refer this thread :
    Re: How to upload excel file in Webdynpro application using ABAP

  • How to read an excel file in webdynpro application

    Hello Experts,
    Can someone please tell me how to read an excel file in a webdynpro application?
    There is a tutorial for how to write contect into an excel, but i want to read the excel.
    Can someone help please !!
    Thanks and Kind regards,
    G.Singh.

    Hello Experts,
    I have done all the given above.
    I want to read a excel file from KM. My code is as below
    ResourceContext resourceContext = buildResourceContext();
    IResourceFactory resourceFactory = ResourceFactory.getInstance();
    RID pathRID = RID.getRID("/documents/ExcelReport.xls");     
    IResource resource =     resourceFactory.getResource(pathRID, resourceContext);
    Workbook wb = Workbook.getWorkbook(resource.getURI().getPath());
    Sheet sh = wb.getSheet(0);
    int columns = sh.getColumns();
    int rows = sh.getRows();
    wdComponentAPI.getMessageManager().reportSuccess(" Rows: " + rows);
    wdComponentAPI.getMessageManager().reportSuccess(" Columns: " + columns);
    This does not give me the excel file form the KM
    Can you please just what i can do at this point?
    Kind Regards,
    G Singh.

  • Can anybody help how to upload an excel file into sap-crm urgent

    hi guys,
    i need the right function module to upload the excel file from the presentation server in to sap-crm.
    1) I know we use the function module 'ALSM_EXCEL_TO_INT_TABLE' in sap-r/3 but this function module is not exist in sap-crm.
    2) i tried with the function moduel 'GUI_UPLOAD' but its not uploading correctly i am gettting hases(#).
    Please can any one provide the right function module to upload the excel into sap-crm with an sample code.
    thanks
    viswa guntha

    Hi Visma,
    Please check this link for sample custom FM.
    Re: function mudule for MS excel file to sap crm
    Hope this will help.
    Regards,
    Ferry Lianto
    Please reward points if helpful as away to say thanks.

  • How to upload a pdf file using webdynpro abap

    Hi Experts,
    I need to upload pdf files using webdynpro abap.my question is where to upload this files and how to upload this files, and how to display this pdf file.
    Please Provide Requried Information.
    Waiting for Reply.
    Thanks & Regards.
    Bhushan.

    Hi,
    There is a UI element with the type 'File Upload'.
    You can use that in your view.
    For further details and coding, please refer to
    [http://www.****************/Tutorials/WebDynproABAP/Upload/Page1.htm]
    Hope this helps you.
    Regards,
    Dolly

  • How to upload a excel file using BDC

    how should i upload a file using BDC
    i have downloaded a excel file containing the values of  table A006 a X server.
    now i hav to upload it into new server Y server using BDC , how do i do it?
    wat all things one shud consider ?

    Hi,
    This is very simple, follow the below mention steps to do so:
    1.Declare an internal table having same structure as db table, but take all the fields type as 'C' and length same as defined in the table.
    TYPES:BEGIN OF it,
      key(20) TYPE c,
      indicator(20) TYPE c,
      bldat(20) TYPE c,"bkpf-bldat
      budat(20) TYPE c,"bkpf-budat
      END OF it.
    DATA: itab TYPE STANDARD TABLE OF it,
          wa TYPE it.
    2.Include TRUX as type pool and declare a variable of type trux_t_text_data to be passed in the FM that actually reads data from excel sheet into above declared intrenal table.
    TYPE-POOLS: truxs.
    DATA: it_raw TYPE truxs_t_text_data.
    3. Call the FM 'TEXT_CONVERT_XLS_TO_SAP' and pass the file name and the internal table name into the parameter
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
        EXPORTING
    *    I_FIELD_SEPERATOR          = 'X'
         i_line_header              = 'X'
          i_tab_raw_data             = it_raw
          i_filename                 = p_file "name of the excel file
        TABLES
          i_tab_converted_data       = itab[] "internal table where data will be stored
       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.
    4. loop at internal table and modify the ztable/dbtable where data to be upload .
    Hope this solve your problem.
    Pooja

  • How to upload all excel files data from one folder into internal table.

    Dear All,
    I have one requirement, It is like I want to upload the frontend file data into my internal table, But here my scenario is;
    If I have one folder ( Called : Temp) in my frontend system, in this folder ( Called : Temp)  I have 100 excel files. In each excel file I have some 1000u2019s of entries. All these data of every file I want to take into my internal table.
    If I have one file I can go for, CALL METHOD cl_gui_frontend_services=>file_open_dialog and then upload method to upload. But I want to take all these excel files from that folder at a time, is there any class or any thing is there..? plz help..
    Thanks...
    Edited by: satishsuri on Jan 11, 2011 9:33 AM

    Hi satishsuri ,
    You will have to use 3 methods together :
    CALL METHOD cl_gui_frontend_services=>directory_browse "Browse the Directory
    CALL METHOD cl_gui_frontend_services=>directory_list_files "Get all the files from the directory
    CALL METHOD cl_gui_frontend_services=>gui_upload "Upload each file in a loop
    Example:
    TYPES: BEGIN OF ty_data,
             line TYPE string,
          END OF ty_data.
    DATA: str_file TYPE string,
          str_dir TYPE string,
          it_file_table TYPE STANDARD TABLE OF file_info,
          wa_file_table TYPE file_info,
          v_count TYPE i,
          it_data TYPE STANDARD TABLE OF ty_data,
          wa_data TYPE ty_data.
    CALL METHOD cl_gui_frontend_services=>directory_browse
      CHANGING
        selected_folder = str_dir.
    CALL METHOD cl_gui_frontend_services=>directory_list_files
      EXPORTING
        directory  = str_dir
      CHANGING
        file_table = it_file_table
        count      = v_count.
    LOOP AT it_file_table INTO wa_file_table.
      CONCATENATE str_dir wa_file_table-filename INTO str_file SEPARATED BY '\'.
      CALL METHOD cl_gui_frontend_services=>gui_upload
        EXPORTING
          filename = str_file
          filetype = 'ASC'
        CHANGING
          data_tab = it_data.
      LOOP AT it_data INTO wa_data.
        WRITE : / wa_data-line.
      ENDLOOP.
      ULINE.
    ENDLOOP.
    Regards,
    Jovito

  • Excel File is corrupt, Please help

    I have an excel file that has recently become corrupt. I was working on this file from last 3 years without any problem. It is helpful if someone know easy and quick method to recover data from it.  
    All other files are working fine. 

    Hi Peter,
    It looks your file is corrupt, try to repair the corrupted file manually:
    On the File tab, click Open.
    In the Open dialog box, select the corrupted workbook that you want to open.
    Click the arrow next to the Open button, and then click Open and Repair.
    To recover as much of the workbook data as possible, click Repair.
    P.S: It might possible that you have mailed this workbook to someone previously. If file is there then download it.
    Good Luck!!!

  • How to download a .txt file correctly. Please help as soon as possible!

    Hi everybody,
    I need to implement download that prompts the user to save a txt file.
    If I use "attachment" in response.setHeader, my IE 5.50 crashes after downloading 4 to 6 files consecutively.
    I tried to change the response.setHeader to "inline" and the response.setContentType to "application/zip" or "application/UNKNOWN", and although it works in IE 5.50, my IE 5.00 never prompts asking to save the file, it always opend the file into the browser window, and I need a prompt.
    I saw many questions related with this problem in this forum, but none that answered accurately to this problem.
    Please help as soon as possible, I dont have much time to do this.
    Thank you very much.

    Thank you gypsy617 for your reply, but it still does not work!
    I made all the changes to
    1)res.setContentType("application/x-download");
    2)res.setHeader("Content-Disposition", "attachment; filename=" + filename);
    3)OutputStream out = res.getOutputStream();
    4)returnFile(filename, out);
    5) and i sent the file content as bytes
    But the real problem is regarding the "attachment" option !!!
    In my application, in the same page, there are a lot of links that users can download, each one a link that calls a action. It works well for the first downloaded file, for the second, ..., and then, when we try to download the file number 4 or 5, IE says that there is a problem and it must close (and it asks us to send a report - something like "Exception Information Code:0xc0000005 Flags:0x00000000 Record:0x0000000000000000 Address:0x0000000077a7710a").
    I know that the problem is the "attachment" because if I choose "inline", IE never crashes. But i really need a Save As dialog, the txt files cannot be openned into the browser window, so i cant use inline.
    Any idea?
    Thank you.

  • Pls tell me how to upload from excel file to database.

    hello,experts,
    I want to upload data from excel local file to database table created by myself.when I use function
    CALL FUNCTION 'GUI_DOWNLOAD'
    the data in the internal table just become error code data that can not understand.
    who can help me out?
    thanks.

    Hi,
    1st copy the values in XLS into internal table by using function Module:-
    call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    exporting
    filename = file_name<it is file path of u r XLS>
    i_begin_col = 1
    i_begin_row = 1
    i_end_col = 250
    i_end_row = 1
    tables
    intern = itab<this structure is same like u r database table>
    exceptions
    inconsistent_parameters = 1
    upload_ole = 2
    others = 3.
    if sy-subrc 0.
    then modify or insert these values to database from internal table:-
    modify <DB table> from itab accepting duplicate keys.
    for file popup use :
    at selection-scree on <screen field>.
    call function 'F4_FILENAME'
    exporting
       program = sy-cprog
       dynnr     = sy-dynnr
    importing
       filename = zfilename.
    here zfilename of type rlgrap-filename.
    and pass this as path in ASLA_EXCEL_TO_INTERNAL_TABLE
    Edited by: vijay Mekala on Dec 29, 2007 12:45 PM

  • Creating Excel Files From Java Please Help I am Lost

    I am doing a project in jbuilder an using a mysql db on a remote server what i want to do is to generate reports in ms excel after executing a query for example if I search for students aged 20+ I want to generate an excel sheet with all the records ....
    Does anyone knows how to do that or is there a good tutorial on the web that explains this issue
    Your help is appreciated many thanks...........

    Spooling the data in a comma "," delimited file is actually a good option. I have used this a couple of times and works like a charm. Spoooling the file is easy because it is a normal text file. Do remember to name the file as <something>.csv - files with this extension is linked to Excel in Windows.

  • How to Upload the excel flat file in LSMW

    Hi all,
    Can any one plz Help me,
    How to Upload a excel file format by suing the lsmw .
    Regadrs.
    [email protected]
    Upender..
    Edited by: Upender Reddy on Sep 12, 2008 8:37 AM

    Hi,
    In 7 th step of LSMW we need to specify the file ie flat file.
    In this step you describe all files to be used in the following steps:
    · Your legacy data on the PC and/or R/3 server
    · The file for the read data
    · The file for the converted data.
    As your legacy data is on the PC: ie your excel file that is tab delimited or comma delimited.
    here give ur file name, description , click data from one src structure, then delimiter is tabulator if so, in file structure click both check boxes if in ur flat file ur first row is column, file type is record end indicator, code page ASCII and conitnue that's it.
    you can go through this link very useful :
    ****************/Tutorials/LSMW/LSMWMainPage.htm.
    thanx.

Maybe you are looking for

  • The big 7200rpm vs 5400 rpm debate

    I'm planning to buy a 2.2ghz Macbook Pro. I would get one with 2Gb of RAM and the 160Gb 7200 rpm HD, but now someone I know had already bought the standard config (2.2 Ghz, 2Gb, 120 5400 rpm) through his company but he's selling it because he'd rathe

  • HT201303 how to change my payment card?

    how can I change my payment card details?

  • Strange graphics while playing cube

    I have a proplem with cube (which I might add to the community repo). When I play it, the graphics are terrible. The red and blue colors are the dominant ones. The graphics also looks very pixelized.  I tried to take a screenshot with cube running in

  • HT1544 Snow leopard

    I would like to update my OS X 10.5.8 to OS X 10.6 Snow Leopard. I missed my chance to get the free snow leopard update when I changed to iCloud. Is there a way to still get this?

  • Upgrading RAM to 8 GB

    I just bought a 13" MacBook Pro (this one: http://store.apple.com/us/configure/MC724LL/A?mco=MjEyOTY3MTE). I currently have 4 GB of RAM. I'd like to upgrade to 8 GB. Do I only need to buy one 4 GB stick or do I need to buy two? It looks like there ar