FIND IN TABLE itab

Short Reference

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 ...].


Addition:

... MATCH LINE mlin

Effect

: The program searches the internal table itab line by line for the byte/character string defined in pattern. A standard table must be entered for itab. The line type of the table must either be byte-like or character-type depending on the addition BYTE or CHARACTER MODE. The search does not recognize byte or character strings that span more than one line of the table.

With the addition table_range, the search range can be restricted to the table. The addition MATCH LINE returns the line number in which the search string has been found. The remaining additions have the same meaning for the search in the individual table rows as the statement FIND for elementary byte and character strings. If the addition RESULTS is used, the line numbers of every found location are also stored in the LINE component of the corresponding table row of result_tab, or the line number of the last found location is stored in result_wa and the lines from result_tab are sorted according to the columns LINE, OFFSET and LENGTH.

The search is ended when the search string is found for the first time or when all search strings in the search range have been found, or if the end of the search range is reached. The search result is made available by setting sy-subrc.

When character strings are processed, the closing blanks are taken into account for line types of fixed length.

System fields

sy-subrc Explanation
0 The search string was found at least once in the search range.
4 The search string was not found in the search range.

The values of sy-tabix and sy-fdpos are not changed.

Addition

... MATCH LINE mlin

Effect

: The addition MATCH LINE saves the number of the line in which the last substring was found, in the data object mlin. For mlin, a variable of data type i is expected. If the substring is not found, mlin retains its previous value.

Example

: Search 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,
      results TYPE match_result_tab.

...

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

Exceptions

Catchable Exceptions

CX_SY_RANGE_OUT_OF_BOUNDS

CX_SY_TAB_RANGE_OUT_OF_BOUNDS

CX_SY_INVALID_REGEX