SAP ABAP - Hashed Internal Table (Table's Key Access) With Example.
Submitted By: Shilpa Gunjan (L&T Infotech)
(Hashed Table performance when the key used is table’s key)
Now the table SKB1 has a primary key which is a combination of BUKRS (Company Code) & SAKNR (G/L Account Number).
When we make a hashed table with key same as the table key, the performance improves drastically as shown.
REPORT z_internal_table_performance.
*Sorted 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
saknr = p_saknr.
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 table KEY bukrs = p_bukrs
saknr = p_saknr.
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 table KEY bukrs = p_bukrs
saknr = p_saknr.
GET RUN TIME FIELD v_time2.
v_time_f = v_time2 - v_time1.
WRITE:/ 'Hashed Table :', v_time_f, 'ms.'.
OUTPUT:
On Executing:
Tip: You can sort hashed internal table but never sort it because it will affect the performance badly.
Include a sort statement as shown:
***********HASHED TABLE*********************
SORT ha_skb1 BY bukrs saknr.
GET RUN TIME FIELD v_time1.
READ TABLE ha_skb1 INTO wa_skb1 WITH table KEY bukrs = p_bukrs
saknr = p_saknr.
GET RUN TIME FIELD v_time2.
v_time_f = v_time2 - v_time1.
WRITE:/ 'Hashed Table :', v_time_f, 'ms.'.
OUTPUT:
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.