Wednesday, January 17, 2007

[bw] sample code export csv file to al11 folder ( folder on application server )

REPORT ZJEFFTEST.
tables: /BI0/PCUSTOMER.
data: cus_text type table of /BI0/TCUSTOMER.
data: cus_text_w type /BI0/TCUSTOMER.

*** Changes made here
data: ls_singlerow type string.
DATA: filename TYPE string VALUE '/bw/flatfile/test.csv'.
*** Changes ends here

select A~customer A~TXTMD A~TXTLG
from /BI0/TCUSTOMER as A JOIN /BI0/PCUSTOMER as B
ON A~customer = B~customer
into table cus_text
where B~COUNTRY = 'TW'
and B~/BIC/ZNAME_FLG <> 'Y'.


*** Changes made here
*close DATASET filename.
DELETE DATASET filename.
write sy-subrc.
OPEN DATASET filename FOR appending IN TEXT MODE ENCODING default.
loop at cus_text into cus_text_w.

concatenate cus_text_w-CUSTOMER
cus_text_w-TXTMD
* cus_text_w-TXTLG
into ls_singlerow
separated by ','.

IF SY-SUBRC = 0.
TRANSFER ls_singlerow TO filename.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDIF.
endloop.
close DATASET filename.

if sy-subrc <> 0.
write sy-subrc.
write 'Unsuccessful'.