ARTICLE
find , find_... - Search Functions
Syntax Forms
1. ... find( val = text {
sub = substring }|{
regex = regex } [
case = case ]
[ off = off ] [
len = len ] [
occ = occ ] ) ...
2. ... find_end( val = text
regex = regex [
case = case ]
[ off = off ] [
len = len ] [
occ = occ ] ) ...
3. ... find_any_of( val = text
sub = substring
[ off = off ] [
len = len ] [
occ = occ ] ) ...
4. ... 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 in
substring or for a match with
the regular expression regex
and returns the offset of the occurrence with respect to the full length
of text . The search is case-sensitive by default, but you can
override this with the parameter case
. If substring is empty, an exception from the class
CX_SY_STRG_PAR_VAL is raised.
The function find_end searches like find , however it
returns the sum of the offset of the occurrence and the length of the
match with the regular expression.
The function find_any_of returns the offset of the occurrence of
any character in substring , and
is always case-sensitive. If substring is empty, the value -1 is
returned.
The function find_any_not_of returns the offset of the found
occurrence of any character not in
substring , and is always case-sensitive. If substring 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 by off and len
is searched from left to right.
If occ is negative, the subarea defined by off and len
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
Using the related search functions count
and count_... , you can determine
the total number of occurrences instead of an offset.
Like the statement FIND , the search functions
can be faster than the comparison operator
CS cy some magnitude.
Example
See String Functions, find
and substring
Runtime Exceptions Catchable Exceptions
CX_SY_RANGE_OUT_OF_BOUNDS
Reason for error: Illegal offset or length specification in the off
and len .
Runtime error: STRING_OFFSET_TOO_LARGE
CX_SY_REGEX_TOO_COMPLEX
Reason for error: More information: Exceptions
in Regular Expressions .
Runtime error: REGEX_TOO_COMPLEX
CX_SY_STRG_PAR_VAL
Reason for error: Substring in sub or regular expression in
regex is empty or occurrence in occ is 0.
Runtime error: STRG_ILLEGAL_PAR
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved