ABAP顾问
分类:
2009-06-17 16:23:16
REPORT z_barry_test .
WRITE / 'aa'.
WRITE / '测试中文'.
PERFORM save_list USING '/usr/sap/listtext.txt' 'LIST20090617'.
*PERFORM write_list_from_db USING 'LIST20090617'.
*&---------------------------------------------------------------------*
*& Form save_list
*&---------------------------------------------------------------------*
FORM save_list USING dname id.
DATA: it_list LIKE abaplist OCCURS 0 WITH HEADER LINE ,
it_ascii LIKE w3html OCCURS 0 WITH HEADER LINE .
DATA wa_indx TYPE indx.
CALL FUNCTION 'SAVE_LIST'
EXPORTING
list_index = '0'
force_write = 'X'
TABLES
listobject = it_list
EXCEPTIONS
list_index_invalid = 1
OTHERS = 2.
**如果要放入簇数据库
wa_indx-aedat = sy-datum.
wa_indx-usera = sy-uname.
wa_indx-pgmid = sy-repid.
EXPORT itab = it_list TO DATABASE indx(lt) ID id FROM wa_indx .
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listasci = it_ascii
listobject = it_list
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
**下载到本地
* CALL FUNCTION 'GUI_DOWNLOAD'
* EXPORTING
* filename = 'C:\list.txt'
* TABLES
* data_tab = it_ascii.
**存储为Dataset
OPEN DATASET dname FOR OUTPUT IN TEXT MODE ENCODING UTF-8.
LOOP AT it_ascii .
TRANSFER it_ascii TO dname.
TRANSFER cl_abap_char_utilities=>cr_lf TO dname.
ENDLOOP.
CLOSE DATASET dname.
**下载Dataset到本地
* CALL FUNCTION 'C13Z_FILE_DOWNLOAD_BINARY'
* EXPORTING
* i_file_front_end = 'c:\list.txt'
* i_file_appl = dname
* i_file_overwrite = 'X'
* EXCEPTIONS
* fe_file_open_error = 1
* fe_file_exists = 2
* fe_file_write_error = 3
* ap_no_authority = 4
* ap_file_open_error = 5
* ap_file_empty = 6
* OTHERS = 7.
ENDFORM. "save_list
*&---------------------------------------------------------------------*
*& Form write_list_from_db
*&---------------------------------------------------------------------*
FORM write_list_from_db USING id .
DATA: it_list LIKE abaplist OCCURS 0 WITH HEADER LINE ,
it_ascii LIKE w3html OCCURS 0 WITH HEADER LINE .
DATA wa_indx TYPE indx.
IMPORT itab = it_list FROM DATABASE indx(lt) ID id.
CALL FUNCTION 'WRITE_LIST'
EXPORTING
write_only = 'X'
TABLES
listobject = it_list
EXCEPTIONS
empty_list = 1
OTHERS = 2.
ENDFORM. "read_list_from_db
注:SAVE_LIST 不适用于后台执行,会有只保存最后一页的Bug
chinaunix网友2009-07-01 22:14:32
白老师的博客是所有SAP博客里面技术最全面的,也是更新最快的,估计是没有时间写前因后果吧,不过我也希望白老师能多少写一点,O(∩_∩)O~