ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Character String and Byte String Processing → Expressions and Functions for String Processing → String Functions → Examples of String Functions
String Functions, count, find, and match
The example demonstrates the string functions count
,
find
, and match
.
Other versions: 7.31 | 7.40 | 7.54
Source Code
DATA: result TYPE i,
substr TYPE string.
WRITE / text.
NEW-LINE.
result = count( val = text
regex = regx ).
DO result TIMES.
result = find( val = text
regex = regx
occ = sy-index ).
substr = match( val = text
regex = regx
occ = sy-index ).
result = result + 1.
WRITE AT result substr.
ENDDO.
Description
In the text field text
all the occurrences are searched for (using
count and find
) that correspond to a regular expression. When a search
is successful, the subfield found is read out and displayed with the help of the match
function.
Instead of using the count
function, you could also use an unlimited
DO loop that is left using EXIT
if the result of find
has the value -1.