SAP WRITE TO ITAB ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• WRITE TO itab ABAP Statement
• • WRITE TO itab (obsolete)

WRITE TO itab
Short Reference

ABAP_SYNTAX_OBS
WRITE dobj TO itab$[+off$]$[(len)$] • idx
$[format_options$].

What does it do?
This variant, of the statement WRITE TO, which is forbidden in classes, has the same effect as the allowed variant , except that the formatted content is written to the line of the internal table itab specified in idx. The internal table must be a standard table without secondary table keys. The same requirements apply to the line type as to the variable destination.
idx expects a data object of the data type i. It must be a data type. When the statement is executed, this data object must contain the index of the line to be overwritten. If the value of idx is less than or equal to 0, an uncatchable exception is raised. If the value of idx is greater than the number of table lines, no line is overwritten and sy-subrc is set to 4.
After the table name itab, offset and length specifications off and len can be made that refer to the specified table line.
System Fields sy-subrcMeaning 0The data object specified in source_name and the line specified in idx were found and the statement was executed. 4The data object specified in source_name or the line specified in idx were not found and the statement was not executed.



Latest notes:

This form of the statement WRITE TO is now only possible outside of classes and is replaced by accessing table lines using field symbols or data references. The following lines 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$].
ABAP_HINT_END



Example ABAP Coding

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



Runtime Exceptions


Non-catchable Exceptions
Reason for error:
Incorrect index specification < = 0 in idx
Runtime error:
TABLE_INVALID_ •
Reason for error:
Negative length specification for offset/length specification.
Runtime error:
WRITE_TO_LENGTH_NEGATIVE
Reason for error:
Negative offset specification for offset/length specification.
Runtime error:
WRITE_TO_OFFSET_NEGATIVE
Reason for error:
Offset specification for offset/length specification is greater than the field length.
Runtime error:
WRITE_TO_OFFSET_TOOLARGE
ABAP_NONCAT_END

Return to menu