Supercharge performance with hashed tables

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

    When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchSAP.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSAP.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

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

This was first published in June 2002

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.