SAP FIND ABAP Statements

Get Example source ABAP code based on a different SAP table
  


Standard SAP Help for FIND

FIND

Short Reference
• FIND ABAP Statement


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

ABAP Addition
1 ... {FIRST OCCURRENCE}|{ALL OCCURRENCES} OF
2 ... [IN {CHARACTER|BYTE} MODE]

What does it do? 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-subrcMeaning 0The search pattern was found at least once in the search range. 4The search pattern was not found in the search range. 8The search string contains an invalid double-byte character in character string processing.

Latest notes:The statement FIND IN TABLE is available for searching in internal tables.
To search in a string in an operand position, you can use search functions. They mask part of the functionality of the FIND statement.
The statement FIND and the search functions can be quicker than the comparison operator CS by some magnitude.
• FIRST OCCURRENCE OF FIND
• ALL OCCURRENCES OF FIND

ABAP Addition

What does it do? 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.
• IN BYTE MODE FIND
• IN CHARACTER MODE FIND

ABAP Addition

What does it do? 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.



Runtime Exceptions

Catchable Exceptions
CX_SY_FIND_INFINITE_LOOP
Reason for error:
Substring of length 0 generates an endless loop when searching for all occurrences.
Runtime error:
FIND_INFINITE_LOOP

CX_SY_RANGE_OUT_OF_BOUNDS
Reason for error:
Illegal offset or length specification in the addition of SECTION OF.
Runtime error:
REFI_WRONG_SECTION

CX_SY_INVALID_REGEX
Reason for error:
Illegal expression after the addition REGEX.
Runtime error:
INVALID_REGEX

CX_SY_REGEX_TOO_COMPLEX
Reason for error:
More information: Exceptions in Regular Expressions.
Runtime error:
REGEX_TOO_COMPLEX

Return to menu