Keep related address fields together
A delivery has an identifier and a destination. The destination itself has a city and postal code. Nesting those fields gives them a clear owner, rather than adding ambiguous names such as city beside unrelated delivery fields.
Define and populate the nested shape
TYPES: BEGIN OF ty_address,
city TYPE string,
postal_code TYPE string,
END OF ty_address.
TYPES: BEGIN OF ty_delivery,
delivery_id TYPE string,
destination TYPE ty_address,
END OF ty_delivery.
DATA(delivery) = VALUE ty_delivery(
delivery_id = 'D-301'
destination = VALUE #( city = 'Northport' postal_code = 'N4 2AB' ) ).
The inner VALUE #( ... ) gets its type from the destination component. You can also spell out VALUE ty_address( ... ) when that is clearer to a reader. Access a nested field with delivery-destination-city.
Nested structures help express ownership, but don’t nest everything automatically. If a data shape is shared, use a well-defined reusable type. If it is just a one-off report row, a simpler flat structure may be easier to understand.
Sources
- SAP Samples: Structures — variants and nested structures
- ABAP Keyword Documentation: nested structures
Developer practice · ABAP
Practice: build a nested destination
Define a destination substructure, place it inside a delivery, and capture the city in result.
This choice changes the output pattern checked here: WRITE belongs in a classic executable report, while out->write( ) uses the supplied output reference in an ABAP Cloud class-run method. It does not switch the language version of the other code; check release and API availability in your target system.
Complete the task and include the output statement shown for your selected environment. Variable names can differ if you use them consistently. This browser checker checks structure only; it does not compile or run ABAP.
0 required structures detected · 0 checks
Write your solution, then check its structure.
One possible solution
TYPES: BEGIN OF ty_address,
city TYPE string,
postal_code TYPE string,
END OF ty_address.
TYPES: BEGIN OF ty_delivery,
delivery_id TYPE string,
destination TYPE ty_address,
END OF ty_delivery.
DATA(delivery) = VALUE ty_delivery( delivery_id = 'D-301' destination = VALUE #( city = 'Northport' postal_code = 'N4 2AB' ) ).
DATA(result) = delivery-destination-city.
WRITE result.out->write( result ).These are context-specific output examples. In your own program, use the result variable from your solution and the output mechanism available in that program.