ABAP - Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Character String and Byte String Processing →  Expressions and Functions for String Processing →  String Functions →  Description Functions for Character-Like Arguments → 

distance - Distance Function

Syntax

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

Effect

This 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 change 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 declare a positive value other than 0; the calculation of the Levenshtein distance is canceled if the distance is greater than max. The value of max is returned instead. max is a numeric expression position of the 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

Notes

Example

The result of the following function calls is 0, 1, and 3.

DATA(result1) = distance( val1 = `abcdefg` val2 = `abcdefg` ).
DATA(result2) = distance( val1 = `abcdefg` val2 = `abcXefg` ).
DATA(result3) = distance( val1 = `abcdefg` val2 = `aXcdXXg` ).

Executable Example

Character String Functions, distance

Exceptions

Handleable Exceptions

CX_SY_STRG_PAR_VAL