Application Development and Automation 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: 
Read only

Hashed internal table and sorted internal tbale

Former Member
0 Likes
2,246

Hi,

I want to know in which situation we are going to use these hashed and sorted internal tables I want to know in depth. Can you please provide sample code for hashed and sorted internal table with some scenarios. I have used only standard internal table.

Thanks & Regards

Mahesh D.R

Hi,

I want to know in which situation we are going to use these hashed and sorted internal tables I want to know in depth. Can you please provide sample code for hashed and sorted internal table with some scenarios. I have used only standard internal table.

Thanks & Regards

Mahesh D.R

3 REPLIES 3
Read only

Former Member
0 Likes
978

Hi,

<b>Sorted Internal Tables:</b>

Sorted tables are always saved correctly sorted by key. They also have a linear key, and, like standard tables, you can access them using either the table index or the key. When you use the key, the response time is in logarithmic relationship to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique, or non-unique, and you must specify either UNIQUE or NON-UNIQUE in the table definition. Standard tables and sorted tables both belong to the generic group index tables.

This table type is particularly suitable if you want the table to be sorted while you are still adding entries to it. You fill the table using the (INSERT) statement, according to the sort sequence defined in the table key. Table entries that do not fit are recognised before they are inserted. The response time for access using the key is in logarithmic relation to the number of table entries, since the system automatically uses a binary search. Sorted tables are appropriate for partially sequential processing in a LOOP, as long as the WHERE condition contains the beginning of the table key.

<b>Hashed Internal Tables:</b>

Hashes tables have no internal linear index. You can only access hashed tables by specifying the key. The response time is constant, regardless of the number of table entries, since the search uses a hash algorithm. The key of a hashed table must be unique, and you must specify UNIQUE in the table definition.

This table type is particularly suitable if you want mainly to use key access for table entries. You cannot access hashed tables using the index. When you use key access, the response time remains constant, regardless of the number of table entries. As with database tables, the key of a hashed table is always unique. Hashed tables are therefore a useful way of constructing and

using internal tables that are similar to database tables.

Check this link

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

Regards,

Priyanka.

Read only

Former Member
0 Likes
978

Hi,

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.

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'.

Check...

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

<b>Reward points</b>

Regards

Read only

Former Member
0 Likes
978

HI,

<b>Sorted tables</b> are always saved sorted by the key. They also have an internal index. The system can access records either by using the table index or the key. The response time for key access is logarithmically proportional to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique or non-unique. When you define the table, you must specify whether the key is to be UNIQUE or NON-UNIQUE. Standard tables and sorted tables are known generically as index tables.

<b>Hashed tables</b> have no linear index. You can only access a hashed table using its key. The response time is independent of the number of table entries, and is constant, since the system access the table entries using a hash algorithm. The key of a hashed table must be unique. When you define the table, you must specify the key as UNIQUE.

this is how we will define them

TYPES: BEGIN OF LINE,

COLUMN1 TYPE I,

COLUMN2 TYPE I,

COLUMN3 TYPE I,

END OF LINE.

data VECTOR TYPE HASHED TABLE OF line WITH UNIQUE KEY TABLE LINE.

data ITAB TYPE SORTED TABLE OF LINE WITH UNIQUE KEY COLUMN1.

enter some data into these tables and write,observe the diffrence

rgds,

bharat.