cancel
Showing results for 
Search instead for 
Did you mean: 

Upload a Excel file to SAP DB table and display it in Browser using ABAP webdynpro

Former Member
0 Kudos

Dear Exports

I have create a webdynpro application to upload a excel file and display the data on the brower. But when I run the application it shows up junk data in the Table rather than Excel file contents whose screenshot is below.

I have create the application by using the following steps.

1. I have create a webdynpro component using SE80.

2. Withen the context tab of view I have create 1 node with 2 attribute(name, age) and another attribute(datasource)

3. withen the layout tanb of the view i have create 3 UI Elements like

4. Withen the method "ONACTION_UPLOAD" I have put the following codes.

   TYPES : BEGIN OF str,
          name(10) TYPE c,
          age(10) TYPE c,
          END OF str.

DATA : t_table1 TYPE STANDARD TABLE OF str,
         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,
         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.

wd_context->get_attribute(
    EXPORTING
      name `DATASOURCE`
    IMPORTING
      value = l_xstring ).
  CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'


    EXPORTING
*     FROM_CODEPAGE       = '8500'
      IN_XSTRING          l_xstring

*     OUT_LEN             =
   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_data = wd_context->get_child_node( 'DATA_TAB' ).
lo_nd_data->bind_table( t_table1 ).

5. Now I have Save and acivate the component

6. When I have run the application by uploading the excel file it will display the junk  data.

First i have tested a excel file whose format is .txt. same Junk data have displayed.

If i am taking the file as .csv extension then also same output junk data will diplayed.

I am not able to understand what is the actual file format i will take so that the actual excel data will be displayed.Is there any mistakes in my coding.

Can anyone please help me to solve this problem. If i am not able to solve it then I can't uplode excel file which contains customer master data of my organisation.

So Please help me to solve my issue.

Thanks and regards

Rashmita Parida 

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

Excel files cannot be uploaded directly in webdynpro ABAP.

Download a empty template of excel file using a File download UI and fill your data into this excel file and then try to upload this excel file, It would work 200% correctly.

OR the second way would be to convert into text(tab delimited) file and upload the text file.

Former Member
0 Kudos

Hi Rashmita,

Please follow the below link

http://scn.sap.com/community/web-dynpro-abap/blog/2012/04/05/upload-xlsx-file-in-webdynpro-abap-and-...

It might help.

Regards,

Sayan

satyabrata_sahoo3
Contributor
0 Kudos

This program works well with File type Text(Tab delimited). Convert your excel to Tab delimited and check.

TusharShinde
Active Participant
0 Kudos

Hi check whether in excel for all columns you have set TEXT in Format Cells option. So as to make sure you pass all the data as TEXT to SAP.

Also you can check the WIKI link

http://wiki.sdn.sap.com/wiki/display/WDABAP/Excel+File+Upload+And+Display+Data+Using+Web+DynPro+ABAP

Thank You.

Br.

Tushar S.

Former Member
0 Kudos

Hi Rashmita,

I think it is better to try the following method.

1. Use a FileUploadUIElement to upload the file.

2. The uploaded file content will be raw data( xstring).

3. Pass it to TEXT_CONVERT_XLS_TO_SAP if file is xls.

4.In case of xlsx use

'ALSM_EXCEL_TO_INTERNAL_TABLE' or 'KCD_EXCEL_OLE_TO_INT_CONVERT'

5. Now you can process the internal table data which is received from the Function Module

Regards,

Fareez

Former Member
0 Kudos

Thanks a lot Fareez for ur valuable answer

I have tried to to uplode my .xlsx formatted flat file by using the function module  'ALSM_EXCEL_TO_INTERNAL_TABLE' like

method ONACTIONON_UPLOAD .

 
TYPES : BEGIN OF str,
          name
(10) TYPE c,
          age
(10) TYPE c,
         
END OF str.
*data:p_file TYPE rlgrap-filename.

DATA : t_table1 TYPE STANDARD TABLE OF str," this is the internal table of str type
         i_data
TYPE STANDARD TABLE OF string," this is the internal table for the flat file
         lo_nd_data
TYPE REF TO if_wd_context_node,
         lo_el_data
TYPE REF TO if_wd_context_element,
         l_string
TYPE string," this is the workarea for the flat file
         fs_table
TYPE str," this is the workarea of type str
         l_xstring
TYPE xstring,"xstring will store the flat file contents as row data
        
fields TYPE string_table,"string_table is a standard table which contains strings
         lv_field
TYPE string.

DATA : t_table TYPE if_main=>elements_data_tab,
        data_table
TYPE if_main=>elements_data_tab.



wd_context
->get_attribute(
   
EXPORTING
      name
`DATASOURCE`
   
IMPORTING
     
value = l_xstring ).

*  CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'**    EXPORTING**     FROM_CODEPAGE       = '8500'*      IN_XSTRING          =  l_xstring***     OUT_LEN             =*   IMPORTING*     OUT_STRING          = l_string.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
 
EXPORTING
    FILENAME                     
= l_xstring
    I_BEGIN_COL                  
= 1
    I_BEGIN_ROW                  
= 2
    I_END_COL                    
= 2
    I_END_ROW                    
= 10
 
TABLES
    INTERN                       
= i_data* EXCEPTIONS*   INCONSISTENT_PARAMETERS       = 1*   UPLOAD_OLE                    = 2*   OTHERS                        = 3
          .IF SY-SUBRC <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.

endmethod.

when I activate the component and test the application below error screen raised.

Can you kindly help me how to solve this error. I am not able to solve the error.Please help me.

deependra_shekhawat3
Contributor
0 Kudos

Hi Rashmita,

Use class CL_BCS_CONVERT  or cl_abap_conv_in_ce.

Thanks,

Deeps