SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
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.
Source Code
REPORT demo_describe_distance.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
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.
FIELD-SYMBOLS: <hex> TYPE x,
<result> TYPE c.
DESCRIBE DISTANCE BETWEEN:
struc AND struc-comp3 INTO DATA(off) IN BYTE MODE,
struc-comp3 AND struc-comp5 INTO DATA(len) IN BYTE MODE.
ASSIGN: struc TO <hex> CASTING,
<hex>+off(len) TO <result> CASTING.
cl_demo_output=>display(
|Offset off is { off }.\n| &&
|Length len is { len }.\n| &&
|<result> points to "{ <result> }".| ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
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!".