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: 

How to Publish the ABAP query results as csv

Former Member
0 Kudos

Hi,

I have a scenario and need help for the same, I need to query a table in CRM which has the long text information and publish or save the result as a csv file, is it possible? if so please tell me the steps and code if available

Thanks

Akila.R

3 REPLIES 3

andreas_mann3
Active Contributor
0 Kudos

hi,

1) select your db-table into itab

2)

data str typ string.
data tab type table of string.

loop at itab.
 clear str. 
 do.
  assign component sy-index of structure itab to <fs>.
  if sy-subrc = 0.
     CONCATENATE str  <fs> ';' INTO str.
  else.
   exit.
  endif.
 enddo.
 append str to tab.
endloop.

3) use fm gui_download for table tab

A.

Message was edited by:

Andreas Mann

0 Kudos

Thanks,

I am very new to BW, should i write this code in SE80 transcation, please tell me the initial steps as well. Also would this code block output as csv, in which location the file will be stored, and from where this function would be executed, can i execute this in a process chain

Please give me more info.

Thanks

Akila.R

0 Kudos

Hi,

Two formats of creating a CSV file:

report zrich_0001 .

data: it001 type table of t001 with header line.

data: iout type table of string .

data: xout type string.

field-symbols: <fs>.

select * into table it001 from t001.

loop at it001.

clear xout.

do.

assign component sy-index of structure it001 to <fs>.

if sy-subrc <> 0.

exit.

endif.

if sy-index = 1.

xout = <fs>.

else.

concatenate xout <fs> into xout separated by ','.

endif.

enddo.

append xout to iout.

endloop.

call function 'GUI_DOWNLOAD'

exporting

filename = 'C:\test.csv'

tables

data_tab = iout.

-


report ztest.

type-pools:TRUXS.

data: begin of itab occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

end of itab.

data: itab1 type TRUXS_T_TEXT_DATA.

select vbeln

posnr

up to 10 rows

from vbap

into table itab.

CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'

EXPORTING

I_FIELD_SEPERATOR = ','

TABLES

I_TAB_SAP_DATA = itab

CHANGING

I_TAB_CONVERTED_DATA = itab1

EXCEPTIONS

CONVERSION_FAILED = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'C:\TEMP\TEST.CSV'

TABLES

data_tab = itab1

EXCEPTIONS

OTHERS = 1.

-


Use SE38.

Regards

Subramanian