FIND statement is used for finding occurrences of a pattern within a string. It can also be used for finding the string pattern within an internal table.
Syntax
FIND <p> IN [SECTION OFFSET <off> LENGTH <len> OF] <text>
[IGNORING CASE|RESPECTING CASE]
[IN BYTE MODE|IN CHARACTER MODE]
[MATCH OFFSET <o>] [MATCH LENGTH <l>].
FIND statement search for the specified pattern (<p>) within the field (<text>).
Additions used with FIND statement
- FIRST OCCURRENCE OF: This addition specifies search only the first occurrence of the pattern in the field.
- ALL OCCURRENCES OF: This addition specifies search entire occurrences of the pattern in the field.
- IN BYTE MODE: This addition specifies the statement is in byte mode.
- IN CHARACTER MODE: This addition specifies the statement is in character string mode.
- RESPECTING CASE: This addition specifies the search is case sensitive.
- IGNORING CASE: Not case sensitive.
- SECTION OFFSET: It specifies an offset value, from that position in the field the search begins.
- LENGTH <len> OF: Specifies a length, inside this length only the search performs.
- MATCH COUNT: It stores the number of matches found.
- MATCH OFFSET: It stores the offset value of the last found occurrence position.
- MATCH LENGTH: It stores the length of the last found substring.
- RESULTS: It stores the offset values for the complete occurrences inside an internal table or a structure.
The main runtime errors for FIND statement for a field string
- FIND_INFINITE_LOOP
- REFI_WRONG_SECTION
- INVALID_REGEX
- REGEX_TOO_COMPLEX
FIND string in an internal table
Syntax:
FIND [{FIRST OCCURRENCE}|{ALL OCCURRENCES} OF] pattern
IN TABLE itab [table_range]
[IN {BYTE|CHARACTER} MODE]
[{RESPECTING|IGNORING} CASE]
[MATCH COUNT mcnt]
{ {[MATCH LINE mlin]
[MATCH OFFSET moff]
[MATCH LENGTH mlen]}
| [RESULTS result_tab|result_wa] }
[SUBMATCHES s1 s2 …].
The main runtime errors for FIND statement for an internal table
- REFI_WRONG_SECTION
- INVALID_TABLE_RANGE
- INVALID_REGEX
sy-subrc values for FIND statement
- sy-subrc=0 (the pattern found in the string)
- sy-subrc=4 (The pattern not found)
- sy-subrc=8 (Search string contain invalid double-byte character in Character mode)
Also Read : View Other ABAP Keywords & Syntax -> ABAP Transaction codes