Modifying the internal table contents using MODIFY statement

Using the MODIFY statement, we can modify more than one data record in an internal table.

It is modified with the contents of the structure along with the additional conditions such as WHERE, INDEX, USING KEY.

Using the ‘TRANSPORTING’ keyword, we can specify which component of the structure in the internal table must be transferred.

WHERE:

DATA lt_internal_table TYPE TABLE OF ztt_db_table2.

DATA ls_record TYPE ztt_db_table2.

SELECT *FROM ztt_db_table2 INTO TABLE lt_internal_table.

ls_record-contact_address = ‘Street 44’.

MODIFY lt_internal_table FROM ls_record TRANSPORTING contact_address WHERE contact_id=102.

INDEX:

MODIFY lt_internal_table FROM ls_contact INDEX 2 TRANSPORTING contact_address.

Using MODIFY inside a loop.

LOOP AT lt_internal_table INTO DATA(ls_record) WHERE contact_id=102.

              ls_record-contact_address = ‘Street 99’.

              MODIFY lt_internal_table FROM ls_record TRANSPORTING contact_address.

ENDLOOP.