Internal Table

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
manicveera
Posts: 79
Joined: Mon Mar 08, 2004 9:11 am

Internal Table

Post by manicveera » Thu Nov 17, 2005 12:41 am

Hi,

Please clarify the following issue.

I have two internal table, Table 1 has around 60,000 records and table 2 has 3,00,000 lac records. I want to use key from table 1 and search ie.read the records from tabl2 with key and update the value from table 2 to table 1. This process took more time and gives time out error. If the records are less the prog.works good.
I have declared both the internal tables are standard table.

How to reduce the process time ? If I declare the table as SORTED OR HASHED will it reduce the time ? Or Tell me other solution to sort it out.

Thanks & Regards

M.Veera

Rich
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool
Contact:

Post by Rich » Thu Nov 17, 2005 2:59 am

Declare table two as a hashed table with the key as the key you are using from table 1.

See topic 0016 - Internal table types in the Abappers Knowledge Corner.
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com

christmaslights
Posts: 857
Joined: Wed Jun 16, 2004 5:13 am
Location: Hampshire, England

Post by christmaslights » Thu Nov 17, 2005 7:07 am

Simpler method using standard tables for people like me who haven't managed to fathom hash tables. Sort both tables by key. Loop at table1. For each table1 entry loop at table2. If the table2 key matches the table1 key add the fields you want to table1 and then delete the table2 entry. If the key fields don't match, exit the table 2 loop. So, you effectively pass through table2 once rather than loads of times because deleting each accepted record moves the next record you want to the top of table2.

wizbongre
Posts: 255
Joined: Thu Dec 19, 2002 8:19 am

Post by wizbongre » Thu Nov 17, 2005 9:00 am

christmaslights wrote:Simpler method using standard tables for people like me who haven't managed to fathom hash tables. Sort both tables by key. Loop at table1. For each table1 entry loop at table2. If the table2 key matches the table1 key add the fields you want to table1 and then delete the table2 entry. If the key fields don't match, exit the table 2 loop. So, you effectively pass through table2 once rather than loads of times because deleting each accepted record moves the next record you want to the top of table2.
Or alternatively use the parralal cursor technique - almost the same as the above suggestion except every time you exit out of the second loop you set a field to equal sy-tabix. Then you always loop at the second table FROM W_TABIX. I think there is a demo ABAP in the example programs...

whizkidd17
Posts: 95
Joined: Wed Sep 10, 2003 11:44 pm

Post by whizkidd17 » Fri Nov 18, 2005 2:15 am

christmaslights wrote:Simpler method using standard tables for people like me who haven't managed to fathom hash tables. Sort both tables by key. Loop at table1. For each table1 entry loop at table2. If the table2 key matches the table1 key add the fields you want to table1 and then delete the table2 entry. If the key fields don't match, exit the table 2 loop. So, you effectively pass through table2 once rather than loads of times because deleting each accepted record moves the next record you want to the top of table2.
Using hashed tables would significantly improve the performance of your program. It wouldn't hurt to read more about it since it would definitely help you a lot to fine tune your current and your future programs.

FYI. Access time using the key is constant, regardless of the number of table entries. -SAP F1 (",)

christmaslights
Posts: 857
Joined: Wed Jun 16, 2004 5:13 am
Location: Hampshire, England

Post by christmaslights » Fri Nov 18, 2005 5:38 am

wizbongre wrote:...loop at the second table FROM W_TABIX....
I didn't know you could do that. That would be better if you need to keep the contents of table2. Of course, both looping techniques would fail dismally if there were any records in table2 that didn't have a related record with the same key in table1 (I realised yesterday).
Using hashed tables would significantly improve the performance of your program. It wouldn't hurt to read more about it since it would definitely help you a lot to fine tune your current and your future programs.
It takes about half a minute for my loop to deal with 35,000+ records in table1 and 200,000+ in table2 which I think is reasonable. But you're right and I will make a note to try again with hash tables.

Rich
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool
Contact:

Post by Rich » Fri Nov 18, 2005 6:28 am

You can find a complete topic on tables and hashed tables - what they are and how they work min the Abappers Knowledge Corner. Note that you will have to register to access this.
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com

Post Reply