Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

downloading of results

Former Member
0 Kudos

Hi Experts,

i want to download the output of the report in to my desktop folder so pls provide the solution

so iam using it as

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

listobject = list_tab3

EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc = 0.

CALL FUNCTION 'WRITE_LIST'

TABLES

listobject = list_tab3.

ENDIF.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

* BIN_FILESIZE =

filename = 'C:\documents and settings\sap\Desktop\Report\Report3.xls'

filetype = 'DAT'

* APPEND = ' '

* WRITE_FIELD_SEPARATOR = ' '

* HEADER = '00'

* TRUNC_TRAILING_BLANKS = ' '

* WRITE_LF = 'X'

* COL_SELECT = ' '

* COL_SELECT_MASK = ' '

* DAT_MODE = ' '

* IMPORTING

* FILELENGTH =

TABLES

data_tab = list_tab3.

But the data is not downloaded properly

11 REPLIES 11

Former Member
0 Kudos

hii

for downloading data in to excel sheet just use following code

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
*   BIN_FILESIZE                  =
    filename                      = 'C:\Documents and Settings\My Documents\data.xls'
   filetype                      = 'ASC'
*   APPEND                        = ' '
   write_field_separator         = 'X'
  TABLES
    data_tab                      = t_kna1

if your internal table does not have any data then it will display 0 bytes transfer so first check with that data.

regards

twinkal

Mohamed_Mukhtar
Active Contributor
0 Kudos

Hi Mohan,

 CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES
listobject = list_tab3
EXCEPTIONS
not_found = 1
OTHERS = 2.

IF sy-subrc = 0.
CALL FUNCTION 'WRITE_LIST'
TABLES
listobject = list_tab3.
ENDIF.

CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING

    * BIN_FILESIZE =

filename = 'C:\documents and settings\sap\Desktop\Report\Report3.xls'
filetype = 'ASC'   

    * APPEND = ' '
    * WRITE_FIELD_SEPARATOR = ' X'     " Add X here
    * HEADER = '00'
    * TRUNC_TRAILING_BLANKS = ' '
    * WRITE_LF = 'X'
    * COL_SELECT = ' '
    * COL_SELECT_MASK = ' '
    * DAT_MODE = ' '
    * IMPORTING
    * FILELENGTH =

TABLES
data_tab = list_tab3.

Thanks & Regards

0 Kudos

Hi Thanks for ur quick reply actually the report is executed properly but it shows as 0bytes passed it creates the file on desktop with 0 bytes file.

0 Kudos

Hi friends,

is there any way is there for downloading of the output data of a report in to desktop file

iam using the coding as

if VARR1 is initial.

submit ZRM07MLBD

  • line-size p_linesz

  • line-count p_linect

via selection-screen

exporting list to memory

and return.

else.

submit ZRM07MLBD

  • line-size p_linesz

  • line-count p_linect

using selection-set T_VARID1-VARIANT

exporting list to memory

and return.

endif.

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

listobject = list_tab1

EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc = 0.

CALL FUNCTION 'WRITE_LIST'

TABLES

listobject = list_tab1.

ENDIF.

ENDLOOP.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

* BIN_FILESIZE =

filename = 'C:\documents and settings\SAP\Desktop\Report\Report1.xls'

filetype = 'DAT'

* APPEND = ' '

* WRITE_FIELD_SEPARATOR = ' '

* HEADER = '00'

* TRUNC_TRAILING_BLANKS = ' '

* WRITE_LF = 'X'

* COL_SELECT = ' '

* COL_SELECT_MASK = ' '

* DAT_MODE = ' '

* IMPORTING

* FILELENGTH =

TABLES

data_tab = T_VARID1.

ENDIF.

pls correct this one

thanks,

mohan

0 Kudos

Hi,

check the corrected line of the program



CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING


BIN_FILESIZE = 
filename = 'C:\documents and settings\SAP\Desktop\Report\Report1.xls'
filetype = 'DAT'

APPEND = ' ' 
WRITE_FIELD_SEPARATOR = ' ' 
HEADER = '00' 
TRUNC_TRAILING_BLANKS = ' ' 
WRITE_LF = 'X' 
COL_SELECT = ' ' 
COL_SELECT_MASK = ' ' 
DAT_MODE = ' ' 
IMPORTING 
FILELENGTH = 
TABLES
data_tab = list_tab1.   " <---- This is the table containing output

ENDIF.

Cheers,

Kothand

0 Kudos

hi no it is giving the out as version of sap and user of computer but it is not giving the data

i changed it to in gui download

tables as t_varid3

but no proper output

thanks

mohan

0 Kudos

Hi,

sorry..

check your internal table name what ever you are passing to GUI_DOWNLOAD fucntion module..

i think it needs to be corrected.

Regares,

venkat

P561888
Active Contributor
0 Kudos

