VALUE

2019-08-22  本文已影响0人  abapCiCi

value

Syntax :

VALUE type( ... )
When an initial value VALUE #( ) is passed to a 
generically typed formal parameter, the type is derived from the generic type.

for example

TYPES:
   BEGIN OF date,
     year  TYPE c LENGTH 4,
     month TYPE c LENGTH 2,
     day   TYPE c LENGTH 2,
   END OF date,
   dates TYPE TABLE OF date WITH EMPTY KEY.

DATA(dates) = VALUE dates(
  ( year = '2013' month = '07' day = '16' )
  ( year = '2014' month = '08' day = '31' )
  ( year = '2015' month = '09' day = '07' ) ).

If you want to add content

dates  = VALUE dates( BASE dates ( year = '2016' month = '07' day = '16'  ) ).

If you don't want rewrite multiple times

 year = '2015'
  (  month = '07' day = '16' )
  (  month = '07' day = '16' )
  ).

About struct assignment

TYPES:  BEGIN OF t_col2, 
           col1 TYPE i, 
           col2 TYPE i, 
        END OF t_col2. 
TYPES: BEGIN OF t_struct, 
         col1 TYPE i, 
         col2 TYPE t_col2, 
       END OF t_struct. 
DATA: struct TYPE t_struct, 
      col2 TYPE t_col2. 
struct = VALUE t_struct( col1 = 1 
                         col2-col1 = 1 
                         col2-col2 = 2 ). 
col2   = VALUE   t_col2( col1 = 1 
                         col2 = 2 ). 
struct = VALUE t_struct( col1 = 1 
                         col2 = col2 ). 
struct = VALUE t_struct( col1 = 1 
                         col2 = VALUE #( col1 = 1 
                                         col2 = 2 ) )."嵌套结构

using let in

struct2 = VALUE #( LET x = struct2 IN 
                   col1 = x-col2 
                   col2 = x-col1 
                   col4 = 5 
                   col3 = x-col4 ). 

using correspongding

struct1 = VALUE #( BASE CORRESPONDING #( struct2 ) col4 = 4 col5 = 5 ). 

using 'new' replace something

DATA(base2)   = `xxyyzz`. 
DATA(ref2)  = NEW struct( BASE base2 col2 = 'BB' )
 "result is  xxbbzz 

new statement to create 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 )  ). 

lines of

DATA(itab3) = itab.
itab3 = VALUE #( BASE itab3
                 ( LINES OF itab3 )"两次添加数据 
                 ( 4 )
                 ( 5 ) ).
上一篇 下一篇

猜你喜欢

热点阅读