01-23-2007 7:48 PM
how do i create an outbound interface whose output should be in csv format
01-23-2007 7:49 PM
You can create a csv file by coding the following.
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.
Regards,
Rich Heilman
01-23-2007 8:00 PM
Hi,
You can use FM SAP_CONVERT_TO_CSV_FORMAT.
Please check this sample code from other thread.
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:TEMPTEST.CSV'
TABLES
data_tab = itab1
EXCEPTIONS
OTHERS = 1.
Regards,
Ferry Lianto
01-23-2007 8:05 PM
If you want CSV file to be downloaded to application server, use below code
Local variables declaration.
DATA: tab.
DATA: outrec(300).
FIELD-SYMBOLS: <f>.
Column break in excel sheet
tab = CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
Open application server filepath
OPEN DATASET p_path FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
Message e000 with 'Error in opening the file'.
ENDIF.
LOOP AT head_tab.
ASSIGN head_tab-header TO <f>.
IF sy-tabix = '1'.
MOVE <f> to outrec.
ELSE.
CONCATENATE outrec <f> into outrec SEPARATED BY tab.
ENDIF.
ENDLOOP.
TRANSFER outrec to p_path.
clear outrec.
Split each field in internal table to separate columns in excel file
LOOP AT data_tab_download.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE data_tab_download TO <f>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF sy-index = 1.
MOVE <f> TO outrec.
ELSE.
CONCATENATE outrec <f> INTO outrec SEPARATED BY tab.
ENDIF.
ENDDO.
Transfer data to excel file
TRANSFER outrec TO p_path.
CLEAR outrec.
ENDLOOP.
CLOSE DATASET p_path.
01-23-2007 11:59 PM