cancel
Showing results for 
Search instead for 
Did you mean: 

Upload Excel File in Webdynpro ABAP

Former Member
0 Kudos

Hello,

I am trying to upload an excel file into webdynpro ABAP application into a table to display it's contents. I am using the following link for the same:

I declared datasource as 'xstring' rather than string as declared in the link because according to the code written in the Action it should be 'xstring'.

Then when i run the application it shows up junk data rather than Excel file contents. Even though i declared datasource attribute as string it didn't work.

Please help.

Accepted Solutions (0)

Answers (1)

Answers (1)

gill367
Active Contributor
0 Kudos

HI

Reading the content from an excel file is not feasible.

You need to save it as Tablimited text file or CSV text file.

then upload it using the FileUpload UI Element and read the content in the xstring attribute.

then convert it into String using utility function module and

then to some split operation on the string data and save them in the table as desired.

thanks

sarbjeet singh

Former Member
0 Kudos

This is what I did exactly:

I am trying to upload an excel file into webdynpro ABAP application into a table to display it's contents.

I created a datasource attribute of type 'xstring' .A node called DATA_TAB with 2 attributes Name and Age.

A file Upload UI Element, a Table and button.

The data property of the FileUpload UI Element is bound to the datasource attribute. The Table is binded to the node DATA_TAB.

Then created action 'Upload' bound it to the onAction property of the Button and wrote the following code in the Action :

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,

lo_nd_sflight TYPE REF TO if_wd_context_node,

lo_el_sflight 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

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.

ENDLOOP.

lo_nd_sflight = wd_context->get_child_node( 'DATA_TAB' ).

lo_nd_sflight->bind_table( t_table1 ).

Then when i run the application it shows up junk data in the Table rather than Excel file contents. Even though i declared datasource attribute as string it didn't work.

Looking forward to your reply.

gill367
Active Contributor
0 Kudos

The code is fine.

But it wont work with the file having .xls or xlsx extension.

Open the xls file. go to file ->save as then select 'Text (Tab delimited) (*.txt)' and click on save.

then upload the file created with .txt extension.

thanks

sarbjeet singh

Former Member
0 Kudos

Thanks it works now. But what's the reason for the same.?

gill367
Active Contributor
0 Kudos

The reason is that xstring generated for the xls can not converted back to proper string by any function in abap till now.

may be in future something might come up.

thanks

sarbjeet singh