Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Internal Tables →  Processing Statements for Internal Tables 

FIND IN TABLE itab

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


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

Effect

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 addition CHARACTER or BYTE MODE. 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 making replacements in the individual table rows, 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 row 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 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.


Notes

  • FIND IN TABLE can be used to search tables with structured row types for character strings, if the structure only contains flat character-like components. Every row 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 rows.
  • If searching multiple rows, the rows can be transferred in a string by using the concatenation function concat_lines_of or the statement CONCATENATE LINES OF. Ensure that trailing blanks are handled correctly.

System Fields

sy-subrc Meaning
0 (means: The search pattern was found at least once in the search range.
4 The search pattern was not found in the search range.

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


Example

Reads a text into an internal table in ITF format and searches for the first string "ABAP" or "XML". The positions the occurrence are written in variables. The row type of the internal table is interpreted as a single field of the type c despite being a structured type.

DATA itf_tab TYPE tline_tab. 
IF cl_abap_docu_itf=>get_docu( EXPORTING id = 'SD' 
                                       langu = 'E' 
                                        object = 'ABENABAP_XML' 
                              IMPORTING itf = itf_tab ) = 0. 

  FIND FIRST OCCURRENCE OF REGEX 'ABAP|XML' 
       IN TABLE itf_tab 
       RESPECTING CASE 
       MATCH LINE DATA(mline) 
       MATCH OFFSET DATA(moff) 
       MATCH LENGTH DATA(mlen). 

  IF sy-subrc = 0. 
    cl_demo_output=>display( |{ mline }, { moff }, { mlen }| ). 
  ENDIF. 
ENDIF. 

Exceptions

Handleable Exceptions

CX_SY_RANGE_OUT_OF_BOUNDS

  • Cause: Illegal offset or length specified in the addition SECTION OF.
    Runtime error: REFI_WRONG_SECTION

CX_SY_TAB_RANGE_OUT_OF_BOUNDS

  • Cause: Illegal offset or length specification in the addition of FROM ... OFFSET ... TO OFFSET.
    Runtime error: INVALID_TABLE_RANGE

CX_SY_INVALID_REGEX

  • Cause: Invalid expression after the addition REGEX.
    Runtime error: INVALID_REGEX

Continue

FIND IN TABLE - table_range

FIND IN TABLE - options