Skip to content

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.

    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> }".| ).

Description

Determines the offset and length, in bytes, of a character-like fragment within the struc structure, accesses the fragment using an offset/length access, and assigns it a field symbol of type c. Since the structure is not purely character-like, the offset/length access takes place using a field symbol. If not, a syntax error occurs. The field symbol is of the type x, since offsets and lengths 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!".