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

INSERT LINES into HASHED Table

Former Member
0 Likes
12,799

Hi,

I have 2 hashed tables of same structure. These 2 hashed tables contain different data.

I want to insert lines of one hashed table to the other hashed table.

Usually for reading a record from a hashed table having 1 entry or 100000 entries, it takes same time.

In case of INSERT LINES, will it take the same time for Inserting 1 line or 1000000 lines?

Thanks & Regards,

Adithya M.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
6,225

Hi Ashish/Akshat/Purnand,

Thanks for your response.

To test this, I created a test program & ran it switching on the Trace in ST12.

When I checked the ABAP Trace in ST12, INSERTING MULTIPLE LINES is having more GrossTime/NetTime % than INSERTING single line.

Also the new lines are Appended instead of Inserting as per the key?

Below is my Test Program.

According to what you said, the last 2 Inserts should have taken same time in ST12. But it didn't happen that way.

Please correct if am checking wrongly.

  TYPES: BEGIN OF t_itab,
         kunnr TYPE kunnr,
         bukrs TYPE bukrs,
         zterm TYPE dzterm,
        END OF t_itab.

DATA: it_itab1 TYPE HASHED TABLE OF t_itab WITH UNIQUE KEY kunnr,
          it_itab2 TYPE HASHED TABLE OF t_itab WITH UNIQUE KEY kunnr,
          it_itab3 TYPE HASHED TABLE OF t_itab WITH UNIQUE KEY kunnr.


DATA: wa TYPE t_itab.

wa-kunnr = 1000.
INSERT wa INTO TABLE it_itab1.

wa-kunnr = 1000.
DO 1000000 TIMES.
  wa-kunnr = wa-kunnr + 2.
  INSERT wa INTO TABLE it_itab2.
ENDDO.

wa-kunnr = 1001.
DO 1000000 TIMES.
  wa-kunnr = wa-kunnr + 2.
  INSERT wa INTO TABLE it_itab3.
ENDDO.

INSERT LINES OF it_itab1 INTO TABLE it_itab3. "--->Inserting 1 entry
INSERT LINES OF it_itab2 INTO TABLE it_itab3. "--->Inserting multiple entries

11 REPLIES 11
Read only

Abhijit74
Active Contributor
Read only

Former Member
0 Likes
6,225

hi,

yes it would take same time.

Number of records does not affect hashed table processing that is the advantage of using hashed table with large number of records.

Read only

0 Likes
6,225

Please check my analysis below.

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
6,225

Hi Adithya,

Yes, I believe it will take the same time to read as well as insert in a hashed table. That's because when you insert an entry into a hashed table, the time critical operation is finding the right place for the entry to be inserted (which is similar to what happens in a read).

Read only

Former Member
0 Likes
6,225

Please check my analysis below.

Read only

Former Member
0 Likes
6,225

Hi Aadhi,

I believe that it will take the same time for Inserting 1 line or 1000000 lines because of its unique key feature and thats its biggest advantage. Its used for processing larger amount of data.

Read only

0 Likes
6,225

Please check my analysis below.

Read only

Former Member
0 Likes
6,226

Hi Ashish/Akshat/Purnand,

Thanks for your response.

To test this, I created a test program & ran it switching on the Trace in ST12.

When I checked the ABAP Trace in ST12, INSERTING MULTIPLE LINES is having more GrossTime/NetTime % than INSERTING single line.

Also the new lines are Appended instead of Inserting as per the key?

Below is my Test Program.

According to what you said, the last 2 Inserts should have taken same time in ST12. But it didn't happen that way.

Please correct if am checking wrongly.

  TYPES: BEGIN OF t_itab,
         kunnr TYPE kunnr,
         bukrs TYPE bukrs,
         zterm TYPE dzterm,
        END OF t_itab.

DATA: it_itab1 TYPE HASHED TABLE OF t_itab WITH UNIQUE KEY kunnr,
          it_itab2 TYPE HASHED TABLE OF t_itab WITH UNIQUE KEY kunnr,
          it_itab3 TYPE HASHED TABLE OF t_itab WITH UNIQUE KEY kunnr.


DATA: wa TYPE t_itab.

wa-kunnr = 1000.
INSERT wa INTO TABLE it_itab1.

wa-kunnr = 1000.
DO 1000000 TIMES.
  wa-kunnr = wa-kunnr + 2.
  INSERT wa INTO TABLE it_itab2.
ENDDO.

wa-kunnr = 1001.
DO 1000000 TIMES.
  wa-kunnr = wa-kunnr + 2.
  INSERT wa INTO TABLE it_itab3.
ENDDO.

INSERT LINES OF it_itab1 INTO TABLE it_itab3. "--->Inserting 1 entry
INSERT LINES OF it_itab2 INTO TABLE it_itab3. "--->Inserting multiple entries

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
6,225

Since you were comparing the behaviour with the read operation and stated the fact that it takes the same amount of time while reading from a hashed table whatever be the number of entries in the table being read, I thought your question was if it would take the same amount of time to insert n records in a hashed table irrespective of the number of entries in the table. And that's what I wrote in my response too. I did not mean to say that it would take the same amount of time to insert a single and multiple records in a hashed table. Of course, the greater the number of records you are inserting, greater will be the time required.

Read only

Former Member
0 Likes
6,225

Hi ,

in case of Hashed table it works according to hash algorithm.

Hashed Tables:

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.

What is hashed algorithm?

Hashed algorithm is a one-way mathematical function that encrypts data. The one-way indicates here that with the current computer power and algorithms available the one-way hash cannot be calculated backwards meaning that the hash value cannot be decrypted to reveal the password in clear text again.

Thanks

Sabyasachi

Read only

Former Member
0 Likes
6,225

Hi if you got your answer plzz close your thread..

Thanks

Sabyasachi