matinal:SAP ABAP7.40及以上新语法-CONV 运算符

2023-10-26 14:28:36 浏览数 (2)

代码语言:javascript复制
CONV dtype|#( … )
 
dtype = Type you want to convert to (显式转换)
#     = compiler must use the context to decide the type to convert to (隐式转换)
 
*简单理解
DATA: LV_TEXT TYPE CHAR01,
      LV_STR TYPE STRING.
 
" 显式转换:将LV_TEXT转换成STRING类型
LV_STR = CONV STRING( LV_TEXT ).
" 隐式转换:将LV_TEXT转换成LV_STR的类型
LV_STR = CONV #( LV_TEXT ).

"before
DATA text   TYPE c LENGTH 255.
DATA helper TYPE string.
DATA xstr   TYPE xstring.
helper = text.
xstr = cl_abap_codepage=>convert_to( source = helper ).
"740
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 ) ).

0 人点赞