ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Character String and Byte String Processing →  Statements for Character String and Byte String Processing → 

FIND  Syntax Diagram

Short Reference

Syntax

FIND [{FIRST OCCURRENCE}|{ALL OCCURRENCES} OF] pattern
  IN [section_of] dobj
  [IN {CHARACTER|BYTE} MODE]
  [find_options].


Extras:

1. ... {FIRST OCCURRENCE}|{ALL OCCURRENCES} OF

2. ... [IN {CHARACTER|BYTE} MODE]

Effect

The operand dobj is searched for the character or byte sequence specified by the search string pattern.

The additions FIRST OCCURRENCE and ALL OCCURRENCES determine whether all occurrences or only the first one is searched. The addition section_of can be used to restrict the search range. The search is terminated if the search pattern was found for the first time, or if all search patterns were found in the entire search area, or if the end of the search area was reached. The search result is communicated by setting sy-subrc. The addition MODE determines a character or byte string is processed, and the addition find_options provides additional options for controlling and analyzing the statement.

When a character string is processed, dobj is a character-like expression position and for dobj operands of a fixed length, the blank characters are taken into account.

System Fields

sy-subrc Meaning
0 The search pattern was found at least once in the search range.
4 The search pattern was not found in the search range.
8 The search string contains an invalid double-byte character in character string processing.

Notes

Addition 1

... {FIRST OCCURRENCE}|{ALL OCCURRENCES} OF

Effect

The optional addition {FIRST OCCURRENCE}|{ALL OCCURRENCES} OF defines whether all or only the first occurrence of the search pattern is searched. If the addition FIRST OCCURRENCE or none of the additions is specified, only the first occurrence is found. Otherwise, all occurrences are found.

If substring is an empty string in the pattern or is of type c, d, n, or t and only contains blank characters, when searching for the first occurrence, the space in front of the first character or byte of the search range is found. If searching for all occurrences, in this case the exception CX_SY_FIND_INFINITE_LOOP is triggered.

If regex contains a regular expression in the pattern that matches the empty character string, the search for one occurrence also finds the space before the first character. When searching for all occurrences, in this case, the search finds the space before the first character, all intermediate spaces that are not within a match, and the space after the last character.

Addition 2

... IN {CHARACTER|BYTE} MODE

Effect

The optional IN {CHARACTER|BYTE} MODE addition determines whether character string or byte string processing is carried out. If the addition is not specified, character string processing is carried out. Depending on the processing type, dobj and substring in pattern must be character-like or byte-like. If regular expressions are used in pattern, only character string processing is permitted.

Exceptions

Catchable Exceptions

CX_SY_FIND_INFINITE_LOOP

CX_SY_RANGE_OUT_OF_BOUNDS

CX_SY_INVALID_REGEX

CX_SY_REGEX_TOO_COMPLEX




Continue
FIND - pattern
FIND - section_of
FIND - options