<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Reading internal table with 2 different keys needed in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-table-with-2-different-keys-needed/m-p/4337134#M1033160</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt; i have faced same problem , for at least two occasions, and 'm applying a solution,  but i'll like to know if there is a better one (for performance reasons, or other ones , memory , etc...)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is that i need to loop an internal table (a large one), searching for some key entries, and for each one , search for all entries in same table with same value in other field (and do some logic for each one ).&lt;/P&gt;&lt;P&gt;The logic i am applying is to copy the internal table, in an auxiliary internal table, and sort the original table with first criteria and the second with the other criteria.&lt;/P&gt;&lt;P&gt;The two tables are standard.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then i have 2 nested loops , for searching all the entries with some keys , and for each one loop for all related entries with same value in another field (second key). In both cases i read using binary search, and then loop from that index , until key values change.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, here is a code extract:&lt;/P&gt;&lt;P&gt;FORM filtra_punteros_exc  TABLES   pt_pit_pointer STRUCTURE  bdcp&lt;/P&gt;&lt;P&gt;                                   &lt;/P&gt;&lt;P&gt;  DATA: lt_pit_pointer_sort_mat TYPE TABLE OF bdcp,&lt;/P&gt;&lt;P&gt;        wa_pit_pointer LIKE LINE OF pt_pit_pointer,&lt;/P&gt;&lt;P&gt;        wa_pit_pointer_sort LIKE LINE OF lt_pit_pointer_sort_mat.&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;sort original table&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;SORT pt_pit_pointer BY cdobjcl tabname fldname.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;auxiliary table, sorted by other criteria&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;lt_pit_pointer_sort_mat[] = pt_pit_pointer[].&lt;/P&gt;&lt;P&gt;SORT lt_pit_pointer_sort_mat BY cdobjid.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;loop all keys&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;LOOP AT pt_point_exc INTO wa_point_exc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;read key&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  READ TABLE pt_pit_pointer WITH KEY&lt;/P&gt;&lt;P&gt;         cdobjcl = wa_point_exc-cdobjcl&lt;/P&gt;&lt;P&gt;         tabname = wa_point_exc-tabname&lt;/P&gt;&lt;P&gt;         fldname = wa_point_exc-fldname&lt;/P&gt;&lt;P&gt;       BINARY SEARCH&lt;/P&gt;&lt;P&gt;         TRANSPORTING NO FIELDS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;      l_tabix = sy-tabix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    read all entries with this key&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;      LOOP AT pt_pit_pointer INTO wa_pit_pointer FROM l_tabix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      Leave the loop, if last relevant entry one read&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;        IF wa_pit_pointer-cdobjcl &amp;lt;&amp;gt; wa_point_exc-cdobjcl OR&lt;/P&gt;&lt;P&gt;           wa_pit_pointer-tabname &amp;lt;&amp;gt; wa_point_exc-tabname  OR&lt;/P&gt;&lt;P&gt;           wa_pit_pointer-fldname &amp;lt;&amp;gt; wa_point_exc-fldname.&lt;/P&gt;&lt;P&gt;          EXIT.&lt;/P&gt;&lt;P&gt;        ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      for each key, search for all entries with same value in cdobjid&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        READ TABLE lt_pit_pointer_sort_mat WITH KEY&lt;/P&gt;&lt;P&gt;                 cdobjid =  wa_pit_pointer-cdobjid&lt;/P&gt;&lt;P&gt;                 BINARY SEARCH&lt;/P&gt;&lt;P&gt;                 TRANSPORTING NO FIELDS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;          l_tabix2 = sy-tabix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          LOOP AT lt_pit_pointer_sort_mat INTO wa_pit_pointer_sort FROM l_tabix2.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;          Leave the loop, if last relevant entry one read&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;            IF wa_pit_pointer_sort-cdobjid &amp;lt;&amp;gt; wa_pit_pointer-cdobjid.&lt;/P&gt;&lt;P&gt;              EXIT.&lt;/P&gt;&lt;P&gt;            ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;         some logic here ...&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;           &lt;/P&gt;&lt;P&gt;          ENDLOOP.&lt;/P&gt;&lt;P&gt;        ENDIF.&lt;/P&gt;&lt;P&gt;      ENDLOOP.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for your valuable sugestions,&lt;/P&gt;&lt;P&gt;Miquel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 22 Aug 2008 09:20:52 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-08-22T09:20:52Z</dc:date>
    <item>
      <title>Reading internal table with 2 different keys needed</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-table-with-2-different-keys-needed/m-p/4337134#M1033160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt; i have faced same problem , for at least two occasions, and 'm applying a solution,  but i'll like to know if there is a better one (for performance reasons, or other ones , memory , etc...)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is that i need to loop an internal table (a large one), searching for some key entries, and for each one , search for all entries in same table with same value in other field (and do some logic for each one ).&lt;/P&gt;&lt;P&gt;The logic i am applying is to copy the internal table, in an auxiliary internal table, and sort the original table with first criteria and the second with the other criteria.&lt;/P&gt;&lt;P&gt;The two tables are standard.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then i have 2 nested loops , for searching all the entries with some keys , and for each one loop for all related entries with same value in another field (second key). In both cases i read using binary search, and then loop from that index , until key values change.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, here is a code extract:&lt;/P&gt;&lt;P&gt;FORM filtra_punteros_exc  TABLES   pt_pit_pointer STRUCTURE  bdcp&lt;/P&gt;&lt;P&gt;                                   &lt;/P&gt;&lt;P&gt;  DATA: lt_pit_pointer_sort_mat TYPE TABLE OF bdcp,&lt;/P&gt;&lt;P&gt;        wa_pit_pointer LIKE LINE OF pt_pit_pointer,&lt;/P&gt;&lt;P&gt;        wa_pit_pointer_sort LIKE LINE OF lt_pit_pointer_sort_mat.&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;sort original table&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;SORT pt_pit_pointer BY cdobjcl tabname fldname.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;auxiliary table, sorted by other criteria&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;lt_pit_pointer_sort_mat[] = pt_pit_pointer[].&lt;/P&gt;&lt;P&gt;SORT lt_pit_pointer_sort_mat BY cdobjid.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;loop all keys&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;LOOP AT pt_point_exc INTO wa_point_exc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;read key&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  READ TABLE pt_pit_pointer WITH KEY&lt;/P&gt;&lt;P&gt;         cdobjcl = wa_point_exc-cdobjcl&lt;/P&gt;&lt;P&gt;         tabname = wa_point_exc-tabname&lt;/P&gt;&lt;P&gt;         fldname = wa_point_exc-fldname&lt;/P&gt;&lt;P&gt;       BINARY SEARCH&lt;/P&gt;&lt;P&gt;         TRANSPORTING NO FIELDS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;      l_tabix = sy-tabix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    read all entries with this key&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;      LOOP AT pt_pit_pointer INTO wa_pit_pointer FROM l_tabix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      Leave the loop, if last relevant entry one read&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;        IF wa_pit_pointer-cdobjcl &amp;lt;&amp;gt; wa_point_exc-cdobjcl OR&lt;/P&gt;&lt;P&gt;           wa_pit_pointer-tabname &amp;lt;&amp;gt; wa_point_exc-tabname  OR&lt;/P&gt;&lt;P&gt;           wa_pit_pointer-fldname &amp;lt;&amp;gt; wa_point_exc-fldname.&lt;/P&gt;&lt;P&gt;          EXIT.&lt;/P&gt;&lt;P&gt;        ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      for each key, search for all entries with same value in cdobjid&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        READ TABLE lt_pit_pointer_sort_mat WITH KEY&lt;/P&gt;&lt;P&gt;                 cdobjid =  wa_pit_pointer-cdobjid&lt;/P&gt;&lt;P&gt;                 BINARY SEARCH&lt;/P&gt;&lt;P&gt;                 TRANSPORTING NO FIELDS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;          l_tabix2 = sy-tabix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          LOOP AT lt_pit_pointer_sort_mat INTO wa_pit_pointer_sort FROM l_tabix2.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;          Leave the loop, if last relevant entry one read&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;            IF wa_pit_pointer_sort-cdobjid &amp;lt;&amp;gt; wa_pit_pointer-cdobjid.&lt;/P&gt;&lt;P&gt;              EXIT.&lt;/P&gt;&lt;P&gt;            ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;         some logic here ...&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;           &lt;/P&gt;&lt;P&gt;          ENDLOOP.&lt;/P&gt;&lt;P&gt;        ENDIF.&lt;/P&gt;&lt;P&gt;      ENDLOOP.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for your valuable sugestions,&lt;/P&gt;&lt;P&gt;Miquel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Aug 2008 09:20:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-table-with-2-different-keys-needed/m-p/4337134#M1033160</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-22T09:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Reading internal table with 2 different keys needed</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-table-with-2-different-keys-needed/m-p/4337135#M1033161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry for bad formatting. I try to arrange it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; 
