Scenario: To upload an Excel file using Webdynpro application.
Procedure:
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 attributes for the Data_tab node like below.
8. Double click on View. We would be designing the screens of our application with the following elements:
1. File Upload
2. Button
3. Table
Insert Element file_upload for uploading FILE.
9. Insert Element button.set its Text property as UPLOAD.
Create A new action for button.
Insert an Element TABLE and does binding by right clicking on it and select Create binding.
By pressing Enter button Binding is done.
Set Column ' s header property as below.
The same-on-the-loop Set header property is the age column too.
Select element File upload and set its DATA property as shown below:
Now select View ' s method list
Double click on Onaction_upload method. Write a code as given below.
METHOD Onactionon_upload.
TYPES:
BEGIN of Str_itab,
name (Ten) TYPE C,
Age (Ten) 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 to l_string.
SPLIT l_string at Cl_abap_char_utilities=>horizontal_tab to 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).
EndMethod.
Activate The program and create a application by right clicking and save it.
. Test Application.
Output:
Click on Browse.select The EXCEL file with the Columns.
Click on UPLOAD button.and Excel data would be displayed like below.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
To upload an Excel file using Webdynpro application.