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: 

link two inner table by index

Former Member
0 Kudos

Hi guys

    now I miss one problem , I hope to   two  link  two inner table  more fast.  both of the tables have millions recoreds.

I have been read some code.but I dont know  WHY?

Can you explain ?  HELP ME !  thank you.



SORT gt_tab01 BY field.

SORT gt_tab02 BY field.

l_index = 1.

LOOP AT gt_tab01 INTO gs_tab01.

READ TABLE gt_tab02  INTO gs_tab02 INDEX l_index.

CHECK sy-subrc = 0.

IF gs_tab02-field = gs_tab01-field.

l_index  = l_index + 1.

ENDIF.

ENDLOOP.

9 REPLIES 9

PeterJonker
Active Contributor
0 Kudos

Can you explain what you are trying to achieve ? Because this code doesn't really do much except for using your memory.

0 Kudos

THANKS FOR YOU ATTENTION.

THIS CODE FROM  BOOK ABOUT ABAP.

  This code is for linking two inner table which have millions recoreds.

former_member306787
Active Participant
0 Kudos

Hello Wei Liang,

Why would you want to link 2 itabs by the index? This is prone to errors...

Don't you have a common unique ID field in both itabs to link them?

For performance improvements, use a hashed or sorted table.

----

Regarding the code sample you provided, my initial idea about the WHY question, is that

(1) L_INDEX is keeping a count how many times the value in GS_TAB02-FIELD equals the value in GS_TAB01-FIELD.

(2) On the other hand, you might interpret this differently: the variable L_INDEX keeps track which index number in GT_TAB02 is missing a value in field GT_TAB02-FIELD, but is present in table GT_TAB01-FIELD.

But theoretically, this has some limitations/design features: the number of identical values in GT_TAB01-FIELD must be equal or larger then the number of identical values in GT_TAB02-FIELD and each value in GT_TAB01-FIELD must be present in GT_TAB02-FIELD.

I don't know the exact purpose of the programmer when he/she 'designed' this piece of code, but I would never do this using an index.

Best regards,

Zhou

former_member220028
Active Contributor
0 Kudos

Hi,

there is no faster method than this.

is this code working for you? normaly you read table entries by there key fields, not by index.

regards

Stefan Seeburger

VenkatRamesh_V
Active Contributor
0 Kudos

Hi,

Try,

LOOP AT gt_tab01 INTO gs_tab01.

READ TABLE gt_tab02   with key   gs_tab02-field  = gs_tab01-field   Transporting no fields .

CHECK sy-subrc = 0.

l_index  = l_index + 1.

ENDLOOP.


Hope you are checking the content of internal table, then above code will be helpful.


Regards,

Venkat.

0 Kudos

Your code will be much slower because it use key access without binary search. Index access is the fastest as Stefansaid earlier.

0 Kudos

THANKS  a lot ,This way I have been used. It is a good way.

former_member210541
Active Participant
0 Kudos

This is the fastest method.... please notice the following points

1. both tables are sorted on the same key, so the sequence of availability of "field" is same for both tables.

2.The read with index is faster

3.upon success it is incrementing the index value by 1, hence the previous entries are not at all scanned in the next iteration.

0 Kudos

Thanks for you answer.

This code is aimed at improve the efficiency of table joins in when inner table have too much record.

  There are two ways to improve efficiency of table joins in.

  1.using index (sort two table and  use one variable  to link two table  ,this is my problem,I dont know which way is better.)

   2.using index (sort one table ,this way is what you say).