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 assess with key specification

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 = sflight_wa-seatsmax + 20.
      MODIFY sflight_tab INDEX sy-tabix
                         USING KEY loop_key
                         FROM  sflight_wa
                         TRANSPORTING seatsmax.
      IF sy-subrc = 0.
        count = count + 1.
      ENDIF.
    ENDLOOP.

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

Description

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 MODIFY statement after USING KEY, it is possible to access the hashed table via the associated secondary table index.

The example only serves to demonstrate the syntax. Generally, instead of using the MODIFY statement such modifications should be carried out 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.
ENDLOOP.