Internal Tables
ABAP DevelopmentIntermediate

APPEND, INSERT, MODIFY, DELETE and COLLECT

Understand the most important internal table modification statements and their risks.

Explanation

APPEND adds a row at the end of a STANDARD table. INSERT can insert by index or key depending on the table type. MODIFY updates an existing row. DELETE removes rows by condition, index or key. COLLECT inserts a row or aggregates numeric fields based on key fields, but many teams avoid it because explicit aggregation is easier to understand and debug. Internal table modification becomes risky when it is done inside loops, especially when deleting by index or modifying copied work areas. A developer must understand whether the code is working on a copy or directly on the table row.

Code example

ABAP Code
LOOP AT lt_data INTO DATA(ls_data).  IF ls_data-amount <= 0.    ls_data-status = 'E'.    ls_data-message = 'Invalid amount'.    MODIFY lt_data FROM ls_data TRANSPORTING status message.  ENDIF.ENDLOOP.

Real project scenario

An upload program validates rows and updates status and message fields. If LOOP INTO work area is used, the developer must call MODIFY. If ASSIGNING is used, the row can be changed directly.

Common mistakes

- Changing work area but not modifying the table. - Deleting rows inside LOOP without safe pattern. - Using COLLECT without understanding key behavior. - Updating all fields when only few fields need change.

Best practices

- Use TRANSPORTING when updating selected fields. - Prefer ASSIGNING for direct row update. - Use explicit aggregation when clarity matters. - Be careful when deleting rows inside loops.

Interview angle

Interviewers may give a code snippet and ask why table data is not changing. Often the issue is missing MODIFY or wrong loop style.