ABAP Keyword Documentation → ABAP − Reference → Declarations → Declaration Statements → Data Types and Data Objects → Types and Objects - Overview → Data Objects
Alignment of Data Objects
Data objects with certain data types cannot be saved to random addresses in the main memory:
s
by 2
i
by 4
int8
,decfloat16
,f
by 8
decfloat34
by 16
utclong
must be divisible by eight.
An elementary data object is aligned when it has an address that corresponds to its data type.
- A structure is aligned when the following applies:
- Its start address satisfies the strictest alignment requirements of its components and
- The offsets of all components satisfy the same type-specific divisibility requirements.
The correct alignment of data objects is not normally an issue, because they are created correctly automatically in the declaration. This can produce alignment gaps in structures with components of different data types.
However, the alignment must be checked in the following cases:
- In assignments and comparisons of structures where the structure fragment view that splits a structure into fragments in accordance with its alignment gaps must be respected.
- When a data object is handled using explicit or implicit casting with another data type.
- When a work area that has a different type from the database table is used in an ABAP SQL statement.
If a statement expects a particular alignment of a data object, an exception is raised if there is insufficient alignment.
Other versions: 7.31 | 7.40 | 7.54
Notes
- Components that are included in structures using
INCLUDE TYPE|STRUCTURE
behave like genuine substructures with respect to alignment.
- The binary content of alignment gaps is not defined and cannot be evaluated.
- Alignment gaps can also occur at the end of structures, since the overall length of the structure is determined by the component with the largest alignment requirement.
- Alignment gaps are part of the length of a structure.
Example
The following alignment gaps (A) appear in the following structure:
The first alignment gap is constructed as a result of the alignment of the substructure struc2
,
the second gap is due to the alignment of the component c
of type c
,
and the third is due to the component d
of type i
.
DATA:
BEGIN OF struc1,
a TYPE x LENGTH 1,
BEGIN OF struc2,
b TYPE x LENGTH 1,
c TYPE c LENGTH 6,
END OF struc2,
d TYPE i,
END OF struc1.