FIND IN TABLE - table_range

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 n lin1, off1, lin2 and off2. Without this addition, the program searches the whole table, line by line. For lin1, off1, lin2 and off2, data objects of type i are expected.

The table section begins in the line lin1 after the offset off1, and ends in the line 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 line 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 lines. The value of off1 must be greater than or equal to 0 and the value of off2 must be greater than or equal to the value of off1, and both must lie within the line length of the internal table itab . Both offsets may refer to the end of the line.

Note

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

Example

: Count 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.
  READ TABLE itab INDEX mlin ASSIGNING <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.