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-Type Arguments
find, find_... - Search Functions
Other versions: 7.31 | 7.40 | 7.54
Syntax Forms
-
... find( val = text {sub = substring}|{regex = regex} [case = case]
[off = off] [len = len] [occ = occ] ) ... -
... find_end( val = text regex = regex [case = case]
[off = off] [len = len] [occ = occ] ) ... -
... find_any_of( val = text sub = substring
[off = off] [len = len] [occ = occ] ) ... -
... find_any_not_of( val = text sub = substring
[off = off] [len = len] [occ = occ] ) ...
Effect
The search functions find
and find_...
scan
text
for the characters specified in substring
or for a match with a
regular expression
specified in regex
,
with the scanned subarea specified in the optional parameters
off
and
len and the occurrence of the match specified in the optional parameter occ
.
The return code has the type i
and is filled as follows:
- The function
find
searches for the exact substring specified insubstring
or for a match with the regular expressionregex
and returns the offset of the occurrence with respect to the full length oftext
. The search is case-sensitive by default, but you can override this with the parametercase
. Ifsubstring
is empty, an exception from the class CX_SY_STRG_PAR_VAL is raised.
- The function
find_end
searches likefind
, however it returns the sum of the offset of the location and the length of the correspondence to the regular expression.
- The function
find_any_of
returns the offset of the occurrence of any character insubstring
, and is always case-sensitive. Ifsubstring
is empty, the value -1 is returned.
- The function
find_any_not_of
returns the offset of the found occurrence of any character not insubstring
, and is always case-sensitive. Ifsubstring
is empty, the value -1 is returned.
If a search is not successful, all functions return the value -1.
The optional parameters off
,
len
, and
occ
have the following meaning when combined:
- If
occ
is positive, the subarea defined byoff
andlen
is searched from left to right.
- If
occ
is negative, the subarea defined byoff
andlen
is searched from right to left.
The occurrence of the match specified by occ
refers to the search area defined by off
and len
.
Notes
Example
Exceptions
Catchable Exceptions
CX_SY_RANGE_OUT_OF_BOUNDS
-
Cause: Illegal offset or length specification in the
off
andlen
.
Runtime Error:STRING_OFFSET_TOO_LARGE
CX_SY_REGEX_TOO_COMPLEX
-
Cause: More information: Exceptions in Regular Expressions.
Runtime Error:REGEX_TOO_COMPLEX
CX_SY_STRG_PAR_VAL
-
Cause: Substring in
sub
or regular expression inregex
is empty or occurrence inocc
is 0.
Runtime Error:STRG_ILLEGAL_PAR