目录导航
声明:原创作品,转载时请注明文章来自SAP师太博客,并以超链接形式标明文章原始出处,否则将追究法律责任!
原文出自:
20.26. 下载文件... 257
20.26.1. 以BIN二进制下载... 257
20.26.2. 以字符模式下载... 258
20.26. 下载文件
20.26.1. 以BIN二进制下载
DATA: xstr TYPE xstring.
DATA: l_codepage(4) TYPE n .
DATA: l_encoding(20).
**********字符集名与内码转换
"将外部字符集名转换为内部编码
CALL FUNCTION ‘SCP_CODEPAGE_BY_EXTERNAL_NAME‘
EXPORTING
external_name = ‘UTF-8‘
IMPORTING
sap_codepage = l_codepage.
l_encoding = l_codepage.
**********编码
DATA: convout TYPE REF TO cl_abap_conv_out_ce.
"创建编码对象
convout = cl_abap_conv_out_ce=>create( encoding = l_encoding ).
convout->write( data = ‘江正军‘)."编码
xstr = convout->get_buffer( )."获取二进制码流
WRITE: / xstr."E6B19FE6ADA3E5869B
**********解码
DATA: convin TYPE REF TO cl_abap_conv_in_ce.
"创建解码对象
convin = cl_abap_conv_in_ce=>create( encoding = l_encoding input = xstr ).
DATA: str TYPE string.
CALL METHOD convin->read"解码
IMPORTING data = str.
WRITE: / str."江正军
TYPES : xx(100) TYPE x.
DATA: xtab TYPE STANDARD TABLE OF xx WITH HEADER LINE.
xtab = xstr.
APPEND xtab.
CALL FUNCTION ‘GUI_DOWNLOAD‘
EXPORTING
filename = ‘c:\2.txt‘
filetype = ‘BIN‘
TABLES
"data_tab的类型为ANY,所以xtab是一列还是多列,都会写到
"文件中去,这里还只有一列,而且还没有列名,这也没有关系
data_tab = xtab[].
20.26.2. 以字符模式下载
DATA: BEGIN OF strc OCCURS 0,
c1(2) TYPE c,
c2(1) TYPE c,
END OF strc.
strc-c1 = ‘中‘.
strc-c2 = ‘国‘.
APPEND strc.
APPEND strc.
CALL FUNCTION ‘GUI_DOWNLOAD‘
EXPORTING
* BIN_FILESIZE =
filename = ‘c:\1.txt‘
filetype = ‘DAT‘"列与列之间会使用TAB分隔
* APPEND = ‘ ‘
* WRITE_FIELD_SEPARATOR = ‘ ‘
* HEADER = ‘00‘
* codepage = ‘8400‘ "GBK
* codepage = ‘8450‘ "GB2312
codepage = ‘4110‘"utf-8
* CODEPAGE = ‘4102‘"UTF-16BE
* CODEPAGE = ‘4103‘"UTF-16LE
TABLES
data_tab = strc[].