08-06-2012 3:26 PM
Hi guys,
I want to save the result of the report aqzz/sapquery/smcrm_rep_act1== into a csv-file.
REPORT z_test.
DATA listtab LIKE abaplist OCCURS 1.
DATA: BEGIN OF ascitab OCCURS 1,
line(256),
END OF ascitab.
SUBMIT aqzz/sapquery/smcrm_rep_act1== EXPORTING LIST TO MEMORY AND RETURN .
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = listtab.
CALL FUNCTION 'LIST_TO_ASCI'
EXPORTING
list_index = -1
with_line_break = '; '
TABLES
listasci = ascitab
listobject = listtab.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'c:\test.csv'
header = '00'
TABLES
data_tab = listtab.
I think fm LIST_FROM_MEMORY is working well. But I'm not sure, if fm LIST_TO_ASCI and GUI_DOWNLOAD are working too.
A csv-file is created, but it contains some cryptic stuff.
Can anyone please help me?
thanks
axel
08-06-2012 3:43 PM
Download ASCITAB and not LISTTAB (internal format)
Regards,
Raymond
08-06-2012 3:43 PM
Download ASCITAB and not LISTTAB (internal format)
Regards,
Raymond
08-06-2012 3:51 PM
with the ascitab there are 0 bytes transmitted, code page 1160
but with the listtab the where 2.009 bytes transmitted.
08-06-2012 3:58 PM
Code the EXCEPTIONS of the FMs and check sy-subrc.
Regards,
Raymond
08-06-2012 4:12 PM
Every sy-subrc is = 0.
There are no changes with the coded exceptions.
08-07-2012 9:40 AM
Could you remove your WITH_LINE_BREAK parameter (word wrapping for long lines)
Regards,
Raymond
08-07-2012 10:00 AM
Now I get this
1- | |
373ÿ €4103» ZMµ+5 ÁUä 3¼ú”ü ˜dÆ„LÌC4ø»(i | |
> NÜó#|D | |
îtòŒ ²¡ ë¹ | [¶wO+Ù* !â´…n0Ä Æ¸Ä s ‰ ¥ª·ËwGœŽüç ¤ôF†+ªCË‘"Ç€j†3â cJ÷„óI˜ |
id³ÅÎ+^/Ï¢ÇS±í3” ]¸§x¤8¤x§H( (*mIß8í!€„&Ë& Zmx †b›KOz-K \Àq/EÇpÚG qÍp âíV2"¡¤ÜŠ’a%Ëî+ ³qšÓ h6SnÏ&VI˜ë5fÕ¸ç–ß]ý¢È믎…3 | |
i³æ6k ž»“oèÿ££ò ö ³§´´çžÙæO¾QÎ8þ²'¬ÙFQº†@yá£m¼ Î ½â‹ #ÜÑôù×—“ lƒ3A¯¤á¸}2ú£”' „ó\s | |
þeS i¤NÛZ6e³7Å Í Yžeô 701 |
in my csv-file.
08-07-2012 10:12 AM
If you are in a unicode system, look for Note 1499385 - Lost layout after text download which corrects LIST_TO_ASCI FM.
Regards,
Raymond
08-06-2012 4:54 PM
LIST_TO_ASCI function module does not convert report output in comma separated values. Internal table ascitab will contains readable values with column separated as pipe ( |) characters and line separator with dash ( - ).
Exporting this ascitab internal table with fm GUI_DOWNLOAD will not convert report in comma separated value either.
After call to LIST_TO_ASCI you need to do some post processing on table ascitab to create csv data and export that using GUI_DOWNLOAD.
Below is code snippet from one of our program which does exactly that
TYPES : BEGIN OF ty_split ,
token TYPE char50 ,
END OF ty_split .
DATA : li_split TYPE TABLE OF ty_split ,
lv_str TYPE string ,
ls_final TYPE ty_fin ,
lv_token TYPE char50 .
* Convert it to csv file
LOOP AT ascilines .
* Skip separater lines
CHECK ascilines+0(10) <> '----------' .
CLEAR li_split .
SPLIT ascilines AT '|' INTO TABLE li_split .
CLEAR lv_str .
LOOP AT li_split ASSIGNING <fs_slip> .
CLEAR lv_token .
lv_token = <fs_slip>-token .
* Post processing - if user want value to be condensed
IF p_trim = abap_true .
CONDENSE lv_token .
ENDIF .
* If user want negative to appear before number
IF p_neg = abap_true .
CONDENSE lv_token .
FIND REGEX '(\d+(\,\d+)?)+(\.\d+)?-' IN lv_token .
IF sy-subrc = 0 .
REPLACE '-' IN lv_token WITH space .
CONCATENATE '-' lv_token INTO lv_token .
ENDIF.
ENDIF.
CASE sy-tabix.
WHEN 1 .
WHEN 2.
lv_str = lv_token.
WHEN OTHERS.
CONCATENATE lv_str lv_token INTO lv_str SEPARATED BY gc_tab.
ENDCASE.
ENDLOOP .
CLEAR ls_final .
ls_final-line = lv_str .
APPEND ls_final TO i_final .
ENDLOOP.
Regards,
Pawan.
08-07-2012 9:29 AM
Hi Pawan,
my table ascitab has only one empty line after LIST_TO_ASCI.
08-07-2012 10:46 AM
Your declaration of ascitab contains a header line, that is why you are having these problems. Change the declaration of ascitab to have no header line and try again:
DATA: ascitab TYPE STANDARD TABLE OF char256.
Che
08-07-2012 12:19 PM
Hi Che,
REPORT z_test.
DATA listtab LIKE abaplist OCCURS 1.
DATA: ascitab TYPE STANDARD TABLE OF char256.
SUBMIT aqzz/sapquery/smcrm_rep_act1== EXPORTING LIST TO MEMORY AND RETURN .
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = listtab.
CALL FUNCTION 'LIST_TO_ASCI'
EXPORTING
list_index = -1
TABLES
listasci = ascitab
listobject = listtab.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'C:\test.csv'
TABLES
data_tab = ascitab.
only saves 2 bytes.
08-07-2012 12:30 PM
and your point is?
Take a look at the contents of ascitab after the call to LIST_T_ASCI. What do you see in there? is it readable and recognisable?
08-07-2012 12:54 PM
after calling LIST_TO_ASCI there is one line in ascitab.
But I don't know how to interpret it nor to use it.
08-07-2012 1:20 PM
Perhaps aqzz/sapquery/smcrm_rep_act1== is returning an empty list. What result do you get when running
aqzz/sapquery/smcrm_rep_act1== in foreground? Can you put up a screen shot of the output from
aqzz/sapquery/smcrm_rep_act1==.
Che
08-07-2012 1:32 PM
If I'm running aqzz/sapquery/smcrm_rep_act1== in SE38 there are many entrieslike these:
my aim is to save this "list" into a csv file.
08-07-2012 2:13 PM
aqzz/sapquery/smcrm_rep_act1== is a query. Unfortunately I do not have this query in my system but I have tried it with another query. Can you try the following and let me know if you get better results?
SUBMIT aqzz/sapquery/smcrm_rep_act1==
WITH %alv EQ ' '
EXPORTING LIST TO MEMORY AND RETURN .
08-07-2012 2:21 PM
unfortunately it brings the same result.
i'm using a crm 7.0 system (the report should also be available in older systems).
08-07-2012 2:31 PM
When running your report do you get a popup asking if you want to restrict the selection to 100 records? This sometimes appears when running a query and will affect your resulting export to memory.
08-07-2012 2:38 PM
yes I do.
but to avoid the popup I've defined a variant.
SUBMIT aqzz/sapquery/smcrm_rep_act1== USING SELECTION-SET 'AXEL' EXPORTING LIST TO MEMORY AND RETURN .
08-07-2012 2:53 PM
Make sure you have SAP List Viewer = X in the variant AXEL (and not ABAP List = X).
This works for me.
Failing that I would go with Raymonds suggestion.
08-07-2012 2:28 PM
If the query displays an ALV by default, you could use the class cl_salv_bs_runtime_info (*) to recover the generated internal table.
* Get Handler
call method cl_salv_bs_runtime_info=>set
exporting
display = abap_false
metadata = abap_false
data = abap_true.
* Call report
submit qzz/sapquery/smcrm_rep_act1==
and return.
* Recover data
try.
call method cl_salv_bs_runtime_info=>get_data_ref
importing
r_data = lr_data.
assign lr_data->* to <lt_data>.
catch cx_salv_bs_sc_runtime_info.
endtry.
Regards,
Raymond
(*) Check this blog : Gain Programmatic Access to Data of SAPGUI ALV Reports.
08-08-2012 1:35 PM
hi Che and Raymond,
the display of the report aqzz/sapquery/smcrm_rep_act1== is an ALV grid, which I can't submit for example:
http://scn.sap.com/thread/259704
I'm now going to try cl_salv_bs_runtime_info (*) or copy the report and modify it.
thanks