SAP DISTANCE FUNCTIONS



Get Example source ABAP code based on a different SAP table
  


• distance ABAP_FUNCTION
• max distance function

ABAP_STRINGFUNC - distance

ABAP_SYNTAX
... distance( val1 = text1 val2 = text2 $[max = max$] ) ...

What does it do?
This built-in function returns the Levenshtein distance between two strings text1 and text2. This distance is the minimum number of insert, delete, and replace operations required to pass one string to another and hence reflects the similarity of the two strings. The return value has the type i.
max can be used to specify a positive value other than 0, that terminates the calculation of the Levenshtein distance if the distance is greater than max. The value max is then returned instead. max is a numeric expression position with type i. If the value of max is less than or equal to 0, an exception of the class CX_SY_STRG_PAR_VAL is raised. If max is not specified, the calculation is not terminated



Latest notes:

The complexity of the function increases in line with the product of the lengths of the two strings. The calculation time can be limited by specifying max.
This function can typically be used to find those words in a word set that are most similar to a word entered in a search using the minimum editing space.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The result of the following function calls is 0, 1, and 3.
ABEXA 01001
ABAP_EXAMPLE_END

ABAP_EXAMPLE_ABEXA
String Functions, distance
ABAP_EXAMPLE_END



Runtime Exceptions



Catchable Exceptions
CX_SY_STRG_PAR_VAL
Reason for error:
Value in max is less than or equal to 0.
Runtime error:
STRG_ILLEGAL_PAR