Skip to end of metadata
Go to start of metadata

Scenario: To create WebDynpro Application. We would accept an input value from the user as an excel file name.By using Browser we will select Excel File with path.After clicking on UPLOAD button it will upload that excel file data and it will store data in an internal table and it will display data on that page.


1.      Go to transaction SE80.
2.      Select "WebDynpro Comp./Intf" from the list.
3.      Create a new WebDynpro component by the name ZEXCEL_UPLOAD.

4.      Double-click on the View. Select Context Tab.
5.      Create an attribute as shown below.


6.      Create a node as shown below:


 7.   Create an attributes for the DATA_TAB node like below.


 Create Attribute Age.

8. Double click on View. We would be designing the screen of our application with the following elements:
File Upload
Insert Element FILE_UPLOAD for Uploading File.


9.  Insert Element Button.Set its Text property as UPLOAD. 

Create a new action for button.

 10. Insert an Element TABLE and do binding by right clicking on it and select Create Binding.          
       By pressing Enter button Binding will be done.
11. Set Column's header property as below.

Same way set header property for the Age column too.
 12. Select element File upload and set its DATA property like below.

13. Now select View's method list


14. Double click on ONACTION_UPLOAD method. Write a code as given below.
METHOD onactionon_upload .
       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,
         lo_nd_data TYPE REF TO if_wd_context_node,
         lo_el_data TYPE REF TO if_wd_context_element,
         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
      name =  `DATASOURCE`
      value = l_xstring ).
      in_xstring = l_xstring
      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.

lo_nd_data = wd_context->get_child_node( 'DATA_TAB' ).
lo_nd_data->bind_table( T_TABLE1 ).

15.  Activate the Program and Create an application by right clicking and save it.


16. Test Application.



Click on Browse.Select An EXCEL file with two Columns.
Click on UPLOAD Button.and Excel data will be displayed like below.



  1. Unknown User (ah3fpy7)

    Hello, Twinkal.
    I see this special atribut cl_abap_char_utilities=>horizontal_tab.
    It mean that you upload txt file with tab separator.
    Is it right?
    I try to upload xls file and it didn't work, but work great with
    txt file.
    Regards, Marat.

  2. Unknown User (sh4u0c4)

    thanks Twinkal,

    it works with tab delimited well, and how to work with EXCEL with correct content parsing as column and row?



  3. Unknown User (c7t8u7x)

    Thanks a lot Twinkal, this is very well described and was very helpful for me.

    There is one finding, which should be interesting according to coding line, which splits the complete string into the lines via Line-Delimiter:

    --> SPLIT l_string  AT cl_abap_char_utilities=>newline INTO TABLE i_data.

    Within the Excel files, I have tested right now with the coding given above, I found that the Line-Delimiter is the two-character control-sign "cl_abap_char_utilities=>cr_lf" instead of the one-charater "cl_abap_char_utilities=>newline".

    Does anybody know, in which Excel-Versions which control-sign is used as line-delimiter?

    More Details and Background of my question:

    Since the two-character control-sign "cl_abap_char_utilities=>cr_lf" also contains the "cl_abap_char_utilities=>newline", the above given coding seems to work also in my cases. However, there is the serions issue, if ALT-Enter is used within one Excel cell, because this appears also as "cl_abap_char_utilities=>newline" within the Text File and so this leads to wrongly additional lines if "cl_abap_char_utilities=>newline" is used as line delimiter.

    So the propsal is to use the following code-line instead of the above code-line:

    --> SPLIT l_string  AT cl_abap_char_utilities=>cr_lf INTO TABLE i_data.

    With this, I have no issue with the Excels, I am currently testing. However, I assume that the above given coding from Twinkal was correct when Twinkal posted this, so it was correct for older Excel Versions. And then I would have a problem with my coding proposal above and the correct coding seems to be something like:

    FIND cl_abap_char_utilities=>cr_lf IN l_string.
    IF sy-subrc 0.
       SPLIT lv_data_string AT cl_abap_char_utilities=>cr_lf INTO TABLE i_data.
       SPLIT lv_data_string AT cl_abap_char_utilities=>newline INTO TABLE i_data.

    Best regards


  4. Former Member

    Hi All,

    I am getting junk values in my alv output by using the above code:

    Can anyone suggest something..?