Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

hashed & sorted internal tables

deepak_kumar11
Participant
0 Kudos

hi all,

can any body help me to understand the concept of <b>hashed & sorted</b> internal table & how they can be used for improve the performance of report.

regards

Deepak

5 REPLIES 5

Former Member
0 Kudos

You can see this link

/people/harry.dietz/blog/2005/10/28/performance-improvement-hints-3-internal-table--fill-and-read

http://www.sap-img.com/abap/what-are-different-types-of-internal-tables-and-their-usage.htm

kishan negi

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

SORTED table

Defines the table as one that is always saved correctly sorted.

Key access to a sorted table uses a binary key. If the key is not unique, the system takes the entry with the lowest index. The runtime required for key access is logarithmically related to the number of table entries.

HASHED table

Defines the table as one that is managed with an internal hash procedure

You can only access a hashed table using the generic key operations or other generic operations ( SORT, LOOP, and so on). Explicit or implicit index operations (such as LOOP ... FROM oe INSERT itab within a LOOP) are not allowed.

Former Member
0 Kudos

hi,

Check this out

REPORT zforum34  LINE-SIZE 255.
 
PARAMETERS p_ktopl LIKE t001-ktopl.
PARAMETERS p_bukrs LIKE t001-bukrs.
PARAMETERS p_konto LIKE skb1-saknr.
 
DATA: t1   TYPE i,
      t2   TYPE i,
      tmin TYPE i.
 
DATA stab TYPE SORTED TABLE OF skb1 WITH UNIQUE KEY bukrs  saknr.
DATA htab TYPE HASHED TABLE OF skb1 WITH UNIQUE KEY bukrs  saknr.
DATA wa TYPE skb1.
 
SELECT        * FROM  skb1 INTO TABLE stab.
write: /'cnt:', sy-dbcnt.
uline.
htab = stab.
 
 
GET RUN TIME FIELD t1.
READ TABLE stab INTO wa WITH TABLE KEY bukrs = p_bukrs
                                       saknr = p_konto.
 
GET RUN TIME FIELD t2.
tmin = t2 - t1.
WRITE:/  'sorted table :', tmin, 'microseconds'.
 
ULINE.
CLEAR: t1, t2, tmin.
FREE stab.
GET RUN TIME FIELD t1.
READ TABLE htab INTO wa WITH TABLE KEY bukrs = p_bukrs
                                       saknr = p_konto.
 
GET RUN TIME FIELD t2.
tmin = t2 - t1.
WRITE:/  'hashed table :', tmin, 'microseconds'.

Former Member
0 Kudos

Check...

/people/harry.dietz/blog/2005/10/28/performance-improvement-hints-3-internal-table--fill-and-read

Former Member
0 Kudos

Hi Deepak,

If you have an internal table in your program which is used solely for lookup, it is good programming practice to use a hash table. The example below shows this, in combination with a method for buffering SELECT SINGLE results.

Code

&----


*& Form select_dispo

&----


  • Get MRP controller and in-house production time from material

  • and plant

----


  • --> MATNR Material

  • --> RESWK Plant

  • <-- DISPO MRP controller

  • <-- DZEIT In-house production time

----


form select_from_marc using matnr werks dispo dzeit.

types: begin of mrp_lookup_type,

matnr like marc-matnr,

werks like marc-werks,

dispo like marc-dispo,

dzeit like marc-dzeit,

end of mrp_lookup_type.

  • Define static hashed table to hold results

statics: st_mrp type hashed table of mrp_lookup_type

with unique key matnr werks.

data: l_wa_mrp type mrp_lookup_type.

clear dzeit.

  • See if data is in the table

read table st_mrp into l_wa_mrp with table key matnr = matnr

werks = werks.

  • If not in table, get it from the database

if not sy-subrc is initial.

select single dispo dzeit from marc

into corresponding fields of l_wa_mrp-dispo

where matnr eq matnr

and werks eq werks.

  • Insert into table

l_wa_mrp-matnr = matnr.

l_wa_mrp-werks = werks.

insert l_wa_mrp into table st_mrp.

endif.

dispo = l_wa_mrp-dispo. " MRP Controller

dzeit = l_wa_mrp-dzeit. " Inhouse production time

endform. " select_from_marc