SAP ABAP - Hashed Internal Table (Partial Key Access) With Example.


Submitted By: Shilpa Gunjan (L&T Infotech)


Comparison between Standard, Sorted & Hashed internal tables & it's performance.

(Hashed Table performance when the key used is table’s partial key)


REPORT z_internal_table_performance.


*Internal table (Performance)
PARAMETERS p_ktopl LIKE t001-ktopl.
PARAMETERS p_bukrs LIKE skb1-bukrs.
PARAMETERS p_saknr LIKE skb1-saknr.

DATA: v_time1 TYPE i,
v_time2 TYPE i,
v_time_f TYPE i.

DATA: st_skb1 TYPE STANDARD TABLE OF skb1,
so_skb1 TYPE SORTED TABLE OF skb1 WITH UNIQUE KEY bukrs saknr,
ha_skb1 TYPE HASHED TABLE OF skb1 WITH UNIQUE KEY bukrs saknr,
wa_skb1 TYPE skb1.



SELECT * FROM skb1 INTO TABLE st_skb1.
WRITE: /'No.Of Entries Fetched:', sy-dbcnt.
ULINE.

so_skb1 = st_skb1.
ha_skb1 = so_skb1.

*********STANDARD TABLE**************
CLEAR: wa_skb1, v_time1, v_time2, v_time_f.
GET RUN TIME FIELD v_time1.
READ TABLE st_skb1 INTO wa_skb1 WITH KEY bukrs = p_bukrs.
GET RUN TIME FIELD v_time2.
v_time_f = v_time2 - v_time1.
WRITE:/ 'Standard Table :', v_time_f, 'ms.'.

ULINE.
CLEAR: v_time1, v_time2, v_time_f, wa_skb1.
*************************************

********SORTED TABLE******************
GET RUN TIME FIELD v_time1.
READ TABLE so_skb1 INTO wa_skb1 WITH KEY bukrs = p_bukrs.
GET RUN TIME FIELD v_time2.
v_time_f = v_time2 - v_time1.
WRITE:/ 'Sorted Table :', v_time_f, 'ms.'.

ULINE.
CLEAR: v_time1, v_time2, v_time_f,wa_skb1.
********************************************

***********HASHED TABLE*********************
GET RUN TIME FIELD v_time1.
READ TABLE ha_skb1 INTO wa_skb1 WITH KEY bukrs = p_bukrs.

GET RUN TIME FIELD v_time2.
v_time_f = v_time2 - v_time1.

WRITE:/ 'Hashed Table :', v_time_f, 'ms.'.


OUTPUT:












On Executing:

















Here we can see the comparison of three tables : Standard, Sorted & Hashed. From the output it's very clear that if the key is a partial key of the tables' primary key combinations, then the best way to read tables is via sorted tables. Sorted tables are the most efficient in reading data from internal table on partial keys.


RELATED POSTS:

- INTERNAL TABLES - Introduction, Advantages & Types Of Internal Tables.

- STANDARD INTERNAL TABLE (Index Table) - Introduction With Sample Programs.

- SORTED INTERNAL TABLE (Index Table) - Introduction, Advantages & Performance.

- SORTED INTERNAL TABLE With Key Access (Performance) - Sample Program.

- SORTED INTERNAL TABLE With INDEX Access (Performance) - Sample Program.

- HASHED INTERNAL TABLE (Non-Index Table) - Introduction, Advantages & Performance.

- HASHED INTERNAL TABLE - Partial Key Access (Performance) - Sample Program.

- HASHED INTERNAL TABLE - Table's Key Access (Performance) - Sample Program.


Your suggestions and comments are welcome in this section.

Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.

No comments:

Post a Comment