SEARCH itab

Short Reference

Syntax

SEARCH itab FOR pattern [IN {BYTE|CHARACTER} MODE]
       [STARTING AT idx1] [ENDING AT idx2]
       [ABBREVIATED]
       [AND MARK].

Extras:

1. ... IN { BYTE |CHARACTER } MODE

2. ... [STARTING AT idx1] [ENDING AT idx2]

3. ... ABBREVIATED

4. ... AND MARK

Effect

This statement searches the rows of the index table itab for a pattern specified in pattern. For hashed-tables, SEARCH cannot be used. The statement always searches the internal table and not a potentially existing header line.

For pattern, a byte- resp. character-type data object can be specified depending on the processing type. The patterns in pattern have the same forms as the statement SEARCH has for Byte- resp. character chain processing.

The search ends at the first hit and sy-tabix is set to the index of the found table row. sy-fdpos is set to the offset of the found byte- or character sequence resp. to the found word in the table row. If the pattern is not found, then sy-fdpos and sy-tabix are set to 0.

Return Value

sy-subrc Relevance
0 Pattern found in itab.
4 Pattern not found in itab.

Note

Since release 6.10, you should - if possible - use the new statement FIND within a loop defined with LOOP ... ASSIGNING instead of SEARCH.

Addition 1

... IN { BYTE |CHARACTER } MODE

Effect

With the addition IN BYTE MODE resp. IN CHARACTER MODE, you determine whether byte- or character chain processing is carried out. The row type of the internal table must be suitable for the chosen processing type. Without specifying the addition and before release 6.10, the search is carried out character by character.

Addition 2

... [STARTING AT idx1] [ENDING AT idx2]

Effect

With the additions STARTING AT and ENDING AT, you can restrict the search to a part of the the table rows of table itab. For idx1 and idx2, data objects of the type i are expected. The value in idx1 specifies from which row and to which row the value idx2 is searched for. If only one of the additions is specified, the search is carried out from the first to the last row.

The search is not carried out and sy-subrc is set to 4, if:

Addition 3

... ABBREVIATED

Effect

When you search character by character, you can specify a shortened pattern in pattern for character chain processing with the addition ABBREVIATED< (just as with statement SEARCH)

Addition 4

... AND MARK

Effect

When searching character by character, you can convert a character sequence resp. a word found in itab to upper case with the statement AND MARK (just as with the statement SEARCH for character chain processing).

Example

The search character by character is successful and sets sy-tabix to the index (2) of the respective row and sy-fdpos to the offset (7) of the word "see" in the row. After execution of the statement, the second table row contains the content "you'll SEE the line" via the addition AND MARK.

DATA text_table TYPE TABLE OF string.

APPEND: 'Sweet child in time' TO text_table,
        'you''ll see the line' TO text_table,
        'the line between' TO text_table,
        'good and bad.' TO text_table.

SEARCH text_table FOR '.see.' AND MARK.