ABAP每日随笔 day 3 - 值转化和赋值

2022-06-23 15:09:56 浏览数 (2)

1.语法为 CONV dTYPE|#(...)

# 代表任意类型

"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 ).

"7.40之后

DATA text TYPE c LENGTH 255.

text = 'zhujx'.

DATA(xstr1) = cl_abap_codepage=>convert_to( source = CONV string( text ) ).

*OR

DATA(xstr2) = cl_abap_codepage=>convert_to( source = CONV #( text ) ).

"转化为16进制

2.新语法:操作值

"操作值

* Variables: VALUE dtype|#( )

*

* Structures: VALUE dtype|#( comp1 = a1 comp2 = a2 … )

*

* Tables: VALUE dtype|#( ( … ) ( … ) … ) …

TYPES:BEGIN OF ty_mara,

matnr TYPE mara-matnr,

matkl TYPE mara-matkl,

END OF ty_mara.

TYPES:BEGIN OF ty_makt,

maktx TYPE makt-maktx,

mara1 TYPE ty_mara,

END OF ty_makt.

"1 给变量赋值

DATA(lv_matnr) = 'AT001'.

"2 给结构赋值

DATA(ls_makt1) = VALUE ty_makt( maktx = 'TEST MATERIAL'

mara1-matnr = lv_matnr

mara1-matkl = 'Z001').

"3 给内表赋值

"(1)标准的内表

TYPES: ty_t_makt TYPE STANDARD TABLE OF ty_makt WITH EMPTY KEY.

DATA(lt_makt) = VALUE ty_t_makt(

( maktx = 'MATERIAL 1' mara1-matnr = 'AT001' mara1-matkl = 'Z001')

( maktx = 'MATERIAL 2' mara1-matnr = 'AT002' mara1-matkl = 'Z001')

( maktx = 'MATERIAL 3' mara1-matnr = 'AT003' mara1-matkl = 'Z001')

结果为:

-TAB 热爱技术 享受生活

0 人点赞