740前
我们可以使用 方法 cl_abap_codepage=>convert_to 来转换字段类型,如下列代码
DATA text TYPE c LENGTH 255.
DATA helper TYPE string.
DATA xstr TYPE xstring.
helper = text. "char类型转换为string类型直接用等于赋值即可 helper = text.
xstr = cl_abap_codepage=>convert_to( source = helper ). "string类型转换为xstring类型
740之后
可以结合快速定义来转换类型
DATA text TYPE c LENGTH 255.
DATA(xstr1) = cl_abap_codepage=>convert_to( source = CONV string( text ) ).""指定转换为xstring类型
DATA(xstr2) = cl_abap_codepage=>convert_to( source = CONV #( text ) ).""根据上下文代码隐式转换
上面的代码运行结束后xstr1,xstr2都是xstring类型
|
Before 7.40 |
|---|
|
DATA text TYPE c LENGTH 255. DATA helper TYPE string. DATA xstr TYPE xstring. helper = text. xstr = cl_abap_codepage=>convert_to( source = helper ). |
|
With 7.40 |
|
DATA text TYPE c LENGTH 255. DATA(xstr) = cl_abap_codepage=>convert_to( source = CONV string( text ) ). OR DATA(xstr) = cl_abap_codepage=>convert_to( source = CONV #( text ) ). |
本文介绍了ABAP在7.40版本前后如何进行数据类型的转换,特别是从`char`到`string`再到`xstring`的过程。在7.40之前,需要通过辅助变量和`cl_abap_codepage=>convert_to`函数进行转换,而7.40之后,可以使用`CONV string(text)`或`CONV #(text)`来更简洁地完成转换。

1285

被折叠的 条评论
为什么被折叠?



