SAP® Documentation

Single view

ABAPDATA_SECONDARY_KEY - DATA SECONDARY KEY

BAL_S_LOG - Application Log: Log header data   rdisp/max_wprun_time - Maximum work process run time  
This documentation is copyright by SAP AG.
SAP E-Book

DATA - secondary_key

Short Reference


Syntax

... ${UNIQUE HASHED$}$|${UNIQUE SORTED$}$|${NON-UNIQUE SORTED$}
    KEY key_name COMPONENTS comp1 comp2 ...

Effect

Defines a secondary table key of an internal table. The syntax and semantics of the additions are the same as those for the statement TYPES for standalone table types.

Use secondary keys in a way that benefits the table.

Notes

  • When internal tables are accessed using the statements READ TABLE itab, LOOP AT itab, MODIFY itab, and DELETE itab or using table expressions and in mesh types and mesh paths, a secondary key can be used to specify the rows to be processed or the processing order. To do this, the additions WITH $[TABLE$] KEY ... COMPONENTS or USING KEY must be specified in the statements and the addition KEY in table expressions. A secondary key is never used implicitly.
  • The statement INSERT itab determines the insert position using the primary key and primary index only. A secondary key can be specified only for the source table from which multiple rows are copied. The latter also applies to the statement APPEND.
  • If different table keys for an internal table contain the same components, the syntax check issues a warning (which can be hidden using a pragma). In the case of references to a non-generic table type defined using TYPES, any pragma specified here is also applied to the DATA statement. In the case of references to a generic table type for which no primary table key is defined, the specified pragma is not applied to the DATA statement, since this statement uses a complete table type implicitly and the pragma must also be specified in the case of DATA.
  • If a secondary key is defined, the addition WITH HEADER LINE can no longer be specified, even outside classes.
  • For more information, see TYPES.

Example

Declares an internal table with primary key and two secondary keys.

DATA sbook_tab
     TYPE STANDARD TABLE
     OF sbook
     WITH NON-UNIQUE KEY carrid connid fldate bookid
     WITH UNIQUE HASHED KEY hash_key
          COMPONENTS carrid connid fldate bookid
     WITH NON-UNIQUE SORTED KEY sort_key
          COMPONENTS customid.

Example

As in the previous example but with explicit naming of the primary key.

DATA sbook_tab
     TYPE STANDARD TABLE
     OF sbook
     WITH NON-UNIQUE KEY primary_key
          COMPONENTS carrid connid fldate bookid
     WITH UNIQUE HASHED KEY hash_key
          COMPONENTS carrid connid fldate bookid
     WITH NON-UNIQUE SORTED KEY sort_key
          COMPONENTS customid.

The program DEMO_SECONDARY_KEYS demonstrates the declaration and use of a secondary table key and the resulting performance gains.






PERFORM Short Reference   TXBHW - Original Tax Base Amount in Local Currency  
This documentation is copyright by SAP AG.

Length: 5626 Date: 20200126 Time: 032653     sap01-206 ( 37 ms )

Our Service

Looking for Support? Questions?

The

Consolut

Callback-Service

Leave us your contact details and we will call you back. Panels marked with * are mandatory.