Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Internal Tables →  Processing Statements for Internal Tables →  FIND IN TABLE itab 

FIND IN TABLE - table_range

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


... [FROM lin1 [OFFSET off1]] 
    [TO   lin2 [OFFSET off2]] ...

Effect

This addition limits the search in the statement FIND IN TABLE to the table section specified in lin1, off1, lin2 and off2. Without this addition, the program searches the whole table, row by row. lin1, off1, lin2 and off2 are numerical expression positions of operand type i.

The table section begins in the row lin1 after the offset off1, and ends in the row lin2 before the offset off2. If FROM is specified without OFFSET, the section implicitly begins at the start of lin1. If TO is specified without OFFSET, the range implicitly ends at the end of the row lin2.

The value of lin1 must be greater than or equal to 1, and the value of lin2 must be greater than or equal to the value of lin1, and both must refer to valid table rows. The values of off1 and off2 must be greater than or equal to 0 and be within the respective row length. If lin1 and lin2 indicate the same row, the value of off2 must be greater than or equal to the value of off1. Both offsets may refer to the end of the row.


Note

This addition is also used in the statement REPLACE IN TABLE.


Example

Counts the frequency with which one of Donald's nephews occurs in an internal table. In the example FIND IN itab, the same result can be achieved more simply using the number of rows in results.

DATA: itab TYPE TABLE OF string, 
      cnt  TYPE i, 
      mlin TYPE i, 
      moff TYPE i, 
      mlen TYPE i. 

FIELD-SYMBOLS <line> TYPE string. 

... 

cnt = -1. 
mlin = 1. 
moff = 0. 
WHILE sy-subrc = 0. 
  cnt = cnt + 1. 
  ASSIGN itab[ mlin ] TO <line>. 
  IF moff >= STRLEN( <line> ). 
    mlin = mlin + 1. 
    IF mlin > LINES( itab ). 
      EXIT. 
    ENDIF. 
    moff = 0. 
  ENDIF. 
  FIND REGEX '\b(Huey|Dewey|Louie)\b' 
       IN TABLE itab FROM mlin OFFSET moff 
       RESPECTING CASE 
       MATCH LINE mlin 
       MATCH OFFSET moff 
       MATCH LENGTH mlen. 
  moff = moff + mlen. 
ENDWHILE.