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

VALUE - Structures

Syntax

... VALUE dtype|#( comp1 = dobj1 comp2 = dobj2 ... ) ...

Effect

If dtype is a structured data type or # represents a type like this, the individual components can be specified as named arguments comp1, comp2, ... Each component of the return value can be assigned a data object with the same data type as the component (or whose data type can be converted to this data type). This assignment is made for all data types in accordance with the appropriate assignment rules. dobj1, dobj2, ... are general expression positions.

If a component is itself structured, either a suitable data object can be assigned to the entire substructure or its components can be specified using the structure component selector (-).

Any components not specified are ignored and retain their type-specified initial value. It is not possible to assign multiple values to a component, regardless of how the component is addressed.

If the VALUE is used as a source of an assignment to a structure, this is initialized first and the assignments in the parentheses are executed directly (from left to right) with the structure components as target fields

Notes

Example

Three different ways of filling a nested structure struct with values. The structure is given the same values each time.

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

Example

This example displays the effects produced if components of a target structure are used as assignment sources. After the assignment, col1 and col2 have the value 0 and col3 and col4 have the value 5. The original values of col1 and col2 are not switched and col3 is not given the original value of col4.

DATA:
  BEGIN OF struct,
    col1 TYPE i VALUE 1,
    col2     TYPE i VALUE 2,
    col3 TYPE i VALUE 3,
    col4 TYPE i VALUE 4,
  END OF struct.

struct = value #( col1 = struct-col2
                  col2 = struct-col1
                  col4 = 5
                  col3 = struct-col4 ).

Example

See also the example for NEW.