cancel
Showing results for 
Search instead for 
Did you mean: 

Rectifying the garbage value problem, while uploading excel in web Dynpro application -

Former Member
0 Kudos

Gejo john , LnT Infotech , 26 Feb 2012.

Most of the time it is required to upload some excel data  into web dynpro application to show it in Table Ui element.

For example a simple example can be :

Upload a excel with two column (Name and age), into the web dynpro application and should be displayed ti user in a tabular format.

Challenge:

The requirement seems to be simple , but while doing it most of the time, ddeveloper gets garbage values in the final as output instead of the data he/she has entered into the excel.

Reason :

Each web dynpro application has its own excel format, which is specific to the respective application only.

Now when you  try to upload the excel into the web dynpro application , some time it may happen that both of these format (web dynpro application format and the format of excel which needs to be uploaded) may differ.

In such situation the developer may get garbage values in the final output instead of the actual data.

Some time it may also possible that the developer is getting the proper results , but when the development is moved to next system , it is getting failed .

this is because in format in the first systems matches with the excel format of the application , on the other hand it is not matching  in the second case as the system is different so it may be possible that in this system the excel format is different.

Solution :

The easiest and the reliable solution is to first download a blank excel template from the web dynpro application , and then ask the user to fill the downloaded excel and then upload the same format back to the application.

So in this way , we can be sure that the functionality will be working fine , irrespective of the system.

Download Excel template :

Excel template can be download to the system by using the below sample code .


  
DATA xtext         TYPE xstring.


   wdr_task
=>client_window->client->attach_file_to_response(
*       path to the word file
      i_filename
= 'WDP.xls'
*       String Variable
*      i_content
xtext
*       File Type
      i_mime_type
= 'EXCEL' ).

this will download a blank excel on the system , if you want to put some header data in the first line , like (Name and age ), you can make use of the string variable -_content.

Once the excel is downloaded , it has to be uploaded back to the web dynpro application

Upload Excel to application :

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.

*get single attribute
  wd_context
->get_attribute(
  
EXPORTING
       name
`FILE_NAME`
  
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( 'EXCEL_DATA' ).
  lo_nd_sflight
->bind_table( t_table1 ).

Hope the document was useful to you,

Thanks,

Gejo john

Accepted Solutions (0)

Answers (5)

Answers (5)

former_member188217
Active Participant
0 Kudos

Hi Gejo,

I tried the above approach , but still getting garbage value. Kindly advice.

Thanks,

Anju

0 Kudos

Hi,

Check the excel file format you are using. The solution will not work for excel files with .xlsx extension.

former_member198064
Participant
0 Kudos

This message was moderated.

Former Member
0 Kudos

Thanks Gejo,

I tried a lot of option but your tric really works Thankyou very much for sharing such a nice concept

Former Member
0 Kudos

thanks .

dnayak
Explorer
0 Kudos

Hi John

Thanks . Very good info.

Former Member
0 Kudos

Hi John,

This is the nice solution. It is working fine and after struggling a lot it seems achievable. I tried all the solutions given in many threads but i was getting garbage value. I tried with logic given by you and i got the data into internal table.

Thanks

Aditya