[SAP ABAP开发技术总结]以二进制、字符模式下载文件
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将追究法律责任!原文链接:http://www.cnblogs.com/jiangzhengjun/p/4265688.html
20.26. 下载文件...257
20.26.1. 以BIN二进制下载...257
20.26.2. 以字符模式下载...258
20.26. 下载文件
20.26.1. 以BIN二进制下载
DATA:xstrTYPExstring.
DATA: l_codepage(4)TYPEn.
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:convoutTYPE REF TOcl_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:convinTYPE REF TOcl_abap_conv_in_ce.
"创建解码对象
convin=cl_abap_conv_in_ce=>create(encoding=l_encodinginput=xstr).
DATA:strTYPEstring.
CALL METHODconvin->read"解码
IMPORTING data=str.
WRITE:/ str."江正军
TYPES:xx(100)TYPE x.
DATA:xtabTYPE STANDARD TABLE OFxxWITH HEADER LINE.
xtab=xstr.
APPENDxtab.
CALL FUNCTION'GUI_DOWNLOAD'
EXPORTING
filename ='c:\2.txt'
filetype ='BIN'
TABLES
"data_tab的类型为ANY,所以xtab是一列还是多列,都会写到
"文件中去,这里还只有一列,而且还没有列名,这也没有关系
data_tab =xtab[].
20.26.2. 以字符模式下载
DATA:BEGIN OFstrcOCCURS0,
c1(2)TYPE c,
c2(1)TYPE c,
END OFstrc.
strc-c1='中'.
strc-c2='国'.
APPENDstrc.
APPENDstrc.
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[].
CODEPAGE
l Description
Use parameter CODEPAGE to specify the desired target codepage. If thisparameter is not set, the codepage of the SAP GUI is used as the targetcodepage.如果不指定,则使用SAP GUI所使用的Codepage。
l Value range
4-digit number of the SAP codepage. The function moduleSCP_CODEPAGE_BY_EXTERNAL_NAMEreturns the SAP codepage number for an external character set name, forexample, "iso-8859-1". The function module NLS_GET_FRONTEND_CP returnsthe appropriate non-Unicode frontend codepage for a language.
You can determine the desired codepage interactively, if the parameterwith_encoding of method file_save_dialog is set by cl_gui_frontend_services.
SPACE: Codepage of the SAP GUI
l Default
SPACE
SCP_CODEPAGE_BY_EXTERNAL_NAME
该函数可将字符集名称转换为CODEPAGE,也可以直接查看TCP00A表
另外,发现TCP00表里也存储了CODEPAGE,而且该表有一个CPCOMPANY字段标示该代码是由哪个组织定义的(一般我们使用ISO国际标准),可以将TCP00A与TCP00通过CODEPAGE联合起来查询,TCP00A可以根据字符集名称(如GBK、UTF-8)TCP00A-CPATTR来查询,而TCP00可以根据字符集描述(如:Chinese)来查询TCP00-CPCOMMENT。
页:
[1]