<?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 Re: read/ loop through a dynamic internal table with a dynamic where clause in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159838#M751707</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi anil,&lt;/P&gt;&lt;P&gt;what u can do is loop at table B and then read tbale A. because if u loop at table A, then probably tbale has more rows than tbale B,and it take longer time. Do this way....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Remember always keep the less records loop outside....may be this will ease the peformance&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT B INTO WA_B&lt;/P&gt;&lt;P&gt;   READ TABLE A WITH KEY FIELDA = WA_B-FIELDA&lt;/P&gt;&lt;P&gt;                                            FIELDB = WA_B-FIELDB&lt;/P&gt;&lt;P&gt;                        INTO WA_A.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can in KEY use which fields you want to compare.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CASE 2:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if u are using loop then better use it in this way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT ITAB_A INTO WA_A.&lt;/P&gt;&lt;P&gt;     LOOP AT ITAB_B INTO WA_B WHERE WA_B-FIELDA EQ WA_A-FIELDA.....&lt;/P&gt;&lt;P&gt;        -&lt;/P&gt;&lt;HR originaltext="-----" /&gt;&lt;P&gt;        -&lt;/P&gt;&lt;HR originaltext="------" /&gt;&lt;P&gt;     ENDLOOP.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To be still more precise, sort the internal table on which you are performing a read statement, and then while using read table stmt, use it thru binary search. this will enhance ur performance..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward if useful......these are the 2 option u can go with...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Sabah...&lt;/P&gt;&lt;P&gt;        Sabahuddin Ahmed&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 14 Dec 2007 14:22:27 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-12-14T14:22:27Z</dc:date>
    <item>
      <title>read/ loop through a dynamic internal table with a dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159837#M751706</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All, &lt;/P&gt;&lt;P&gt;         We have a situation where we have two internal tables of similar type ( the tables are of dynamic type but we are at the part of the code where it is guaranteed that both the tables are of similar type ) . The table "A" contains the master details and table B contains partial details. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;eg) Lets say table A has the following fields and data &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FieldA    FieldB    FieldC   FieldD   FieldE &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A1          B1          C1          D1          E1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A2          B2          C2           D2          E2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A3          B3           C3          D3          E3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A1         B2           C3           D4           E4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And table "B"  has the following data ( fields are similar to table A )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FieldA    FieldB    FieldC   FieldD   FieldE &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A1          &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;                            C3 &lt;/P&gt;&lt;P&gt;A2          B3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each row of Table B acts as a "where clause" for the master table A. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The information required is the records of table A which satisfy the "condition" in each row of table B. Which would be the best way to approach it keeping the performance issue in mind ? In other words how to build a dynamic where clause to loop through Table A with the info available from Table B ? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;Anil &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A2          B3&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Dec 2007 12:27:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159837#M751706</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-14T12:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: read/ loop through a dynamic internal table with a dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159838#M751707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi anil,&lt;/P&gt;&lt;P&gt;what u can do is loop at table B and then read tbale A. because if u loop at table A, then probably tbale has more rows than tbale B,and it take longer time. Do this way....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Remember always keep the less records loop outside....may be this will ease the peformance&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT B INTO WA_B&lt;/P&gt;&lt;P&gt;   READ TABLE A WITH KEY FIELDA = WA_B-FIELDA&lt;/P&gt;&lt;P&gt;                                            FIELDB = WA_B-FIELDB&lt;/P&gt;&lt;P&gt;                        INTO WA_A.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can in KEY use which fields you want to compare.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CASE 2:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if u are using loop then better use it in this way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT ITAB_A INTO WA_A.&lt;/P&gt;&lt;P&gt;     LOOP AT ITAB_B INTO WA_B WHERE WA_B-FIELDA EQ WA_A-FIELDA.....&lt;/P&gt;&lt;P&gt;        -&lt;/P&gt;&lt;HR originaltext="-----" /&gt;&lt;P&gt;        -&lt;/P&gt;&lt;HR originaltext="------" /&gt;&lt;P&gt;     ENDLOOP.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To be still more precise, sort the internal table on which you are performing a read statement, and then while using read table stmt, use it thru binary search. this will enhance ur performance..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward if useful......these are the 2 option u can go with...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Sabah...&lt;/P&gt;&lt;P&gt;        Sabahuddin Ahmed&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Dec 2007 14:22:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159838#M751707</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-14T14:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: read/ loop through a dynamic internal table with a dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159839#M751708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sabahuddin,&lt;/P&gt;&lt;P&gt;                       I am working with Anil on the same issue.  I am afraid the obvious solution suggested by you wont work because we have no idea about the "key" fields here. Remember they are dynamic and from what I can gather from the net there is no provision to dynamically build that where clause . ( the column field can be dynamic but that doesn't help here as the number of columns required is variable too ) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Dec 2007 14:53:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159839#M751708</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-14T14:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: read/ loop through a dynamic internal table with a dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159840#M751709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So, you want sort of LOOP AT A WHERE fields match B.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sort table B by the comparison fields.  Find the first matching field in B, using the dynamic version of READ ... TRANSPORTING NO FIELDS.  Store the sy-tabix of the found record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT B FROM INDEX index.
  IF (fields don't match anymore).
    EXIT.
  ENDIF.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Dec 2007 15:28:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159840#M751709</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2007-12-14T15:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: read/ loop through a dynamic internal table with a dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159841#M751710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Matthew,&lt;/P&gt;&lt;P&gt;                 Thanks for the response but am afraid it doesnt solve the problem. The nub of the issue is both the fields and the number of fields is dynamic here!! Which means have no idea about the comparison fields or even the number of them &lt;SPAN __jive_emoticon_name="plain"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried using the following statement : &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab_B into wa_B .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read table itab_A from wa_B into wa_a1 . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;..if sy-subrc eq 0 do some processing &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endloop. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the above the structure "wa_B" contained values for some fields and the itab_A did contain records with the same data in wa_B in the some fields. I was under the impression that this statement would give the record which satisfies the condn in wa_B but that didnt happen . Am I missing something? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Dec 2007 15:44:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159841#M751710</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-14T15:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: read/ loop through a dynamic internal table with a dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159842#M751711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you can get the names of the fields of the structures from RTTS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;( Or you could use the Internal Use only part of DESCRIBE ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Dec 2007 15:52:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159842#M751711</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2007-12-14T15:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: read/ loop through a dynamic internal table with a dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159843#M751712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes we can get the fields alright but how does that help here? Can you please explain your approach in more detail? guess I must have missed something..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Dec 2007 16:05:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159843#M751712</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-14T16:05:43Z</dc:date>
    </item>
    <item>
      <title>Re: read/ loop through a dynamic internal table with a dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159844#M751713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, now you've got the name of the fields to use in the read, the remaining problem is that the number might be different.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can determine whether to use a field of the B table presumably by checking if it has a value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, once you know which fields in B have a value and their name, I think you have do something like.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CASE field_count.
  WHEN 1.
    READ TABLE A TRANSPORTING NO FIELDS WITH KEY (fld1) = &amp;lt;b_val_1&amp;gt;.
  WHEN 2.
    READ TABLE A TRANSPORTING NO FIELDS WITH KEY (fld1) = &amp;lt;b_val_1&amp;gt; (fld2) = &amp;lt;b_val_2&amp;gt;.
...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not pretty, I'll admit.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Totally off the wall - but how about writing both datasets to transparent tables, and then using dynamic WHERE?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Dec 2007 16:21:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-loop-through-a-dynamic-internal-table-with-a-dynamic-where-clause/m-p/3159844#M751713</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2007-12-14T16:21:52Z</dc:date>
    </item>
  </channel>
</rss>

