cancel
Showing results for 
Search instead for 
Did you mean: 

File Download to Excel

Former Member
0 Kudos

Hi.

I know there are already some topics in this forum for this.

But I am quite a novice and could not actually understand the complex convert to XSTRING and back and encoding thing.

Can someone please take some pains to tell me step-by-step how do I download a simple internal table which I have into Excel sheet?

I also want to give a popup to user to select the file location. FileDownload UI does not seem to give a popup.

Thanks in adv.

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member758419
Active Participant
0 Kudos

Hi Aishi,

The Filedownload UI element in Webdynpro Abap only accepts Xstring format data as an input data that is to be downloaded into local computer. So for that we need to convert the existing table contents into Xstring format, using the following procedure:

1) First convert the table data into XML format using the method:

call transformation ('ID')

source tab = itab_sflight

result xml xml_out.

where itab_flight is the internal table to be downloaded and Xml_out is the Xml output contains the xml format of itab_sflight.

The same can also be achieved by:

loop at itab_sflight into wa_sflight.

concatenate output

wa_sflight-carrid cl_abap_char_utilities=>horizontal_tab

wa_sflight-connid cl_abap_char_utilities=>horizontal_tab

....

....

wa_sflight-planetype cl_abap_char_utilities=>horizontal_tab

cl_abap_char_utilities=>cr_lf

into output.

endloop.

Here data in Itab_sflight is converted into String format(Output).

2) Convert the XML or String content to XSTRING format using Convert method.

conv_out = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' ).

conv_out->convert(

exporting

data = output / xml_out

importing

buffer = stru_filecontent_node-filecontent ).

Here stru_filecontent_node-filecontent is of type XSTRING.

3) Bind the Xstring to the context node, which is in turn binded to FileDownload UI element.

node->bind_structure(

new_item = stru_filecontent_node

).

Hope this is Clear..

Reward all useful answers..

Sachi

Former Member
0 Kudos

Thanks.

I tried this and what it does is to open the entire file in a new window.

Then I used the method ATTACH_FILE_TO_RESPONSE of CL_WD_RUNTIME_SERVICES to give a popup for selecting the file where to save. But that also doesn't work in the FILEDOWNLOAD UI element. But this method works perfectly fine if I give a button and call it on the button action.

What can be the reason for this behavior? If attach_file_to_response cannot be called in FILEDOWNLOAD UI element, then how to give popup for selecting file in it?

Thanks again.

Message was edited by:

Aishi Sharma

Former Member
0 Kudos

Hi,

you can use the function 'WS_DOWNLOAD' to download the internal table to a local excel file. the usage likes the following:

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

FILENAME = TAR_FILENAME

FILETYPE = 'DAT'

TABLES

DATA_TAB = tab_prog_name

EXCEPTIONS

OTHERS = 4.

pls remember to set FILETYPE parameter as 'DAT', and you can set the value of the parameter 'FILENAME' like 'c:\test.xls'. 'DATA_TAB is just the internal table you want to download.

if this is help please don't forget to give the marks.

BEST REGARDS

qiuguo wu

Former Member
0 Kudos

I am talking about Web Dynpro for ABAP.

gurus any suggestions please.