ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Attributes of Data Objects → DESCRIBE → DESCRIBE DISTANCE
Determining Data Object Distances
The example demonstrates how the distance between two data objects can be determined at runtime.
Other versions: 7.31 | 7.40 | 7.54
Source Code
DATA: BEGIN OF struc,
comp1 TYPE i,
comp2 TYPE x LENGTH 1,
comp3 TYPE c LENGTH 4 VALUE 'Hey',
comp4 TYPE c LENGTH 4 VALUE 'you!',
comp5 TYPE x,
END OF struc.
DATA: off TYPE i,
len TYPE i.
FIELD-SYMBOLS: <hex> TYPE x,
<result> TYPE c.
DESCRIBE DISTANCE BETWEEN:
struc AND struc-comp3 INTO off IN BYTE MODE,
struc-comp3 AND struc-comp5 INTO len IN BYTE MODE.
ASSIGN: struc TO <hex> CASTING,
<hex>+off(len) TO <result> CASTING.
WRITE: / 'Offset off is', off,
/ 'Length len is', len,
/ '<result> points to', <result>.
Description
Determining the offset and length, in bytes, of a character-like fragment within the struc
structure, access to the fragment using an offset/length access and assignment to a field symbol of
type c
. Since the structure is not purely character-like, the offset/length
access takes place using a field symbol, otherwise a syntax error occurs in a Unicode program. The field symbol is of the type x
, since offset and length are determined in bytes. In
Unicode systems, a different
value is identified for off
than in non-Unicode systems because of the alignment
gap before comp3
. The <result>
field symbol has the same content in both cases "Hey you!".