Entering content frame

Obsolete Statements for Internal Tables Locate the document in its SAP Library structure

CautionThe following statements are obsolete and are only available to ensure compatibility with Releases prior to 4.6 and 6.10. The statements may appear in older programs but should no longer be used.

Finding Character Strings in Internal Tables

To find a character string in a line of an index table, use the following statement:

SEARCH itab FOR str options.

This statement checks the lines of internal table itabfor the character string str. If the search is successful sy-subrc is set to 0 and sy-tabix is set to the index of the table line where the character string was found. sy-fdpos contains the offset position of the character string in the table line. Otherwise, sy-subrc is set to 4.

In a Unicode system, the line type of the internal table must have a character type. In a non-Unicode system, the line can also contain numeric or hexadecimal components.

The statement treats all table lines as type cfields, regardless of their actual line type. There is no conversion. The search string str can have the same form as for a normal SEARCH in a field.

The different options (options) for the search in an internal table itab are:


The table itab is searched for a word containing the character string str. The characters can be separated by other characters. The first letter of the word and the string strmust be the same.

        STARTING AT lin1

This searches table itab for str, starting at line lin1.lin1 can be a variable.

        ENDING AT lin2

This searches table itab for str, ending at line lin2.lin2 can be a variable.

        AND MARK

If the search string is found, all the characters in the search string (and all the characters in between when using ABBREVIATED) are converted to upper case.

This statement only works with index tables. There is no corresponding statement for hashed tables.


REPORT demo_int_tables_search_index.

        index(4) TYPE c,
        text(8) TYPE c,
      END OF line.


DATA num(2) TYPE n.

  DO 10 TIMES.
  line-index = sy-index.
  num = sy-index.
  CONCATENATE 'string' num INTO line-text.
APPEND line TO itab.

SEARCH itab FOR 'string05' AND MARK.

WRITE: / '''string05'' found at line', (1) sy-tabix,
         'with offset', (1) sy-fdpos.


READ TABLE itab INTO line INDEX sy-tabix.
WRITE: / line-index, line-text.

The list output is:

'string05' found at line 5 with offset 4


The offset of the string found in the table is determined by the width of the first table column, which has type i and length 4. The option AND MARK changes the table contents in the corresponding line.

Changing Lines Using WRITE TO

You can change the lines of standard tables using the following statement:

WRITE f TO itab INDEX idx.

This variant of the WRITE TO (see keyword documentation) statement converts the contents of field f to type c and then transfers the resulting character string into the line with index idx. If the operation is successful, sy-subrc is set to 0. If the internal table contains fewer lines than idx, no line is changed and sy-subrc is set to 4.

The data type of f must be convertible into a character field; if it is not, a syntax or runtime error occurs. The line is always interpreted as a character string, regardless of its actual line type. You can process sub-fields  in the same way as in the normal WRITE TO statement. You should only use this statement for structured line types if you want to change a single character whose exact position you already know. Another possibility is to use internal tables whose structure is made up of a single character field. Tables of this kind are often used in dynamic programming.


REPORT demo_int_tables_write_ind.

DATA text(72) TYPE c.


text = 'This is the first line.'.

APPEND text TO code.

text = 'This is the second line. It is ugly.'.

APPEND text TO code.

text = 'This is the third and final line.'.

APPEND text TO code.

WRITE 'nice.' TO code+31 INDEX 2.

LOOP AT code INTO text.
  WRITE / text.


This produces the following output:

This is the first line.
This is the second line. It is nice.
This is the third and final line.

Here, an internal table code is defined with an elementary type c field which is 72 characters long. After filling the table with three lines, the second line is changed by using the WRITE TO statement. The word "ugly" is replaced by the word "nice".


Leaving content frame