10-15-2015 1:18 PM
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.
10-15-2015 3:08 PM
Can you explain what you are trying to achieve ? Because this code doesn't really do much except for using your memory.
10-15-2015 3:21 PM
THANKS FOR YOU ATTENTION.
THIS CODE FROM BOOK ABOUT ABAP.
This code is for linking two inner table which have millions recoreds.
10-15-2015 3:21 PM
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
10-15-2015 3:23 PM
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
10-15-2015 5:07 PM
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.
10-15-2015 8:23 PM
10-16-2015 6:13 AM
10-15-2015 8:53 PM
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.
10-16-2015 6:12 AM
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).