matinal:SAP ABAP 7.40及以上新语法之VALUE 运算符

2023-10-29 14:12:37 浏览数 (2)

直接上代码

代码语言:javascript复制
*定义
变量:VALUE dtype|#( )
结构:VALUE dtype|#( comp1 = a1 comp2 = a2 … )
内表:VALUE dtype|#( ( … ) ( … ) … ) …
*结构赋值
TYPES:  BEGIN OF ty_columns1, “Simple structure
            cols1 TYPE i,
            cols2 TYPE i,
        END OF ty_columns1.
TYPES: BEGIN OF ty_columnns2,  “Nested structure
            coln1 TYPE i,
            coln2 TYPE ty_columns1,
       END OF ty_columns2.
DATA: struc_simple TYPE ty_columns1,
      struc_nest   TYPE ty_columns2.
struct_nest = VALUE t_struct(coln1 = 1
                             coln2-cols1 = 1
                             coln2-cols2 = 2 
                            ).
 或者
struct_nest = VALUE t_struct(coln1 = 1
                             coln2 = VALUE #( cols1 = 1
                                              cols2 = 2 ) 
*内表赋值
" 内表
TYPES t_itab TYPE TABLE OF i WITH EMPTY KEY.
DATA itab TYPE t_itab.
itab = VALUE #( ( ) ( 1 ) ( 2 ) ).
 
" Range
DATA itab TYPE RANGE OF i.
itab = VALUE #( sign = 'I'  option = 'BT' ( low = 1  high = 10 )
                                          ( low = 21 high = 30 )
                                          ( low = 41 high = 50 )
                            option = 'GE' ( low = 61 )  
              )

0 人点赞