ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Structures → Examples of structures
Filling a Structure
The example demonstrates the filling of a nested structure.
Other versions:
7.31 | 7.40 | 7.54
Source Code
DATA: name TYPE name_type,
addr TYPE address_type.
name-title = `Mr.`.
name-prename = `Duncan`.
name-surname = `Pea`.
addr-name = name.
addr-street-name = `Vegetable Lane`.
addr-street-number = `11`.
addr-city-zipcode = `349875`.
addr-city-name = `Botanica`.
DATA(address) =
VALUE address_type(
name-title = `Mr.`
name-prename = `Duncan`
name-surname = `Pea`
street = VALUE #( name = `Vegetable Lane`
number = `11` )
city = VALUE #( zipcode = `349875`
name = `Botanica` ) ).
ASSERT address = addr.
cl_demo_output=>new(
)->write( address-name
)->write( address-street
)->write( address-city
)->display( ).
Description
In this example, the structure from the executable example
Declaring a Nested Structure is defined with
TYPES as the data type
address_type and used for the data objects addr and address. A structure type is also defined for each separate substructure.
If a structure is declared by reference to a structure type, as shown here, the addition
VALUE cannot be used. Instead, the structure must be filled by accessing
the components. In particular, this also applies to the frequently occurring reference to structures of the ABAP Dictionary.
- In the first part of the method
main, the structureaddris filled by using the structure component selector. The componentnameis assigned a prefilled structure. In the componentsstreetandcity, the components that are nested there are accessed.
- In the second part of the method
main, the structureaddressis filled with the value operator VALUE, but the structure itself is created using an inline declaration. The parentheses afterVALUEshow different options for accessing the components of substructures. Either the structure component selector is used again, as with the substructurename, or additionalVALUEoperators are nested, as withstreetandcity.
The content of the two structures is the same. The value operator VALUE can be used to replace many fully spelled names simply by using parentheses.