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: 

save the result of a report into csv-file

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
0 Kudos

Download ASCITAB and not LISTTAB (internal format)

Regards,

Raymond

22 REPLIES 22

raymond_giuseppi
Active Contributor
0 Kudos

Download ASCITAB and not LISTTAB (internal format)

Regards,

Raymond

0 Kudos

with the ascitab there are 0 bytes transmitted, code page 1160

but with the  listtab the where 2.009 bytes transmitted.

0 Kudos

Code the EXCEPTIONS of the FMs and check sy-subrc.

Regards,

Raymond

0 Kudos

Every sy-subrc is = 0.

There are no changes with the coded exceptions.

0 Kudos

Could you remove your WITH_LINE_BREAK parameter (word wrapping for long lines)

Regards,

Raymond

0 Kudos

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.

0 Kudos

If you are in a unicode system, look for Note 1499385 - Lost layout after text download which corrects LIST_TO_ASCI FM.

Regards,

Raymond

Pawan_Kesari
Active Contributor
0 Kudos

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.

0 Kudos

Hi Pawan,

my table ascitab has only one empty line after LIST_TO_ASCI.

0 Kudos

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

0 Kudos

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.

0 Kudos

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?

0 Kudos

after calling LIST_TO_ASCI there is one line in ascitab.

But I don't know how to interpret it nor to use it.

0 Kudos

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


0 Kudos

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.

0 Kudos

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 . 

0 Kudos

unfortunately it brings the same result.

i'm using a crm 7.0 system (the report should also be available in older systems).

0 Kudos

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.

0 Kudos

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 .

0 Kudos

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.

raymond_giuseppi
Active Contributor
0 Kudos

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.

0 Kudos

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