MODIFY itab

MODIFY - Changing an Internal Table

Variants:
1. MODIFY itab [FROM wa] [INDEX idx] [TRANSPORTING f1 ... fn].
2. MODIFY TABLE itab [FROM wa] [TRANSPORTING f1 ... fn].
3. MODIFY itab [FROM wa] TRANSPORTING f1 ... fn WHERE cond.

Variant 1

MODIFY itab [FROM wa] [INDEX idx] [TRANSPORTING f1 ... fn].

Effect

Changes a single entry in the

internal table itab, specifying the key explicitly or implicitly. You can only use this variant with index table (standard or sorted tables).

If you specify "FROM wa ", the new values are taken from the work area wa. If you do not specify FROM, the header line of itab is used as the work area.

You can use "INDEX idx" to specify the table index of the line you want to change. This may be omitted within a LOOP at an internal table. In this case, the current table line is changed.
The INDEX specification can come before the FROM addition.

If you specify "TRANSPORTING f1 ... fn", only components f1, f2, ... of the work area are copied into the table. You can also specify components dynamically in the form (name). The actual component name is then taken from the field name at runtime. If name contains an invalid component name, the system triggers a runtime error.

When you specify the insertion point with INDEX idx:

SY-SUBRC = 4:

Index position too large. No entry was changed, since the table contains less than idx entries.

If you do not specify an insertion point,

return code

is set to 0.

Variant 2

MODIFY TABLE itab [FROM wa] [TRANSPORTING f1 ... fn].

Effect

Generic change to a single entry in the internal table itab with key. Unlike variant 1, you can use this variant for any table.

You can use "FROM wa" and "TRANSPORTING f1 ... fn" in the same way as in variant 1. If you do not use the TRANSPORTING addition, only the non-key fields are transported.

The key of the entry to be changed is taken from the work area. The procedure depends on the table type:

The

return code

is set as follows:

Variant 3

MODIFY itab [FROM wa] TRANSPORTING f1 ... fn WHERE cond.

Effect

Changes several entries in the internal table itab. You can use this variant for any table.

You can use " FROM wa" and "TRANSPORTING f1 ... fn" as in variant 1. If the table has the type SORTED TABLE or HASHED TABLE, the TRANSPORTING list may not contain key fields.

In comparisons within the logical expression cond , the first operand must always be a subfield of the line structure of itab.

DATA: BEGIN OF TAB OCCURS 500, 
		FLAG	 TYPE C, 
		COMP(20) TYPE C, 
	END OF TAB. 
 
CLEAR TAB-FLAG. 
MODIFY TAB TRANSPORTING FLAG WHERE FLAG = 'X'.

Related

APPEND itab, INSERT itab, COLLECT itab