cancel
Showing results for 
Search instead for 
Did you mean: 

uploading a excel file using abap webdynpro

Former Member
0 Kudos

Dear exports

I want to upload a excel file and display the data in broswer using abap webdynpro. My excel file format is .XLSX . But I am not able to upload it because when I browse the file and click on upload button an error raised. And I am a fresher in this platform so I have no much knowledge to solave this error. Can anyone kindly help me to solve the error.

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 '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.

    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  an error raised.

and the erroe screenshot is

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 (8)

Answers (8)

0 Kudos

You can try:

METHOD onactionon_upload .

   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=>element_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 THE 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 ) .

ENDMETHOD.

UweFetzer_se38
Active Contributor
0 Kudos

Just out of plain curiosity:

  • why you are answering to a two year old question, where the original poster is not really interested in an answer?
  • why you are copy/pasting a one year old answer without additional information?
0 Kudos

I am very new to SCN SAP. I could not understand. I shall be familiar with the site very soon. And I am not copying and pasting other's answers. Thank you.

UweFetzer_se38
Active Contributor
0 Kudos

A warm "Welcome"

(your answer looked exactly like )

0 Kudos

Thank you..

Former Member
0 Kudos

Please refer below links for .xlsx upload/download.

http://scn.sap.com/docs/DOC-45719

http://scn.sap.com/docs/DOC-46001

Award points if useful.

Former Member
0 Kudos

Hi,

In the exporting parameters u have to use l_xstring as type string not xstring.

Regards,

Vineesh.

Former Member
0 Kudos

Hi ,

I have the same requirement, but i have an excel with multiple fields like more than 20 fields to be uploaded into Webdynpro ALV.

Please suggest me the approach how it can be done.

Thanks in advance.

Former Member
0 Kudos

HI Rashmita,

here is the sample code  plz try this

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 ).

thanks & regards,

Meenachi.R

Former Member
0 Kudos

Hello Rashmita,

Refer following link,It may help to resolve your issue.

http://www.saptechnical.com/Tutorials/WebDynproABAP/Upload/Page1.htm

Katrice

Former Member
0 Kudos

Dear Venkatesh,

Every  web dynpro application  has its own understandable excel format, which is specific to it only.

Now when ever you are uploading any excel , if the format not matches with the format of the web dynpro application , it will show you dump values in the output .

You can very well overcome this issue by allowing the user first download a blank template from the application its self and then ask him to fill it and upload back to application.

This way you can make sure that the both the formats will remain always same in any case irrespective of the system

For more details and explanation on this you can refer the below document.

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

Link :

http://scn.sap.com/thread/3314346

Hope this will resolve the issue.

Thanks,

Gejo john

former_member199126
Participant
0 Kudos

The Problem is with the i_data.

it should be of

data : i_data LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
   
EXPORTING
      FILENAME                = P_FILE
      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.

0 Kudos

Hi Rashmita Parida ,

Please save as  the xlsx file to Text(Tab Delimited) *.txt  format  ,then upload it willsurly work.

Regards,

Ragupathi.T

UweFetzer_se38
Active Contributor
0 Kudos

Hi Rashmita,

the reason for this error is a type conflict in the function module interface (passed parameters don't have the same type as declared in the function module).

But: you cannot use this function module in Webdynpro environment because it uses GUI_UPLOAD but Webdynpro applications don't have a SAPGUI connection.

Please search in the documentation (or here in the forum) how to upload files in WDA.

Best regards
(@se38)

Former Member
0 Kudos

Thanks for your valuable answer.

But my requirement is ito uplode the excel file which is in .xlsx format. Because my flat file contains the Customer details which is a excel file. So how I can upload it.If I use the function module 'HR_KR_XSTRING_TO_STRING' then whn I will browse the file it wiil be selected. But when I uplode it, it will display junk data like

How to solve this issue. Kindly help me to solve this probe. I have no much knowledge in this platform because recently I have joined. Which function module I will be use so that my flat file will be uploded.

Regards/Rashmita

UweFetzer_se38
Active Contributor
0 Kudos

do you have tried the search function (upper right corner) already? Search eg. for "wda excel upload".

If you still cannot find an answer, feel free to come back.

Best regards

Uwe

Former Member
0 Kudos

Hi Not Active Contributor

former_member198064
Participant
0 Kudos

Hi Uwe,

I am doing the same Excel file upload Program in Webdynpro . I am getting the data in the below format.

Can you please tell me how to convert the above format as a data.

How to solve this issue.

Thanks,

Venkatesh