Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Obsolete Language Elements →  Obsolete Internal Table Processing 

WRITE TO itab

Short 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 for the line type as for the variable destination.

For idx, a data object of the data type i is expected. 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, you have an exception that cannot be handled. 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 statement WRITE TO is now only possible outside of classes and is replaced by field symols or data references through access to table rows. The following rows show the implementation with a field synmbol:

FIELD-SYMBOLS <line> LIKE LINE OF itab.
READ TABLE itab INDEX idx ASSIGNING <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. 

READ TABLE itab INDEX 1 ASSIGNING <line>. 
WRITE sy-datum TO <line> DD/MM/YYYY. 

Exceptions


Non-Catchable Exceptions

  • Cause: Incorrect index specification <= 0 in idx
    Runtime Error: TABLE_INVALID_INDEX
  • Cause: Negative length specification for offset/length specification.
    Runtime Error: WRITE_TO_LENGTH_NEGATIVE
  • Cause: Negative offset specification for offset/length specification.
    Runtime Error: WRITE_TO_OFFSET_NEGATIVE
  • Cause: Offset specification for offset/length specification is larger than the field length.
    Runtime Error: WRITE_TO_OFFSET_TOOLARGE