FORM filtra_punteros_exc TABLES pt_pit_pointer STRUCTURE bdcp

DATA: lt_pit_pointer_sort_mat TYPE TABLE OF bdcp,
wa_pit_pointer LIKE LINE OF pt_pit_pointer,
wa_pit_pointer_sort LIKE LINE OF lt_pit_pointer_sort_mat.
...



*sort original table 
SORT pt_pit_pointer BY cdobjcl tabname fldname.

*auxiliary table, sorted by other criteria 
lt_pit_pointer_sort_mat] = pt_pit_pointer[.
SORT lt_pit_pointer_sort_mat BY cdobjid.


*loop all keys 
LOOP AT pt_point_exc INTO wa_point_exc.


*read key 
  READ TABLE pt_pit_pointer WITH KEY
         cdobjcl = wa_point_exc-cdobjcl  
         tabname = wa_point_exc-tabname
         fldname = wa_point_exc-fldname
       BINARY SEARCH
       TRANSPORTING NO FIELDS.

  IF sy-subrc = 0.
     l_tabix = sy-tabix.


*    read all entries with this key 
     LOOP AT pt_pit_pointer INTO wa_pit_pointer FROM l_tabix.


*        Leave the loop, if last relevant entry one read 
        IF wa_pit_pointer-cdobjcl  NE wa_point_exc-cdobjcl OR
            wa_pit_pointer-tabname NE wa_point_exc-tabname OR
            wa_pit_pointer-fldnamem NE wa_point_exc-fldname.
             EXIT.
        ENDIF.



*      for each key, search for all entries with same value in   
*      cdobjid 

       READ TABLE lt_pit_pointer_sort_mat WITH KEY
       cdobjid = wa_pit_pointer-cdobjid
       BINARY SEARCH
       TRANSPORTING NO FIELDS.

       IF sy-subrc = 0.
          l_tabix2 = sy-tabix.

          LOOP AT lt_pit_pointer_sort_mat INTO   wa_pit_pointer_sort FROM l_tabix2.



*            Leave the loop, if last relevant entry one read 
             IF wa_pit_pointer_sort-cdobjid  NE wa_pit_pointer-cdobjid.
                     EXIT.
             ENDIF.


*          some logic here ... 
         ENDLOOP.
     ENDIF. 
  ENDLOOP.
ENDIF.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Aug 2008 11:13:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-table-with-2-different-keys-needed/m-p/4337135#M1033161</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-22T11:13:07Z</dc:date>
    </item>
  </channel>
</rss>

