Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Internal Tables →  Processing Statements for Internal Tables 

MODIFY itab

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


MODIFY { itab_line |
itab_lines }. 

Effect

This statement changes the content either of a single row itab_line or multiple rows itab_lines, which can be specified using a table key or a table index.

The following restrictions apply with respect to modifications to key fields of the primary and secondary table keys:

  • The key fields of the primary table key of sorted tables and hashed tables are read-only and must not be modified. This would invalidate internal table administration. The processing statements for internal tables check whether writes are performed on individual key fields and a corresponding non-handleable exception raised. If writes are performed in write positions across the entire table row (for example, as a target field of assignments or as actual parameters for output parameters), an exception is always raised.
  • The key fields of a secondary table key, however, are only read-only while the secondary table is being used. This is the case in LOOP loops and during the use of the MODIFY statement, in which the secondary key is specified after USING KEY. Otherwise the key fields are not read-only.

The administration of unique secondary keys is updated directly after a modification using MODIFY, and raises a non-handleable exception if duplicate entries would otherwise be produced. The non-unique secondary keys are updated when the secondary table key is next used explicitly (lazy update).

System Fields

sy-subrc Meaning
0 At least one row was changed.
4 No rows were changed, since no suitable row was found in the search using a table key or in thelogical expression, or the specified index was greater than the current number of rows for the search using a table index.

The system field sy-tabix is not set.


Notes

  • Apart from using the MODIFY statement, the content of an individual table row can be changed using assignments to field symbols and dereferenced data references that point to the table row.
  • There is no implicit selection of a suitable key or index. The used table key or table index is always specified uniquely. The syntax check issues a warning if there is a suitable secondary table key but this table key is not used. This warning should be removed through using the key. However, in exceptional cases, it can be bypassed using a pragma.
  • Using a special variant MODIFY mesh_path, rows from the last path node of a mesh path can be changed.

Example

Modifies a row in an internal table using a key access. A row with a specific key value is read to a work area wa. From this value, a structure with a different value is then constructed in a non-key component after the addition FROM of the statement MODIFY. The table row with the appropriate key value is then modified.

DATA itab TYPE HASHED TABLE OF scarr WITH UNIQUE KEY carrid. 

SELECT * 
       FROM scarr 
       INTO TABLE @itab. 

DATA(wa) = VALUE #( itab[ carrid = 'LH' ] OPTIONAL ). 

IF wa IS NOT INITIAL. 
  MODIFY TABLE itab 
         FROM VALUE #( BASE wa carrname = '...' ). 
ENDIF. 

Exceptions

Handleable Exceptions

CX_SY_ITAB_DYN_LOOP

  • Cause: Error in a dynamic WHERE condition
    Runtime error: DYN_WHERE_PARSE_ERROR

Non-Handleable Exceptions

  • Cause: Invalid dynamic specification of a row component
    Runtime error: ITAB_ILLEGAL_COMPONENT
  • A read-only secondary table key would be overwritten
    Runtime error: ITAB_ACTIVE_KEY_VIOLATION
  • Cause: Memory area violated when TABLES parameter accessed
    Runtime error: ITAB_STRUC_ACCESS_VIOLATION

Continue

MODIFY itab - itab_line

MODIFY itab - itab_lines