Structures
A structure in ABAP is a composite data type grouping several fields, like a single row of a table. Structures and internal tables together are how ABAP models and moves business data.
Structures can contain other structures and even internal tables (deep structures), useful for representing complex documents (a header structure containing an items table).
- A structure bundles related fields (of possibly different types) under one name, for example an order structure with order id…
- Often you type a structure directly from a dictionary structure or a table’s line type (DATA ls_mara TYPE mara), so it always…
- Structures and internal tables together are how ABAP models and moves business data.
- Watch out: Field mismatches from hand-defining instead of dictionary typing.
What a structure is
A structure bundles related fields (of possibly different types) under one name, for example an order structure with order id, customer, date and amount. A single structure holds one record; an internal table of that structure holds many. Structures can mirror dictionary types (e.g. a table’s row type) or be defined locally.
Declaring and using structures
TYPES: BEGIN OF ty_order,
id TYPE vbeln,
customer TYPE kunnr,
amount TYPE p LENGTH 9 DECIMALS 2,
END OF ty_order.
DATA ls_order TYPE ty_order.
ls_order-id = '0000001234'.
ls_order-amount = '150.00'.Structures and the dictionary
Often you type a structure directly from a dictionary structure or a table’s line type (DATA ls_mara TYPE mara), so it always matches the database definition. This keeps custom code aligned with SAP’s data model and avoids field mismatches.
Nested and deep structures
Structures can contain other structures and even internal tables (deep structures), useful for representing complex documents (a header structure containing an items table). Understanding work areas (a structure used to process one row of a table) is key to looping and reading tables.
Common pitfalls
- Field mismatches from hand-defining instead of dictionary typing.
- Confusing a structure (one row) with a table (many).
- Deep structures misunderstood when moving/among components.