下載內表到本地.CSV檔案中

kevinhaerbin發表於2009-02-20
form down_load tables gt_down." TYPE gt_data.

data: filename type string value '',
path type string value '',
fullpath type string value ''.


call method cl_gui_frontend_services=>file_save_dialog
exporting
default_extension = 'CSV'
file_filter = '*.CSV'
initial_directory = 'D:'
changing
filename = filename
path = path
fullpath = fullpath
exceptions
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
others = 4.

loop at gt_down into wa_down.
if not wa_down-runit is initial.
call function 'CONVERSION_EXIT_CUNIT_OUTPUT'
exporting
input = wa_down-runit
language = sy-langu
importing
* LONG_TEXT =
output = wa_down-runit
* SHORT_TEXT =
exceptions
unit_not_found = 1
others = 2.
endif.

condense wa_down-lcamount.
condense wa_down-tcamount.
condense wa_down-quantity.

modify gt_down from wa_down.
clear wa_down.
endloop.

* CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
* EXPORTING
* I_FIELD_SEPERATOR = ';'
* I_APPL_KEEP = 'X'
* TABLES
* I_TAB_SAP_DATA = gt_down[]
* CHANGING
* I_TAB_CONVERTED_DATA = gt_down1[]
* 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.
data lv_num(6) type c.
data lv_temp(32).
clear: wa_down , wa_down1,lv_temp,lv_num.
clear gt_down1.
refresh gt_down1.

loop at gt_down into wa_down.
clear wa_down1.
write wa_down-period to wa_down1(6).
write ';' to wa_down1+6(1).
write wa_down-rbukrs to wa_down1+7(3).
write ';' to wa_down1+10(1).
write wa_down-segment to wa_down1+11(2).
write ';' to wa_down1+13(1).
write wa_down-blank1 to wa_down1+14(12).
write ';' to wa_down1+26(1).
write wa_down-blank2 to wa_down1+27(12).
write ';' to wa_down1+39(1).
write wa_down-racct to wa_down1+40(12).
write ';' to wa_down1+52(1).
write wa_down-txt50 to wa_down1+53(30).
write ';' to wa_down1+83(1).
write wa_down-bilkt to wa_down1+84(12).
write ';' to wa_down1+96(1).
write wa_down-txt50_ga to wa_down1+97(30).
write ';' to wa_down1+127(1).
write wa_down-rcntr to wa_down1+128(12).
write ';' to wa_down1+140(1).
write wa_down-prctr_text to wa_down1+141(30).
write ';' to wa_down1+171(1).
write wa_down-rfarea to wa_down1+172(12).
write ';' to wa_down1+184(1).
write wa_down-fkbtx to wa_down1+185(30).
write ';' to wa_down1+215(1).
write wa_down-country to wa_down1+216(10).
write ';' to wa_down1+226(1).
write wa_down-product to wa_down1+227(15).
write ';' to wa_down1+242(1).
write wa_down-lcamount to wa_down1+243(20) right-justified.
write ';' to wa_down1+263(1).
write wa_down-quantity to wa_down1+264(20) right-justified.
write ';' to wa_down1+284(1).
write wa_down-runit to wa_down1+285(3).
write ';' to wa_down1+288(1).

write wa_down-rassc to wa_down1+289(33).
write ';' to wa_down1+322(1).
write wa_down-blank3 to wa_down1+323(12).
write ';' to wa_down1+335(1).
write wa_down-tcamount to wa_down1+336(20) right-justified.
write ';' to wa_down1+356(1).
write wa_down-rtcur to wa_down1+357(3).

append wa_down1 to gt_down1.
endloop.

call function 'GUI_DOWNLOAD'
exporting
filename = fullpath
tables
data_tab = gt_down1[]
endform. "down_load
[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11011430/viewspace-1017647/,如需轉載,請註明出處,否則將追究法律責任。

相關文章