Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Creating Objects and Values →  VALUE - Value Operator 

VALUE - Internal Tables

Other versions: 7.31 | 7.40 | 7.54

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:

  • Firstly, an optional LET expression let_exp can be specified to define local auxiliary fields whose values can be used to construct the table rows.
  • An optional start value for the content can be specified for the content of the internal table after BASE (see below).
  • Then the table rows are constructed in one or more internal parentheses by specifying line_spec. Each inner parenthesis constructs one or more rows in accordance with the information in line_spec and inserts them into the new internal table in accordance with the rules for the statement INSERT ... INTO TABLE. The rows are inserted in the order of the parentheses.

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

  • In an assignment of the constructor expression to an internal table, its existing rows cannot be used directly as an argument in line_spec. This is because this table is deleted before line_spec is evaluated or overwritten by the content of itab. If the entire internal table or rows from the left side are needed on the right side, however, they can be saved in local auxiliary variables using a LET expression, since this expression is evaluated first.

  • The operand type for line_spec in the inner parentheses is the row type of the table type specified using dtype or #, which means it is always uniquely identifiable. Constructor expressions in this place can therefore always derive the required data type using #.

Addition 1

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

  • If the addition BASE is not specified, only new content of tables can be constructed with the value operator and not enhanced. If the same table is specified after BASE to which the constructor expression is assigned, further rows can be inserted in this table.

  • If the target table is specified as itab after BASE in an assignment to an existing internal table, no assignment takes place before line_spec is evaluated, and the target table just keeps its value instead.

Addition 2

... FOR for_exp

Effect

If one or more iteration expressions are specified one after the other using FOR, this means that the lines 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 also be used.

  • If table iterations are used, the rows of existing internal tables are evaluated. This is known as table comprehensions, since new table rows can be constructed from the rows of existing internal tables.


Notes

  • The term "table comprehension" is derived from similar concepts used in many other languages, where it is also known as "list comprehension".

  • For tasks that can be solved with table comprehensions and also with special assignments for components (in particular the component operator CORRESPONDING), we recommend the use of assignments (see example).

  • If the VALUE operator is used, it should be noted that assignments to internal tables are also initialized (or given the content of itab after base) even in the case of table comprehensions after the evaluation of a LET expressions. The target table is then used directly. The original table can therefore not be used directly in the FOR expressions (unless it is assigned to an auxiliary variable after LET).

Example

Constructs an internal table with an elementary row type. jtab is filled with three rows and itab with six rows. The first row inserted in itab is initial and the last three rows are taken from the table jtab filled previously.

TYPES t_itab TYPE TABLE OF i WITH EMPTY KEY. 

DATA(jtab) = VALUE t_itab( ( 10 ) ( 20 ) ( 30 ) ). 

DATA(itab) = VALUE t_itab( ( ) ( 1 ) ( 2 ) ( LINES OF jtab ) ). 

cl_demo_output=>display( itab ).

Example

Constructs an internal table with an elementary row type of type string and fills it with three rows. The result is a table that is given the previous day, current day, and next day formatted for the current language environment. Today's is produced using a method. To make sure that the method is called only once, the return value is assigned to a local auxiliary field in a LET expression.

CLASS date DEFINITION. 
  PUBLIC SECTION. 
    CLASS-METHODS get RETURNING VALUE(d) TYPE d. 
ENDCLASS. 

CLASS date IMPLEMENTATION. 
  METHOD get. 
    d = sy-datlo. 
  ENDMETHOD. 
ENDCLASS. 

TYPES t_date_tab TYPE TABLE OF string  WITH EMPTY KEY. 

DATA date_tab TYPE t_date_tab. 

START-OF-SELECTION. 

  date_tab = VALUE #( 
               LET d = date=>get( ) IN 
               ( |{ CONV d( d - 1 ) DATE = ENVIRONMENT }| ) 
               ( |{        d       DATE = ENVIRONMENT }| ) 
              ( |{ CONV d( d + 1 ) DATE = ENVIRONMENT }| ) ).

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 a ranges table and fills it with four rows while using the short form for structured row types.

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

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

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 suitable for specifying individual components in the following parentheses. 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 interation 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.

Examples of Table Comprehensions

See Examples of Table Comprehensions.


Note

See also the examples for the instance operator NEW.

Continue

VALUE - line_spec