ABAP - Keyword Documentation →  ABAP - Programming Language →  Creating Objects and Values →  VALUE, Value Operator → 
Mail Feedback

VALUE, Internal Tables

Syntax

... VALUE dtype|#( [let_exp]
                   [BASE itab]
                   [FOR for_exp1
                    FOR for_exp2
                    ... ]
                   ( line_spec1 )
                   ( line_spec2 )
                     ... ) ...


Additions:

1. ... BASE itab

2. ... FOR for_exp

Effect

If dtype is a tabular data type or # stands for such a type, the table lines of the constructed table are created as follows:

The constructed lines must meet the requirements of the statement INSERT for inserting work areas using table keys and therefore be compatible with the line type, with one exception: when constructing a standard table where the lines are only appended anyway, the value can be shorter than the line length for line types c and x and then 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, it is first initialized after the evaluation of a possible LET expression or is assigned the content of itab. Then, line_spec data is then evaluated and inserted directly into the target table.

Hints



Example

Construction of an internal table with a structured line type and filling it with two lines. 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

Construction of an internal table with a tabular line type and filling it with two lines. The first line is assigned a table that is already filled. The second line 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 ) ) ) ).

Executable Examples



Addition 1  

... BASE itab

Effect

An addition, BASE, followed by an internal table, itab, can be specified in front of the specification of lines to be inserted. itab is a functional operand position. The line type of itab must be convertible to the line type of the return value. If BASE is specified, the content of itab is assigned to the return value before the individual lines 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 it is known.

Hints



Example

Use of BASE. The table type of base1 or base2 is transferred in the construction of tab1 and tab2. This is not possible in the construction of tab3 since the line type of base2 is not structured and hence does not match the specification of individual components in the following parentheses. The type itab2 is specified explicitly for tab3. This is possible since the line type of base2 can be converted into this line type. Since sorted tables are constructed, the lines 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.

FINAL(base1) = VALUE itab1(
                ( `x1y1z1` )
                ( `x2y2z2` )
                ( `x3y3z3` ) ).
FINAL(base2) = VALUE itab2(
                ( col1 = 'x1' col2 = 'y1' col3 = 'z1' )
                ( col1 = 'x2' col2 = 'y2' col3 = 'z2' )
                ( col1 = 'x3' col2 = 'y3' col3 = 'z3' ) ).

FINAL(tab1) = VALUE #( BASE base1
               ( `A1B1B1` )
               ( `A2B2B2` ) ).

FINAL(tab2)  = VALUE #(
                BASE base2
                ( col1 = 'A1' col2 = 'B1' col3 = 'C1' )
                ( col1 = 'A2' col2 = 'B2' col3 = 'C2' ) ).

FINAL(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

Use of BASE to append lines to existing lines 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

Use of BASE to append lines to an internal table in a loop. After the output, it is shown 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.

Executable Example

VALUE - Addition BASE for Internal Tables

Addition 2  

... FOR for_exp

Effect

The specification of one or more consecutive iteration expressions using FOR, this means that the lines constructed in line_spec for each iteration of the last FOR expression are inserted into the target table. When constructing table lines in line_spec, the visible local work areas and field symbols of the iteration expressions can be used to construct the table lines.

Hints

Example

Construction of a temporary internal table with an elementary line type and filling 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



Continue
VALUE, line_spec
Example VALUE, Operator for Internal Tables
Example VALUE, Operator with LET for Internal Tables
Example VALUE, Addition BASE for Internal Tables