ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Internal Tables → Processing Statements for Internal Tables → FIND IN TABLE itab
FIND IN TABLE - table_range
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 range 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
numeric expression positions of operand type i.
The table range begins in the row lin1 after the
offset off1,
and ends in the row lin2 in front of the offset off2.
If FROM is specified without OFFSET, the range
implicitly begins at the start of lin1. If TO
is specified without OFFSET, the range ends implicitly 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
Reads a text into an internal table in ITF format and searches for the first string "AS" in a non-case-sensitive
search. The row type of the internal table is interpreted as a single field of the type c
despite being a structured type. The first search finds the first paragraph format "AS" in the column
tdformat. The second search is limited to the lines of the first paragraph
and finds the word "as" in the column tdline, if it exists here. If the offset is specified, the paragraph format is not found in the first line of the paragraph.
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.
DELETE itf_tab FROM 18.
cl_demo_output=>write( itf_tab ).
FIND FIRST OCCURRENCE OF SUBSTRING 'as'
IN TABLE itf_tab
IGNORING CASE
MATCH LINE DATA(mline)
MATCH OFFSET DATA(moff)
MATCH LENGTH DATA(mlen).
IF sy-subrc = 0.
cl_demo_output=>write( |{ mline }, { moff }, { mlen }| ).
ENDIF.
DATA:
idx1 TYPE i,
idx2 TYPE i.
LOOP AT itf_tab TRANSPORTING NO FIELDS WHERE tdformat = 'AS'.
idx2 = COND i( WHEN idx1 IS NOT INITIAL THEN sy-tabix ).
IF idx2 IS NOT INITIAL.
EXIT.
ENDIF.
idx1 = COND i( WHEN idx1 IS INITIAL THEN sy-tabix ).
ENDLOOP.
FIND FIRST OCCURRENCE OF SUBSTRING 'as'
IN TABLE itf_tab
FROM idx1 OFFSET 2 TO idx2 - 1
IGNORING CASE
MATCH LINE mline
MATCH OFFSET moff
MATCH LENGTH mlen.
IF sy-subrc = 0.
cl_demo_output=>write( |{ mline }, { moff }, { mlen }| ).
ENDIF.
cl_demo_output=>display( ).
ENDIF.