[SAP ABAP开发技术总结]以二进制、字符模式下载文件

时间:2023-03-08 23:15:21
[SAP ABAP开发技术总结]以二进制、字符模式下载文件
[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

:

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[]

.

CODEPAGE

l

Description

Use parameter CODEPAGE to specify the desired target codepage. If this
parameter is not set, the codepage of the SAP GUI is used as the target
codepage.

如果不指定,则使用

SAP GUI

所使用的

Codepage

l

Value range

4-digit number of the SAP codepage. The function module

SCP_CODEPAGE_BY_EXTERNAL_NAME

returns the SAP codepage number for an external character set name, for
example, "iso-8859-1". The function module NLS_GET_FRONTEND_CP returns
the appropriate non-Unicode frontend codepage for a language.

You can determine the desired codepage interactively, if the parameter
with_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

[SAP ABAP开发技术总结]以二进制、字符模式下载文件

另外,发现

TCP00

表里也存储了

CODEPAGE

,而且该表有一个

CPCOMPANY

字段标示该代码是由哪个组织定义的(一般我们使用

ISO

国际标准),可以将

TCP00A

TCP00

通过

CODEPAGE

联合起来查询,

TCP00A

可以根据字符集名称(如

GBK

UTF-8

TCP00A-CPATTR

来查询,而

TCP00

可以根据字符集描述(如:

Chinese

)来查询

TCP00-

CPCOMMENT