SAP DESCRIBE DISTANCE ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• DESCRIBE DISTANCE ABAP Statement
• INTO DESCRIBE DISTANCE
• IN BYTE MODE DESCRIBE DISTANCE
• IN CHARACTER MODE DESCRIBE DISTANCE

DESCRIBE DISTANCE
Short Reference

ABAP_SYNTAX
DESCRIBE DISTANCE BETWEEN dobj1 AND dobj2 INTO dst
IN ${BYTE$|CHARACTER$} MODE.

What does it do?
This statement determines the distance between the start positions of the data objects dobj1 and dobj2.
The return value has the type i. The following can be specified for dst:
An existing variable to which the return value can be converted.
An inline declaration DATA(var) or FINAL(var), where a variable of type i is declared.
It is not important in which order dobj1 and dobj2 are specified.
The variant with the addition IN BYTE MODE determines the distance in bytes. The variant with the addition IN CHARACTER MODE converts the distance into the number of characters that can be stored in this length according to the current character format. When this addition is used in IN CHARACTER MODE and the determined distance cannot be converted into a number of characters, an uncatchable exception is raised.
In the case of deeper data types, the referenced data object is not relevant but the position of the internal reference (for strings and internal tables) or the reference variables instead.



Latest notes:

The distance between data objects should only be determined within a structure for its components, since this is the only way to guarantee that they follow each other directly in the memory. It should be noted that the alignment gaps are counted as well, which is why the addition in IN BYTE MODE should be used to avoid an uncatchable exception.
The byte offset of a component in a structure can be determined by applying DESCRIBE DISTANCE to this component and the first component of the structure.
With respect to DESCRIBE DISTANCE, every substructure declared as a boxed component is an independent structure. The distance between components which are not in the same boxed component is undefined.
ABAP_HINT_END



Example ABAP Coding

The results of the two statements in a Unicode system are 5 and 10.
ABEXA 00218
ABAP_EXAMPLE_END



Example ABAP Coding

The DESCRIBE statement returns the offset of component col3 in structure struct in bytes. The result is 8. It consists of 1 byte for col1, 3 bytes for an alignment gap, and 4 bytes for col2.
ABEXA 01741
ABAP_EXAMPLE_END

ABAP_EXAMPLE_ABEXA
Determining Data Object Distances
ABAP_EXAMPLE_END



Runtime Exceptions


Non-catchable Exceptions
Reason for error:
Distance cannot be converted into characters.
Runtime error:
UC_NO_CHAR_NUMBER
ABAP_NONCAT_END

Return to menu