Skip to Content
avatar image
Former Member

link two inner table by index

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Oct 15, 2015 at 04: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.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 15, 2015 at 07: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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

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

  • Oct 15, 2015 at 02:08 PM

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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      THANKS FOR YOU ATTENTION.

      THIS CODE FROM  BOOK ABOUT ABAP.

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

  • Oct 15, 2015 at 02: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

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 15, 2015 at 02: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

    Add comment
    10|10000 characters needed characters exceeded