Documentation View

We are hiring and constantly growing! Have a look through our vacancies to find the right role for you!

ABAPWRITE_TO_ITAB - WRITE TO ITAB

ABAPWRITE_TO_ITAB - WRITE TO ITAB

BAL_S_LOG - Application Log: Log header data   CL_GUI_FRONTEND_SERVICES - Frontend Services  
This documentation is copyright by SAP AG.
SAP E-Book

WRITE TO itab

Short Reference



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

Effect

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-subrc Meaning
0 The data object specified in source_name and the line specified in idx were found and the statement was executed.
4 The data object specified in source_name or the line 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 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$].

Example

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.

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





SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   ABAP Short Reference  
This documentation is copyright by SAP AG.

Length: 4433 Date: 20230207 Time: 085008     sap01-206 ( 61 ms )