Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Internal Tables →  Processing Statements for Internal Tables →  MODIFY itab →  MODIFY itab - itab_line 

Internal Tables, Index Access with Key Specified

The example shows an index access to a hashed table.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA: sflight_tab TYPE HASHED TABLE
                      OF sflight
                      WITH UNIQUE KEY primary_key
                        COMPONENTS carrid connid fldate
                      WITH NON-UNIQUE SORTED KEY plane_type
                        COMPONENTS planetype,
          sflight_wa  LIKE LINE OF sflight_tab,
          count       TYPE i.

    SELECT *
           FROM sflight
           WHERE carrid = 'LH'
           INTO TABLE @sflight_tab.

    LOOP AT sflight_tab INTO sflight_wa USING KEY plane_type
                                       WHERE planetype = 'A310-300'.
      sflight_wa-seatsmax += 20.
      MODIFY sflight_tab INDEX sy-tabix
                         USING KEY loop_key
                         FROM  sflight_wa
                         TRANSPORTING seatsmax.
      IF sy-subrc = 0.
        count += 1.

    cl_demo_output=>display( |{ count } flights modified| ).


The table sflight_tab is a hashed table with a unique primary key and a non-unique secondary sorted key. Since a secondary sorted key is specified in the statement MODIFY after USING KEY, it is possible to access the hashed table using the associated secondary table index.

This example only demonstrates the syntax. Generally, instead of using the statement MODIFY, modifications of this type should be made using a field symbol or a data reference:

LOOP AT sflight_tab ASSIGNING <sflight_wa> USING KEY plane_type
                    WHERE planetype = 'A310-300'.
  <sflight_wa>-seatsmax = <sflight_wa>-seatsmax + 20.