cancel
Showing results for 
Search instead for 
Did you mean: 

How to download an internal table as .txt file on to Client system

Former Member
0 Kudos

Hi all,

I have an internal table of type string.I want to download the contents of this internal table into a .txt file on to the desired location in the client system with a desired name.The rows of the internal table should appear as lines of the .txt file.

I have created a node NODE_FILE with cardinality 0-n and created an attribute DATA_ATTR of type xstring.

I have converted the internal table of type string into an internal table of type xstring,bound the internal table to this node.

I have created two input fields to allow the user to input file name and file location respectively.

Now am having the filename , filelocation , and filecontent in the context.Can anyone please help me how to download the file onto the desired location in the client system.

Is the procedure am following is right?

Thanks and Regards,

Rahim.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi ,

Follow this approach :

You can use following funcntions. First one to create internal table to string and second FM SCMS_STRING_TO_XSTRING to convert String to XSTRING. Then this XSTRING value you can pass to CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE.

data: tab_str type string.

data: begin of it_tab1,

name(20),

age(10) ,

end of it_tab1.

data : lv_name type xstring.

data it_tab like STANDARD TABLE OF it_tab1.

data: wa like line of it_tab.

wa-name = 'naresh'.

wa-age = '30'.

append wa to it_tab.

wa-name = 'naresh1'.

wa-age = '31'.

append wa to it_tab.

CALL FUNCTION 'SOTR_SERV_TABLE_TO_STRING'

IMPORTING

TEXT = tab_str

TABLES

TEXT_TAB = it_tab

.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

TEXT = tab_str

IMPORTING

BUFFER = lv_name

.

CALL METHOD CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE

EXPORTING

I_FILENAME = 'c:\test.txt'

I_CONTENT = lv_name

I_MIME_TYPE = 'TXT'

Refer below links. This has been discussed many times :

Former Member
0 Kudos

Thanks a lot Amit and Saurav.

I want to ask another question, am calling the CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE inside the event handler method of a BUTTON click. once I click the button , am getting a pop window to name the file and also to browse the location where I want to save my file. I dont want this pop up window to appear, I want to save the file at the location i mention in CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE method.

Is that pop up window is because of security settings of my browser ?

Regards,

Rahim

Edited by: M Rahim on Oct 21, 2009 11:35 AM

Former Member
0 Kudos

I think That pop-up cannot be controlled.

attach_file_to_response will always have that pop-up.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>Is that pop up window is because of security settings of my browser ?

Exactly. The browser doesn't allow you to do slient downloads. You could imagine the damage that could be caused by a malicious website.

Former Member
0 Kudos

Hi Thomas,

what if I want to do multiple downloads, every time the pop up window will appear?

Cant I create a ZIP file containing all the multiple files and download at a time, so that the window appears only once?

Can you please provide me the code , of zip file downloading( or may be multiple file downloading ).

Thanks and Regards,

Abdul Rahim.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Same basic issue - browser security. You can't do slient downloads, forced location downloads or multiple file downloads. A suitable workaround is generally to use the ABAP class CL_ABAP_ZIP to combine all of you contents into one file for download. CL_ABAP_ZIP is pretty easy to use.

data izip type ref to cl_abap_zip.
data output_file type xstring.
  create object izip.
  loop at files assigning <Wa_file>.
  izip->add( name = <wa_file>-name
              content = <wa_file>-content ).
endloop.
 output_file = izip->save( ).

Former Member
0 Kudos

Thanks a lot Thomas

Answers (1)

Answers (1)

Former Member
0 Kudos

hi ,

u can save the contents of ur internal table as excel file or text file .get the contents in internal table and then use the FM 'SCMS_STRING_TO_XSTRING'


DATA text   TYPE string.
  DATA xtext  TYPE xstring.
 
*   get all declared attributes
  lo_nd_sbook->get_static_attributes_table(
    IMPORTING
     table = lt_sbook ).
 
  LOOP AT lt_sbook INTO ls_sbook.
 
 
CONCATENATE text ls_sbook-carrid
ls_sbook-connid
ls_sbook-fldate
ls_sbook-bookid
ls_sbook-order_date
ls_sbook-counter
ls_sbook-passname
cl_abap_char_utilities=>newline INTO text SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
 
ENDLOOP.
 
 
    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
      EXPORTING
        text   = text
      IMPORTING
        buffer = xtext.
    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' ).


i_filename = 'WDP.txt'
* String Variable
i_content =  xtext
* File Type
i_mime_type = 'TXT' ). // for text file

here it_sbook is the inernal table and ls_sbook is the structure type of the attributes declared in the context node sbook


 DATA ls_sbook TYPE wd_this->element_sbook.
*  data LT_SFLIGHT type WD_THIS->ELEMENTS_SFLIGHT.
 
  DATA lt_sbook TYPE wd_this->elements_sbook.

regards,

amit