UNICODE系统中使用DATASET,如果是文本模式(IN TEXT MODE),则会要求编码方式(ENCODING),下面的例子说明了如何生成ANSI的文本文件或者UNICODE(UTF-8)的文本文件
REPORT z_barry_test.
DATA:BEGIN OF itab OCCURS 0 ,
matnr LIKE makt-matnr ,
maktx LIKE makt-maktx ,
END OF itab.
DATA:dname(120) TYPE c.
START-OF-SELECTION.
SELECT matnr maktx INTO TABLE itab FROM makt
UP TO 20 ROWS
WHERE spras = '1'.
dname = '/usr/sap/TZK/DVEBMGS00/work/test1.txt'.
OPEN DATASET dname FOR OUTPUT IN TEXT MODE ENCODING UTF-8. "UTF-8格式
IF sy-subrc NE 0. EXIT. ENDIF.
LOOP AT itab.
TRANSFER itab TO dname.
ENDLOOP.
CLOSE DATASET dname.
dname = '/usr/sap/TZK/DVEBMGS00/work/test2.txt'.
OPEN DATASET dname FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE. "ANSI格式
IF sy-subrc NE 0. EXIT. ENDIF.
LOOP AT itab.
TRANSFER itab TO dname.
ENDLOOP.
CLOSE DATASET dname.
注:如果使用ENCODING DEFAULT,则在UNICODE系统为UTF-8,在非UNICODE系统为ANSI
阅读(7220) | 评论(0) | 转发(0) |