hi ,

pass the all necc. parameters to the FM gui_download...

Regards,

Bharani.

Former Member
0 Kudos

Hi,

if you want to use GUI_DOWNLOAD...then give the file type as 'ASC'.

if you want to give file type as DAT...then use WS_DOWNLOAD

REgards,

venkat

Former Member
0 Kudos

hi,

just refer this step by step procedure how to download the internal table data and after that send it in mail it will help u a lot:

Firstly export the data to memory using the FM LIST_FROM_MEMORY.

CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = t_listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc 0.
MESSAGE e000(su) WITH text-001.
ENDIF.

then i converted it into ASCII using LIST_TO_ASCI,

CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listasci = t_xlstab
listobject = t_listobject
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE e003(yuksdbfzs).
ENDIF.

This gives the data in ASCII format separated by '|' and the header has '-', dashes. If you use this internal table directly without any proccesing in SO_NEW_DOCUMENT_ATT_SEND_API1, then you will not get a good excel sheet attachment. To overcome this limitation, i used cl_abap_char_utilities=>newline and cl_abap_char_utilities=>horizontal_tab to add horizontal and vertical tabs to the internal table, replacing all occurences of '|' with 
cl_abap_char_utilities=>horizontal_tab.

Set the doc_type as 'XLS', create the body and header using the packing_list and pass the data to be downloaded to SO_NEW_DOCUMENT_ATT_SEND_API1 as contents_bin.
This will create an excel attachment.

Sample code for formatting the data for the attachment in excel format.


u2022	Format the data for excel file download 



LOOP AT t_xlstab INTO wa_xlstab .
DESCRIBE TABLE t_xlstab LINES lw_cnt.
CLEAR lw_sytabix.
lw_sytabix = sy-tabix.


u2022	If not new line then replace '|' by tabs 



IF NOT wa_xlstab EQ cl_abap_char_utilities=>newline.
REPLACE ALL OCCURRENCES OF '|' IN wa_xlstab
WITH cl_abap_char_utilities=>horizontal_tab.
MODIFY t_xlstab FROM wa_xlstab .
CLEAR wa_xlstab.
wa_xlstab = cl_abap_char_utilities=>newline.
IF lw_cnt NE 0 .
lw_sytabix = lw_sytabix + 1.


u2022	Insert new line for the excel data 



INSERT wa_xlstab INTO t_xlstab INDEX lw_sytabix.
lw_cnt = lw_cnt - 1.
ENDIF.
CLEAR wa_xlstab.
ENDIF.
ENDLOOP.
Sample code for creating attachment and sending mail:

FORM send_mail .


u2022	Define the attachment format 


lw_doc_type = 'XLS'.


u2022	Create the document which is to be sent 


lwa_doc_chng-obj_name = 'List'.
lwa_doc_chng-obj_descr = w_subject. "Subject
lwa_doc_chng-obj_langu = sy-langu.


u2022	Fill the document data and get size of message 


LOOP AT t_message.
lt_objtxt = t_message-line.
APPEND lt_objtxt.
ENDLOOP.

DESCRIBE TABLE lt_objtxt LINES lw_tab_lines.
IF lw_tab_lines GT 0.
READ TABLE lt_objtxt INDEX lw_tab_lines.
lwa_doc_chng-doc_size = ( lw_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt ).
lwa_doc_chng-obj_langu = sy-langu.
lwa_doc_chng-sensitivty = 'F'.
ELSE.
lwa_doc_chng-doc_size = 0.
ENDIF.


u2022	Fill Packing List For the body of e-mail 



lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = lw_tab_lines.
lt_packing_list-doc_type = 'RAW'.
APPEND lt_packing_list.


u2022	Create the attachment (the list itself) 



DESCRIBE TABLE t_xlstab LINES lw_tab_lines.


u2022	Fill the fields of the packing_list for creating the attachment: 



lt_packing_list-transf_bin = 'X'.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = lw_tab_lines.
lt_packing_list-doc_type = lw_doc_type.
lt_packing_list-obj_name = 'Attach'.
lt_packing_list-obj_descr = w_docdesc.
lt_packing_list-doc_size = lw_tab_lines * 255.
APPEND lt_packing_list.


u2022	Fill the mail recipient list 



lt_reclist-rec_type = 'U'.
LOOP AT t_recipient_list.
lt_reclist-receiver = t_recipient_list-address.
APPEND lt_reclist.
ENDLOOP.


u2022	Finally send E-Mail 


CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lwa_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = lw_sent_to_all
TABLES
packing_list = lt_packing_list
object_header = lt_objhead
contents_bin = t_xlstab
contents_txt = lt_objtxt
receivers = lt_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.

Hope it will help you

Regards

Rahul sharma

Former Member
0 Kudos

hi Thanks for all for providing the solution

Mohan