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类型

本文介绍了如何在ABAP编程中使用`cl_abap_codepage.convert_to`方法进行字符类型到string和xstring类型的转换,包括直接赋值、快速定义以及隐式转换的实例。
1071

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



