AS ABAP Release 754, ©Copyright 2019 SAP SE. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Creating Objects and Values → VALUE - Value Operator →VALUE - Internal Tables
Syntax
... VALUE dtype|#( [let_exp]
[BASE itab]
[FOR for_exp1
FOR for_exp2
... ]
( line_spec1 )
( line_spec2 )
... ) ...
Extras:
1. ... BASE itab
2. ... FOR for_exp
Effect
If dtype is a tabular data type or # stands for a type like this, the table rows of the constructed table are created as follows:
The constructed rows must meet the requirements of the statement INSERT for inserting work areas using table keys and therefore be compatible with the row type. There is one exception to this: When constructing a standard table, where the rows are only appended, the value can be shorter than the row length (for row types c and x), in which case it is padded on the right with blanks or hexadecimal 0.
If the VALUE operator is used as the source of an assignment to an internal table, this table is first initialized after the evaluation of the LET expression (if available) or is assigned the content of itab. The line_spec data is then evaluated and inserted directly in the target table.
Notes
Example
Constructs an internal table with a structured row type and fills it with two rows. The structures are filled with values component by component.
TYPES: BEGIN OF t_struct,
col1 TYPE i,
col2 TYPE i,
END OF t_struct,
t_itab TYPE TABLE OF t_struct WITH EMPTY KEY.
DATA itab TYPE t_itab.
itab = VALUE #( ( col1 = 1 col2 = 2 )
( col1 = 3 col2 = 4 ) ).
Example
Constructs an internal table with a tabular row type and fills it with two rows. The first row is assigned a table that is already filled. The second row is constructed using VALUE.
TYPES: t_itab1 TYPE TABLE OF i WITH EMPTY KEY,
t_itab2 TYPE TABLE OF t_itab1 WITH EMPTY KEY.
DATA itab1 TYPE t_itab1.
DATA itab2 TYPE t_itab2.
itab1 = VALUE #( ( 1 ) ( 2 ) ( 3 ) ).
itab2 = VALUE #( ( itab1 )
( VALUE t_itab1( ( 4 ) ( 5 ) ( 6 ) ) ) ).
Examples
See also the examples for the instance operator NEW.
Executable Examples
... BASE itab
Effect
An addition, BASE, followed by an internal table, itab, can be specified in front of the lines that you want to insert. This is a functional operand position. The row type of itab must be convertible to the row type of the return value. If BASE is specified, the content of itab is assigned to the return value before the individual rows are inserted. If the character # is specified for the type of the return value and the type cannot be determined from the operand position of the constructor expression, the type of itab is used for this expression (if identifiable).
Notes
Example
Uses BASE. The table type of base1 or base2 is applied in the construction of tab1 and tab2. This is not possible in the construction of tab3 since the row type of base2 is not structured and hence not suitable for specifying individual components in the parentheses that follow. The type itab2 is specified explicitly for tab3. This is possible since the row type of base2 can be converted into this row type. Sorted tables are constructed, which means that the rows in the results are also sorted.
TYPES:
itab1 TYPE SORTED TABLE OF string WITH UNIQUE KEY table_line,
BEGIN OF struct,
col1 TYPE c LENGTH 2,
col2 TYPE c LENGTH 2,
col3 TYPE c LENGTH 2,
END OF struct,
itab2 TYPE SORTED TABLE OF struct WITH UNIQUE KEY col1 col2 col3.
DATA(base1) = VALUE itab1(
( `x1y1z1` )
( `x2y2z2` )
( `x3y3z3` ) ).
DATA(base2) = VALUE itab2(
( col1 = 'x1' col2 = 'y1' col3 = 'z1' )
( col1 = 'x2' col2 = 'y2' col3 = 'z2' )
( col1 = 'x3' col2 = 'y3' col3 = 'z3' ) ).
DATA(tab1) = VALUE #( BASE base1
( `A1B1B1` )
( `A2B2B2` ) ).
DATA(tab2) = VALUE #(
BASE base2
( col1 = 'A1' col2 = 'B1' col3 = 'C1' )
( col1 = 'A2' col2 = 'B2' col3 = 'C2' ) ).
DATA(tab3) = VALUE itab2( BASE base1
( col1 = 'A1' col2 = 'B1' col3 = 'C1' )
( col1 = 'A2' col2 = 'B2' col3 = 'C2' ) ).
cl_demo_output=>write( tab1 ).
cl_demo_output=>write( tab2 ).
cl_demo_output=>display( tab3 ).
Example
Uses BASE to append rows to existing rows in an internal table.
TYPES itab TYPE TABLE OF string WITH EMPTY KEY.
DATA(itab) =
VALUE itab(
( `a` ) ( `b` ) ( `c` ) ).
...
itab =
VALUE #(
BASE itab
( `d` ) ( `e` ) ( `f` ) ).
cl_demo_output=>display( itab ).
Example
Uses BASE to append rows to an internal table in a loop. After the output, it possible to see how the same function can be applied using an iteration expression with FOR.
DATA itab TYPE TABLE OF i WITH EMPTY KEY.
DO 10 TIMES.
itab = VALUE #( BASE itab ( ipow( base = sy-index exp = 2 ) ) ).
ENDDO.
cl_demo_output=>display( itab ).
DATA jtab LIKE itab.
jtab = VALUE #( FOR j = 1 UNTIL j > 10
( ipow( base = j exp = 2 ) ) ).
ASSERT jtab = itab.
... FOR for_exp
Effect
If one or more iteration expressions are specified consecutively using FOR, this means that the rows constructed in line_spec for every iteration of the last FOR expression are inserted into the target table. When constructing table rows in line_spec, the visible local work areas and field symbols of the iteration expressions can be used to construct table rows.
Notes
Example
Constructs a temporary internal table with an elementary row type and fills it with square numbers using an iteration expression.
TYPES t_itab TYPE TABLE OF i WITH EMPTY KEY.
cl_demo_output=>display(
VALUE t_itab( FOR i = 1 UNTIL i > 10
( ipow( base = i exp = 2 ) ) ) ).
Executable Examples
VALUE - Operator for Internal Tables
VALUE - Operator with LET for Internal Tables