SAP WRITE TO ITAB ABAP Statements

Get Example source ABAP code based on a different SAP table
  


Standard SAP Help for WRITE_TO_ITAB

WRITE TO itab

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

ABAP Syntax(Obsolete)WRITE dobj TO itab[+off][(len)] • idx
[format_options].

What does it do? 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-subrcMeaning 0The data object specified in source_name and the row specified in idx were found and the statement was executed. 4The data object specified in source_name or the row specified in idx were not found and the statement was not executed.



Latest notes: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.
ASSIGN itab[ idx ] TO <(><<)>line>.
WRITE dobj TO <(><<)>line>[+off][(len)] [ format_options].



Example ABAP Coding
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 • 1 DD/MM/YYYY.

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




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 larger than the field length.
Runtime error:
WRITE_TO_OFFSET_TOOLARGE

Return to menu