SAP FIND PATTERN ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• SUBSTRING FIND
• REGEX FIND
• PCRE FIND

FIND, pattern
Short Reference

ABAP_SYNTAX
... ${$[SUBSTRING$] substring$} $| ${PCRE pcre$}$|${REGEX regex_ref$} ... .

ABAP_VARIANTS:
1 ... $[SUBSTRING$] substring.
2 ... ${PCRE pcre$}$|${REGEX regex_ref$}

What does it do?
Definition of a search pattern for the statements FIND and FIND IN TABLE. The system can either search for exactly one substring substring or for a substring that matches a regular expression behind PCRE or REGEX.



Latest notes:

The statements REPLACE and REPLACE IN TABLE use the same search pattern.
NON_V5_HINTS
ABAP_HINT_END

ABAP_VARIANT_1 ... $[SUBSTRING$] substring.

What does it do?
In this variant, a search is performed for the exact occurrence of a substring specified in a character-like or byte-like operand substring. substring is a character-like expression position. The optional word SUBSTRING can be specified for emphasis.
If substring is either an empty string or is of type c, n, d, or t and only contains blanks, a search is performed for an empty substring. This is only possible when searching for the first occurrence, and the empty substring is always found before the first character or byte. In character string processing, the trailing blanks are ignored for substring data objects of fixed length.



Latest notes:

If trailing blanks are not to be ignored in the substring, substring must have the data type string.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
Search for all occurrences of the string now in a text string literal. The offsets 11 and 24 of both occurrences are shown in the output.
ABEXA 00275
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
Search for all occurrences of the string now in a text string literal using a WHILE loop. After every successful search, the search range is redefined to start after the occurrence. In this way, all occurrences of the search pattern could be found even before the addition ALL OCCURRENCES was introduced.
ABEXA 00276
ABAP_EXAMPLE_END

ABAP_VARIANT_2 ... ${PCRE pcre$}$|${REGEX regex_ref$}

What does it do?
In this variant, a search is performed for a substring that matches a regular expression specified in pcre or regex_ref.
If the addition PCRE is used, a character-like operand can be specified for pcre that contains a valid PCRE regular expression. The PCRE syntax is compiled in an extended mode: Most unescaped whitespace (blanks and line breaks) of the pattern are ignored outside character classes and comments can be placed behind #. In order to include whitespace and # into a pattern, they must be escaped or the extended mode must be switched off with (?-x) in the regular expression.
If the addition REGEX is used, an object reference variable regex_ref can be specified that points to an instance of the system class CL_ABAP_REGEX that in turn represents a regular expression in any allowed syntax for regular expressions supported by ABAP.
pcre is a character-like expression position.
In searches using a regular expression, special search patterns can be specified that allow further conditions including forecast conditions.
An empty string in pcre is not a valid regular expression and raises an exception. A character string is empty if pcre is either an empty string or is of type c, n, d , or t and only contains blanks.



Latest notes:

Instances of CL_ABAP_REGEX for all kinds of regular expressions, PCRE, XPath, XSD and POSIX (obsolete) can be used with the addition REGEX. This circumvents the restriction that regular expressions of XPath and XSD syntax cannot be specified directly as character strings.
When using CL_ABAP_REGEX , the extended mode can be switched by a parameter for PCRE and XPath regular expressions.
Some regular expressions that are not empty, such as a*, are used to search for empty character strings. This is possible when searching for the first occurrence or all occurrences. The corresponding empty substrings are found before the first character, between all characters, and after the last character of the search range. A search of this type is always successful.
A regular expression can have correct syntax but be too complex for the execution of the statement FIND, which raises a catchable exception of the class CX_SY_REGEX_TOO_COMPLEX. See Exceptions in Regular Expressions.
Behind REGEX, a character-like operand that contains a valid POSIX regular expression posix can also be specified. This variant is obsolete.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The search uses PCRE regular expression syntax and finds the 'ab' from offset 3.
ABEXA 00277
ABAP_EXAMPLE_END

ABAP_EXAMPLES_ABEXA
Find a PCRE regular expression
Search for a regular expression
ABAP_EXAMPLE_END

Return to menu