Using Secondary InternalTable Keys

In order to improve improve Table performance, SAP has introduced in ABAP release 7.0 EhP 2, secondary table keys.

Below you can find the sintax:


    CLASS-DATA: gt_zpo_hardcodes TYPE SORTED TABLE OF zpo_hardcodes
        WITH NON-UNIQUE KEY PRIMARY_KEY           COMPONENTS bsart badi_method name instance numb active
        with NON-UNIQUE SORTED KEY secondary_key  COMPONENTS badi_method name instance numb active.


* Reading using the secondary index

    FIELD-SYMBOLS: <fs_zpo_hardcodes> TYPE zpo_hardcodes.
    
    READ TABLE gt_zpo_hardcodes ASSIGNING <fs_zpo_hardcodes> WITH TABLE KEY secondary_key
        COMPONENTS badi_method = im_badi_method
                   name        = im_name
                   instance    = im_instance
                   numb        = im_numb
                   active      = 'X'.
    IF sy-subrc = 0.
      re_result = <fs_zpo_hardcodes>-low.
    ENDIF.


* Looping using the secondary index

    FIELD-SYMBOLS: <fs_zpo_hardcodes> TYPE zpo_hardcodes,
                   <fs_range>         TYPE rsdsselopt.

    LOOP AT gt_zpo_hardcodes ASSIGNING <fs_zpo_hardcodes> 
      USING KEY secondary_key WHERE badi_method = im_badi_method
                                    AND name        = im_name
                                    AND instance    = im_instance
                                    AND active      = 'X'.
      
      APPEND INITIAL LINE TO re_range ASSIGNING <fs_range>.
      <fs_range>-sign   = <fs_zpo_hardcodes>-sign.
      <fs_range>-option = <fs_zpo_hardcodes>-opti.
      <fs_range>-low    = <fs_zpo_hardcodes>-low.
      <fs_range>-high   = <fs_zpo_hardcodes>-high.

    ENDLOOP.


1 comment: