SAP FIND ITAB ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID FIND
• FIND IN TABLE ABAP Statement
• FIRST OCCURRENCE OF FIND IN TABLE
• ALL OCCURRENCES OF FIND IN TABLE
• IN BYTE MODE FIND IN TABLE
• IN CHARACTER MODE FIND IN TABLE

FIND IN TABLE itab
Short Reference

ABAP_SYNTAX
FIND $[${FIRST OCCURRENCE$}$|${ALL OCCURRENCES$} OF$] pattern
IN TABLE itab $[table_range$]
$[IN ${CHARACTER$|BYTE$} MODE$]
$[find_options$].

What does it do?
The internal table itab is searched line-by-line for the character strings or byte strings specified in pattern. itab is a functional operand position.
itab must be a standard table with no secondary table keys. The lines in the table must be character -like or byte-like, depending on the addition CHARACTER or BYTE MODE. Character strings or byte strings that cover multiple table lines are not found.
The table_range addition can be used to restrict the search range in the table. When making replacements in the individual table lines, the other additions generally have the same meaning as the statement FIND for elementary character or byte strings. Here, a further addition MATCH LINE also returns the line number of any occurrence.
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 range, or if the end of the search range was reached. The search result is communicated by setting sy-subrc.
In string processing for line types of fixed length, trailing blanks are respected.
If the internal table is empty, a search is never successful and sy-subrc is set to 4 with one exception: A search for a obsolete POSIX regular expression that matches an empty string sets sy-subrc to 0 and behaves as if the internal table contained an empty first line by returning 1 for MATCH LINE and 0 for MATCH OFFSET and MATCH LENGTH.



Latest notes:

FIND IN TABLE can be used to search tables with structured line types for character strings, if the structure only contains flat character-like components. Every line is then handled in the same way as a field of type c.
Searching using FIND IN TABLE produces better performance than running a LOOP and using FIND to search the individual lines.
For searching multiple lines, the lines can be converted to a string by using the concatenation function concat_lines_of or the statement CONCATENATE LINES OF. It must be ensured that trailing blanks are handled correctly.
NON_V5_HINTS
ABAP_HINT_END
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.
The values of sy-tabix and sy-fdpos are not changed.

ABAP_EXAMPLE_VX5
Reading of a text into an internal table in ITF format and search for the first string ABAP or XML. The positions the occurrence are written in variables. The line type of the internal table is interpreted as a single field of the type c despite being a structured type.
ABEXA 00268
ABAP_EXAMPLE_END



Runtime Exceptions



Catchable Exceptions
CX_SY_RANGE_OUT_OF_BOUNDS
Reason for error:
Illegal offset or length specified in the addition SECTION OF.
Runtime error:
REFI_WRONG_SECTION
CX_SY_TAB_RANGE_OUT_OF_BOUNDS
Reason for error:
Illegal offset or length specification in the addition of FROM ... OFFSET ... TO OFFSET.
Runtime error:
INVALID_TABLE_RANGE
CX_SY_INVALID_REGEX
Reason for error:
Invalid expression after the addition PCRE$|REGEX.
Runtime error:
INVALID_REGEX

Return to menu