ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Internal Tables → Processing Statements for Internal Tables → MODIFY itab
MODIFY itab - itab_line
Other versions: 7.31 | 7.40 | 7.54
Syntax
... { table_key
| index } FROM wa
[TRANSPORTING comp1 comp2 ...]
[result].
Addition
... TRANSPORTING comp1 comp2 ...
Effect
In this variant, the statement MODIFY
assigns the content of work area
wa to a row specified by a table key in
table_key or by a row number in index
. wa
is a
general expression position.
Use TRANSPORTING
to restrict the components comp
to be modified. Use result
when changing a single row to set a reference to the changed row in the form of a field symbol or a data reference.
For access using table keys, index access to
sorted tables and when the addition TRANSPORTING
is used, the wa
work area must be
compatible with the row type of the primary internal table. Only in the case of insertion using the table index in
standard tables without
the addition TRANSPORTING
can wa
be incompatible with the line type of the internal table, and is converted to the row type in accordance with the
conversion rules. If a conversion error occurs here, the exception cannot be handled using CX_SY_CONVERSION_ERROR and the associated runtime error occurs instead. If an
arithmetic expression is specified for wa
, the row type of the internal table is respected when determining the
calculation type.
Notes
-
When modifying a row in a table, be mindful of table keys that are read only. While overwriting of protected key fields in the
primary table key is not checked until runtime, this always produces a syntax error for the
secondary table key. If a row whose
secondary table key
is read only is changed,
FROM wa
can therefore only be specified together withTRANSPORTING
, and no key fields of the secondary key can be specified afterTRANSPORTING
. -
Specifying a calculation expression for
wa
is usually only a good idea for elementary row types. -
The statement
MODIFY itab FROM wa
has the statementMODIFY dbtab FROM wa
with identical syntax. If an internal table has the same name as a database table, a statement like this accesses the internal table. -
Outside of classes, an obsolete short form is possible where
FROM wa
can be omitted if the internal table has a header lineitab
with the same name. The statement then uses the header line as the work area implicitly.
Addition
... TRANSPORTING comp1 comp2 ...
Effect
The addition TRANSPORTING
has the effect that only the specified components
comp1
,
comp2
, ... of the work area are assigned to the corresponding components of the row(s) to be changed. For
sorted tables and
hashed tables, no primary table key components may be declared after TRANSPORTING
.
The components comp1
,
comp2
, ... are specified in accordance with the rules specified in
Specifying Components, with the constraint that,
after TRANSPORTING
, no attributes of classes can be addressed using the object component selector.
Example
The position of letters from the first column of an internal table is defined in the system field
sy-abcde and this value is assigned to the second column. The column is accessed using the table index and the statement MODIFY
modifies the second column only.
TYPES:
BEGIN OF line,
key TYPE c LENGTH 1,
pos TYPE i,
END OF line,
itab TYPE TABLE OF line WITH EMPTY KEY.
DATA(itab) = VALUE itab( ( key = 'U' ) ( key = 'H' ) ( key = 'K' ) ).
LOOP AT itab INTO DATA(wa).
DATA(idx) = sy-tabix.
wa = VALUE #( BASE wa pos = find( val = sy-abcde sub = wa-key ) + 1 ).
MODIFY itab
FROM wa
INDEX idx
TRANSPORTING pos.
ENDLOOP.
cl_demo_output=>display( itab ).