Secondary indexes for internal tables
In this recipe, we will see the new concept of secondary keys/index within internal tables. This lets you optimize your programs when accessing data residing within an internal table.
Getting ready
In this recipe, we will create a program that will store all data of table VBAK
into an internal table. Then we will use the secondary key in order to fetch a record pertaining to a given order number, aufnr
. The primary emphasis of this recipe is on the definition and usage of a secondary key for internal tables.
How to do it...
For creating a program using secondary index in internal tables, follow the steps below:
We first declare a type
ty_vbak
based on the database tablevbak
. We create two keys for this table type. The first is a non-unique primary key havingvbeln
as the key field. We also create a non-unique sorted secondary keysec_key
having one fieldaufnr
. An internal tableit_vbak
is defined based on the typety_vbak
. In addition, a work areawa_vbak...