Tip

Supercharge performance with hashed tables

You've optimized your select, used joins and internally buffered using internal tables and binary reads. Now supercharge the performance by using hashed internal tables with direct reads instead of binary searches!

If the internal tables you are working with have unique keys, and are referenced as part of your code, you should find that defining the tables as Hashed tables are the logical choice when building and utilizing internal tables with unique indexes that are to be referenced later and include large amounts of data. This is the most efficient way of managing the internal data and minimizing access time. Using hashed internal tables the 100,000th record is read just as quickly as the 1st making it much faster than even a binary search.

--------------------------------------

* declare the table as type hashed.
TYPES: BEGIN OF LINE,
         COL1 TYPE I,
         COL2 TYPE I,
       END OF LINE.

DATA: ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1,
      WA LIKE LINE OF ITAB.


* example inserting data into the table
DO 4 TIMES.
  WA-COL1 = SY-INDEX.
  WA-COL2 = SY-INDEX ** 2.
  INSERT WA INTO TABLE ITAB.
ENDDO.

* assign key and read record
WA-COL1 = 2.
READ TABLE ITAB FROM WA INTO WA.

* assign new value and modify record
WA-COL2 = 100.
MODIFY TABLE ITAB FROM WA.

* assign key and delete record
WA-COL1 = 4.
DELETE TABLE ITAB FROM WA.

* display contents
LOOP AT ITAB INTO WA.
  WRITE: / WA-COL1, WA-COL2.
ENDLOOP.

**********************************
The

    Requires Free Membership to View

list is as follows: 1 1 2 100 3 9 *

This was first published in June 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.