Declaring internal tables is an essential part of writing ABAP code as this is where most of the data will be stored.

ABAP knows the three table types STANDARD, SORTED, and HASHED table. Each of these table types differs in the way they are declared, accessed, and changed during runtime.

The most simple type is the STANDARD TABLE. This works mostly like an array in other programming languages and can be used for a small set of data.

If the data should be kept in a specific order it is recommended to use the SORTED TABLE. During runtime, it is ensured that all table entries are sorted according to the defined table key. Be aware that it is not possible to add new entries with the APPEND statement .

For large sets of data that will be accessed via a table key, you should use the HASHED TABLE. Thanks to the hashed key entries can be retrieved fast and efficiently.

For the following declaration examples we use the local type ty_sales_order_item:

TYPES: BEGIN OF ty_sales_order_item,
vbeln   TYPE vbeln,
posnr   TYPE posnr,
matnr   TYPE matnr,
deleted TYPE boolean,
END OF ty_sales_order_item.


## Standard Table

• Unsorted but can be sorted with SORT
• Access via table index and table key
DATA: sales_order_items TYPE STANDARD TABLE OF ty_sales_order_item WITH DEFAULT KEY.


## Sorted Table

• Sorted according to the defined table key
• Access via table index and table key
• Fast key access thanks to binary search

Primary Key: posnr
Secondary Key: flag

DATA: sales_order_items TYPE SORTED TABLE OF ty_sales_order_item WITH UNIQUE KEY vbeln WITH NON-UNIQUE SORTED KEY delete COMPONENTS deleted.


Primary Key: table_line

DATA: sales_order_items TYPE SORTED TABLE OF string WITH UNIQUE KEY table_line.


## Hashed Table

• Access only via a unique key, no index
• Each key value may only appear once, otherwise an exception is raised
• Fast if all key fields are included

Primary Key: DEFAULT KEY

DATA: sales_order_items TYPE HASHED TABLE OF ty_sales_order_item WITH UNIQUE DEFAULT KEY.


Primary Key: vbeln

DATA: sales_order_items TYPE HASHED TABLE OF ty_sales_order_item WITH UNIQUE KEY vbeln.


Primary Key: DEFAULT KEY
Secondary Key: delete

DATA: it_hask TYPE HASHED TABLE OF ty_sales_order_item WITH UNIQUE DEFAULT KEY WITH NON-UNIQUE SORTED KEY delete COMPONENTS deleted.


Primary Key: vbeln, posnr
Secondary Key: deleted

DATA: it_hauksk TYPE HASHED TABLE OF ty_sales_order_item WITH UNIQUE KEY vbeln posnr WITH NON-UNIQUE SORTED KEY deleted COMPONENTS deleted.