sapdev logo background
sapdev logo sapdev logo
Comments

ABAP FIND ITAB Statement syntax, information and example SAP source code



Return to Statement index



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 row-by-row 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 rows in the table must be character-like or byte-like, depending on the
CHARACTER or BYTE MODE addition. Character strings or byte strings that cover multiple table rows are not found.
The table_range addition can be used to restrict the search range in the table. When replacing, the other additions generally have the same significance as the FIND statement for elementary character or byte strings, whereby a further addition MATCH LINE also returns the row number of any location found.
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 .
In string processing with row types of fixed length, trailing blanks are respected.

Latest notes: Searching using FIND IN TABLE produces better performance than running a LOOP and using FIND to search the individual rows.

System Fields
sy-subrc Meaning
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.

Example ABAP Coding Searches for all occurrences of Donald's nephews in an internal table and save the results in the table results .
DATA: itab TYPE TABLE OF string.

...

FIND ALL OCCURRENCES OF REGEX '\b(Huey|Dewey|Louie)\b'
IN TABLE itab
RESPECTING CASE
RESULTS DATA(results).



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: Invalid offset or length specified in the addition
FROM ... OFFSET ... TO OFFSET .
Runtime error: INVALID_TABLE_RANGE
CX_SY_INVALID_REGEX
Reason for error: Illegal expression after the addition REGEX .
Runtime error: INVALID_REGEX
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




FIND
FIND_ITAB_OPTIONS




comments powered by Disqus