Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Obsolete Language Elements →  Obsolete Processing of Internal Data →  Obsolete Internal Table Processing 

WRITE TO itab

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Obsolete Syntax

WRITE dobj TO itab[+off][(len)] INDEX idx
      [format_options].

Effect

This variant, forbidden in classes, of the statement WRITE TO has the same effect as the allowed variant, with the difference that the edited content is written to the row in the internal table itab in which idx is specified. The internal table must be a standard table without secondary table keys. The same requirements apply to the row type as to the variable destination.

idx expects a data object of the data type i. It must be a data type which, when the statement is executed, contains the index of the row to be overwritten. If the value of idx is less than or equal to 0, a non-handleable exception is raised. If the value of idx is greater than the number of table rows, no row will be overwritten and sy-subrc will be set to 4.

After the table name itab, offset and length specifications off and len can be made. These refer to the specified table row.

System Fields

sy-subrc Meaning
0 The data object specified in source_name and the row specified in idx were found and the statement was executed.
4 The data object specified in source_name or the row specified in idx were not found and the statement was not executed.


Note

This form of the statement WRITE TO is now only possible outside of classes and is replaced by field symbols or data references using access to table rows. The following rows show the implementation with a field symbol:

FIELD-SYMBOLS <line> LIKE LINE OF itab.
ASSIGN itab[ idx ] TO <line>.
WRITE dobj TO <line>[+off][(len)][ format_options].


Example

Formatted write of current date into the first row of the internal table itab. The first statement WRITE TO uses the obsolete form; the second statement WRITE TO represents the recommended variant.

DATA line TYPE c LENGTH 80. 
DATA itab LIKE TABLE OF line. 

FIELD-SYMBOLS <line> LIKE LINE OF itab. 

APPEND line TO itab. 

WRITE sy-datum TO itab INDEX 1 DD/MM/YYYY. 

ASSIGN itab[ 1 ] TO <line>. 
WRITE sy-datum TO <line> DD/MM/YYYY.

Exceptions

Non-Handleable Exceptions

  • Cause: Incorrect index specified <= 0 in idx
    Runtime error: TABLE_INVALID_INDEX
  • Cause: Negative length specified when offset/length is specified.
    Runtime error: WRITE_TO_LENGTH_NEGATIVE
  • Cause: Negative offset specified when offset/length is specified.
    Runtime error: WRITE_TO_OFFSET_NEGATIVE
  • Cause: Offset specified when offset/length is specified is greater than the field length.
    Runtime error: WRITE_TO_OFFSET_TOOLARGE