Hashed Internal table faster access
The source tables ITAB1 and ITAB2 are standard tables. It is assumed that ITAB1 takes more entries than ITAB2. Otherwise, the table with more entries must be computed with "DESCRIBE TABLE ... LINES ...".Since both tables shall represent sets, it is assumed that their entries are unique with respect to component K.
The algorithm works with a temporary table with unique key K. The table is a copy of ITAB1 and is used to locate the entries being also contained in ITAB2. The matching entries are copied to ITAB3.
The left-hand and right-hand side differ only by the kind of the temporary table being used. For a hashed table, the READ statement in the LOOP is faster than for the sorted table.
Using a sorted table
STAB1 = ITAB1.
REFRESH ITAB3.
LOOP AT ITAB2 ASSIGNING <WA>.
READ TABLE STAB1 FROM <WA>
TRANSPORTING NO FIELDS.
IF SY-SUBRC = 0.
APPEND <WA> TO ITAB3.
ENDIF.
ENDLOOP.
FREE STAB1.
HTAB1 = ITAB1.
REFRESH ITAB3.
LOOP AT ITAB2 ASSIGNING <WA>.
READ TABLE HTAB1 FROM <WA>
TRANSPORTING NO FIELDS.
IF SY-SUBRC = 0.
APPEND <WA> TO ITAB3.
ENDIF.
ENDLOOP.
FREE HTAB1.
For more Tutorials, visit ABAP Tutorials, Tips & Tricks and Certification Questions
No comments:
Post a Comment