cancel
Showing results for 
Search instead for 
Did you mean: 

Uploading Data from Excel File To Dynpro

Former Member
0 Kudos

Hi All,

Can data from from Excel file be uploaded to ABAP Web Dynpro application?

Taking a scenario, I need to upload data from Excel file into an application where it will be displayed in table format.

Appreciate your help.

Regards,

Prosenjit.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Thomas,

Thanks for your time. I could make some progress into it, but I need clarification on how to work with the uploaded data.

How is the data from excel sheet uploaded to the local internal table of the dynpro application? Please help me out guys.

Regards,

Prosenjit.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Did you have a look at the help link on the fileUpload element. The UI element will data bind the content of the uploaded file into a context attribute of binary string. You can read that context attribute like any other.

Now are you uploading a text, delimited file? If so you just need to turn the binary string into a string before you perform the splits on it. For this you can use the CL_ABAP_CONV_IN_CE class:

data s_cont type string.
data x_cont type xstring.

data convt type ref to cl_abap_conv_in_ce.
convt = cl_abap_conv_in_ce=>create( input = x_cont ).
conv->read( importing data = s_cont ).

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Thomas,

I have an excel sheet with data under two columns. I want to load it to my dynpro application and display it in my table control.

Regards,

Prosenjit.

abhimanyu_lagishetti7
Active Contributor
0 Kudos

Hi

It is already explained by Thomas clearly

Place a FileUpload UI element on your View and bind the bind the data property to a cotnext attribute of type XSTRING

Read the Cotnext Attribute into a variable and convert it to String

data s_cont type string.

data x_cont type xstring. '' this is your context attribute data

data convt type ref to cl_abap_conv_in_ce.

convt = cl_abap_conv_in_ce=>create( input = x_cont ).

conv->read( importing data = s_cont ).

Now split the string to convert it into an internal table

data: fields type string_table.

data: lv_field type string.

data: s_table type string_table.

data: itab type <your internal table type>

data: str_itab type < internal type structure type >

split s_cont at cl_abap_char_utilities=>cr_lf into table s_table.

field-symbols: <wa_table> like line of s_table.

loop at s_table assigning <wa_table>.

split <wa_table> at cl_abap_char_utilities=>HORIZONTAL_TAB into table fields.

        • you have only two columns as you said

read table fields into lv_field index 1.

str_itab-col1 = lv_field.

read table fields into lv_field index 2.

str_itab-col2 = lv_field.

append str_itab to itab.

endloop.

Now itab will contain the values ( make sure the file is Tab Delimited )

Abhi

former_member219737
Participant
0 Kudos

Hi Experts,

I have tried the above code ...and i am getting "SET Conversion Error"

I want to upload in excel via webdynpro ..

Can u please suggest me an idea for it ...

Regards,

Karthik S

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You can upload any data file from the client to WDA via the FileUpload UI element. As far as WDA is concerned all it needs to do is handle the upload. Then you have a binary string with the file contents and it is up to you as the application developer to decide what to do with that data. So now you are really in the realm of normal ABAP programming and nothing really specific about WDA.

Now normal Excel content is saved in a binary, priopriatery Microsoft format. This can't really be processed very easily within ABAP. What usually happens is that the Excel file must be saved to some open format - like text tab delimited or XML. You then have the possibility to parse the file content and read it into an ABAP internal table. The exact procedure differs depending upon which format the Excel file is actually in.

Former Member
0 Kudos

Thomas,

I'm quiet interested to know more details about the excel upload.

Can you tell the procedure to be followed?

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Which part are you interested in - the file upload itself or the processing of the data afterwards.

The file upload is pretty simple and all the work is done by the fileUpload UI element:

http://help.sap.com/saphelp_nw70/helpdata/EN/b3/be7941601b1d09e10000000a155106/frameset.htm

The processing of the file once uploaded, really has nothing to do with Web Dynpro per say. As I said the actual process of parsing the Excel file depends upon the file format - text delimited or XML. Which one did you have in mind? I personally find text delimited the easier of the two because it can be coded using the SPLIT statement. It can be something as simple as this:

data: input_string type string.
data: fields  type string_table.
data: s_table type string_table.
split input_string at cl_abap_char_utilities=>cr_lf into table s_table.
 
field-symbols: <wa_table> like line of s_table.
loop at s_table assigning <wa_table>.
  split <wa_table> at cl_abap_char_utilities=>HORIZONTAL_TAB into table fields.
*****Process Each Field into your destination structure
endloop.

The XML approach usually requires an XSLT or the use of the iXML library. You can also try searching SDN for Excel Upload - it is fairly common topic. Just be careful because some of the approaches use SAPGUI specific (Office Automation) approaches to processing the upload.