SAP NEWS-40-KEYTAB

Get Example source ABAP code based on a different SAP table
  


ARTICLE

Internal Tables and Key Tables in Release 4.0
The following features of internal tables have been improved considerably in Release 4.0:

Performance improvements, particularly for large tables. This has been achieved by introducing hashed tables, whose access time is constant, mostly regardless of the number of table entries.

Introduction of sorted tables. This has removed the need for complex program code, whose tasks are now performed in the kernel.

Support for generic programming by introducing generic table types.
The term standard key has been extended to include a user-definable key. In addition to the previous form of internal tables (standard tables), SAP has introduced new table types for sorted and hashed tables. The key of these tables is an integral part of the type definition. For this reason, tables with these types are also generically known as key tables. For further information, see internal tables .


New table types: STANDARD TABLE, SORTED TABLE, and HASHEDTABLE
Internal tables in their old form are now known as standard tables . The old type TABLE has now been replaced by STANDARD TABLE. The new types SORTED TABLE and HASHED TABLE have been introduced.

Sorted tables are always stored sorted by their table key in ascending order. The access time is logarithmically related to the number of table entries.

Hashed tables are managed internally using a hash procedure. The access time to a single table entry is essentially constant, that is, the access time is independent of the number of entries.

This means that a complete table type is defined as follows:

1. Table category (STANDARD TABLE, SORTED TABLE, HASHED TABLE)
2. Row type
3. Key (the order is part of the type definition)
4. Uniqueness attribute (UNIQUE, NON-UNIQUE)

For further information about defining table types and objects, see the documentation for the statements TYPES and DATA.

Generic table types: • TABLE and ANY TABLE
To allow generic programming, there is a hierarchy based on the basic internal table types listed above. The generic type • TABLE includes standard and sorted tables. The type ANY TABLE can be used for any table.

Furthermore, further generic types can be defined by omitting the row type, key, or uniqueness attribute of a table (see TYPES). This enables the types of parameters to be defined in generic procedures.

Typing procedure parameters
Since the old internal table type corresponds to the new standard table, only standard tables can be passed to a TABLES parameter. The new tables types can be passed to FORM and FUNCTION parameters using the additions USING or CHANGING or the additions IMPORTING, EXPORTING, and CHANGING.

New table operations
Entries in key tables are located using their key. This means that it must also be possible to add, modify, and delete table entries using the appropriate table key. The following new table operations have therefore been introduced:

INSERT ... INTO TABLE ...
MODIFY TABLE ...
READ TABLE ... [FROM ...|WITH TABLE KEY ...]
DELETE TABLE ... [FROM ...|WITH TABLE KEY ...]
The new operations are valid for all table categories and are, in this respect, generic (for details of the semantics, refer to the corresponding keyword documentation). In each of the statements, the key can be specified using a work area, either explicit or implicit (table with header line). The key values are then taken from the work area. In the statements READ and DELETE, the key can be specified explicitly in the form

... WITH TABLE KEY k1 = v1 ... kn = vn

Unlike the previous form of the READ statement, 'WITH KEY k1 = v1 ... kn = vn', the new form must specify the key in full. This is tested within the syntax check.

The syntax of the new operations has been modeled as far as possible on the existing statements for reading, inserting, modifying and deleting table entries. Note the following rules of thumb:

In the new operations, the word TABLE comes directly before the table name itself
Use the addition WITH TABLE KEY to specify the key explicitly

Integration of the new table types
The new table types can be used both in the new table operations listed above and in existing ABAP statements. This means that the following statements can also be used on key tables:

LOOP
AT
COLLECT
EXPORT
IF
IMPORT
destination = source
SELECT
SORT