<?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: SELECT query based on two internal tables. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513275#M2004224</link>
    <description>&lt;P&gt;pretty sure there is a cds view on these tables, did you check this option ? &lt;/P&gt;</description>
    <pubDate>Tue, 12 Oct 2021 05:41:40 GMT</pubDate>
    <dc:creator>FredericGirod</dc:creator>
    <dc:date>2021-10-12T05:41:40Z</dc:date>
    <item>
      <title>SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513271#M2004220</link>
      <description>&lt;P&gt;Hello Folks,&lt;BR /&gt;&lt;BR /&gt;I am facing an issue due to which I need to make an improvisation on the below SELECT statement:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;SELECT objectclas objectid changenr tabname tabkey
             fname chngind value_new value_old
             FROM cdpos INTO TABLE lt_changelogs
             FOR ALL ENTRIES IN lt_chglog_rules
             WHERE objectclas = lt_chglog_rules-objectclas
               AND changenr   IN lt_r_changenr
               AND tabname    = lt_chglog_rules-tabname
               AND fname      = lt_chglog_rules-fname
               AND value_new  = lt_chglog_rules-newval
               AND value_old  = lt_chglog_rules-oldval.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;The above query works perfectly fine when the number of entries in the range table &lt;STRONG&gt;lt_r_changenr &lt;/STRONG&gt;is less. &lt;/P&gt;
  &lt;P&gt;Off late we are noticing more than 200,000 records in this range table which ends up in the dump attached&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1983852-dump.png" /&gt;&lt;/P&gt;
  &lt;P&gt;On researching the above dump, the most common solution available is to use FOR ALL ENTRIES statement on the range table instead of the IN operator but it is already used for another internal table in the query.&lt;/P&gt;
  &lt;P&gt;Also we are avoiding using SLEECT statement inside a LOOP due to performance issues and bad coding practices.&lt;/P&gt;
  &lt;P&gt;Any improvisation suggestions would be appreciated that could help mitigate this issue.&lt;/P&gt;
  &lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 04:48:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513271#M2004220</guid>
      <dc:creator>aminpranal</dc:creator>
      <dc:date>2021-10-12T04:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513272#M2004221</link>
      <description>&lt;P&gt;if changelog number comes from CDHDR why didn't you make an INNER JOIN instead of a ranges ? &lt;/P&gt;&lt;P&gt;second option, I have created several time a method that convert ranges to reduce the size : &lt;/P&gt;&lt;P&gt;instead of I EQ  1 ... 2 ... 3... 4 ... 6   it gives you I BT 1 4   I EQ 6 ...   sometimes it works also&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 04:59:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513272#M2004221</guid>
      <dc:creator>FredericGirod</dc:creator>
      <dc:date>2021-10-12T04:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513273#M2004222</link>
      <description>&lt;P&gt;  &lt;SPAN class="mention-scrubbed"&gt;frdric.girod&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;The second option sounds better as we are trying to do minimal changes as this report runs as a job and has dependencies associated.&lt;BR /&gt;Do we have any FM or method that can help to convert the ranges to minimize the size?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 05:13:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513273#M2004222</guid>
      <dc:creator>aminpranal</dc:creator>
      <dc:date>2021-10-12T05:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513274#M2004223</link>
      <description>&lt;P&gt;If you don't want to take any risk, you may also split lt_chglog_rules into smaller groups of lines and repeat the SELECT for each group, append lines, and after the loop do a "sort" and "delete adjacent duplicates" so that to mimic the DISTINCT behavior of FOR ALL ENTRIES.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 05:33:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513274#M2004223</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2021-10-12T05:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513275#M2004224</link>
      <description>&lt;P&gt;pretty sure there is a cds view on these tables, did you check this option ? &lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 05:41:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513275#M2004224</guid>
      <dc:creator>FredericGirod</dc:creator>
      <dc:date>2021-10-12T05:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513276#M2004225</link>
      <description>&lt;P&gt; &lt;SPAN class="mention-scrubbed"&gt;frdric.girod&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;This a legacy system where the code is present and not a HANA system, so CDS views are not there.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 05:49:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513276#M2004225</guid>
      <dc:creator>aminpranal</dc:creator>
      <dc:date>2021-10-12T05:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513277#M2004226</link>
      <description>&lt;P&gt;Hi Pranal,&lt;/P&gt;&lt;P&gt;instead of using the internal table lt_chglog_rules, you should consider to join the tables.&lt;BR /&gt;In newer released (7.5.x) you can select also directly from the internal table.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;select distinct a~*
from cdpos as a
inner join @lt_chglog_rules as b 
  on b~objectclas = a~objectclas&lt;BR /&gt; AND b~tabname    = a-tabname
 AND b~fname      = a-fname
 AND b~value_new  = a-newval
 AND b~value_old  = a-oldval
where a~changenr   IN lt_r_changenr
into table @data(lt_data)
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Oct 2021 06:10:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513277#M2004226</guid>
      <dc:creator>ThorstenHoefer</dc:creator>
      <dc:date>2021-10-12T06:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513278#M2004227</link>
      <description>&lt;P&gt;   &lt;SPAN class="mention-scrubbed"&gt;thorstenhoefer&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;Thanks for your valuable suggestion.&lt;BR /&gt;In my case th range table &lt;STRONG&gt;lt_r_changenr &lt;/STRONG&gt;has close to 200,000 records which leads to the RSQL dump mentioned. &lt;BR /&gt;Will this SELECT query suggested by you take care of the dump then?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 06:17:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513278#M2004227</guid>
      <dc:creator>aminpranal</dc:creator>
      <dc:date>2021-10-12T06:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513279#M2004228</link>
      <description>&lt;P&gt;Hi &lt;SPAN class="mention-scrubbed"&gt;aminpranal&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;select for all entries generate a large sql string which is executed on the datbase.&lt;/P&gt;&lt;P&gt;This can be avoid by joining two tables.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 06:29:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513279#M2004228</guid>
      <dc:creator>ThorstenHoefer</dc:creator>
      <dc:date>2021-10-12T06:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513280#M2004229</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Range tables are usually designed for a smaller input set. If I recall correctly it should be in range of 1000 or something. If the the entries are more you would get the dump as mentioned in your question. I would suggest to use FOR ALL ENTRIES IN instead.&lt;/P&gt;&lt;P&gt;for your Query where you are using &lt;STRONG&gt;lt_r_changenr&lt;/STRONG&gt; there if possible create a separate table with two fields, object class and change no. then use it in for all entries in. &lt;BR /&gt;Also another suggestion would be to check your query once, I think you might also have a performance impact.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Juby&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 06:31:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513280#M2004229</guid>
      <dc:creator>former_member598787</dc:creator>
      <dc:date>2021-10-12T06:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513281#M2004230</link>
      <description>&lt;P&gt;Why did everybody do a :  CDPOS as A    ?? &lt;/P&gt;&lt;P&gt;This is human speaking A ? Do you understand what it means A without the CDPOS ?   &lt;/P&gt;&lt;P&gt;Why didn't you write :  CDPOS as Change_Item ?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 06:36:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513281#M2004230</guid>
      <dc:creator>FredericGirod</dc:creator>
      <dc:date>2021-10-12T06:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513282#M2004231</link>
      <description>&lt;P&gt;"as a" is only an alias. If you select from an internal table  @lt_chglog, you need to use an alias.&lt;/P&gt;&lt;P&gt;You can use anything else as an alias, or you can remove the alias for table cdpos.&lt;/P&gt;&lt;P&gt;It doesn't matter.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 06:46:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513282#M2004231</guid>
      <dc:creator>ThorstenHoefer</dc:creator>
      <dc:date>2021-10-12T06:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513283#M2004232</link>
      <description>&lt;P&gt;CDS views and HANA are distinct, independent technologies. I'm using a system right now that's not HANA but has CDS views.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 07:06:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513283#M2004232</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2021-10-12T07:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513284#M2004233</link>
      <description>&lt;P&gt; &lt;SPAN class="mention-scrubbed"&gt;thorstenhoefer&lt;/SPAN&gt;  &lt;SPAN class="mention-scrubbed"&gt;frdric.girod&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;The netweaver version for the system is 7.0.&lt;BR /&gt;So I think the SELECT ...JOIN on internal table will not be supported.&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Do we have an alternative here?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 07:43:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513284#M2004233</guid>
      <dc:creator>aminpranal</dc:creator>
      <dc:date>2021-10-12T07:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513285#M2004234</link>
      <description>&lt;P&gt;inner join works in sap R/3 4.5  sure, and certainly before&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 08:10:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513285#M2004234</guid>
      <dc:creator>FredericGirod</dc:creator>
      <dc:date>2021-10-12T08:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513286#M2004235</link>
      <description>&lt;P&gt;inner joins works of course also before, but the new feature is to select from the internal table @lt_chglog_rules.&lt;/P&gt;&lt;P&gt;If you can join the original table of the source from lt_chglog_rules you will be fine.&lt;/P&gt;&lt;P&gt;How do you fill the internal table lt_chglog_rules?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 09:45:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513286#M2004235</guid>
      <dc:creator>ThorstenHoefer</dc:creator>
      <dc:date>2021-10-12T09:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT query based on two internal tables.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513287#M2004236</link>
      <description>&lt;P&gt; &lt;SPAN class="mention-scrubbed"&gt;thorstenhoefer&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;lt_chglog_rules &lt;/STRONG&gt;gets filed from rules defined in BRF+.&lt;/P&gt;&lt;P&gt;We are coming up with something like below to solve the dump issue.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT lt_changenr INTO lwa_changenr.
    LOOP AT lt_chglog_rules INTO lwa_chglog_rules.
      MOVE-CORRESPONDING lwa_chglog_rules TO lwa_chglog_rules_chgnr.
      lwa_chglog_rules_chgnr-changenr = lwa_changenr-changenr.
      APPEND lwa_chglog_rules_chgnr TO lt_chglog_rules_chgnr.
      clear lwa_chglog_rules_chgnr, lwa_chglog_rules.
    ENDLOOP.
    clear lwa_changenr.
  ENDLOOP.


* and then the select query on this new internal table having same structure as lt_chglog_rules with an 
* additional field changenr
* Now the SELECT query changes by eliminating the RANGE table
SELECT objectclas objectid changenr tabname tabkey
       fname chngind value_new value_old
       FROM cdpos INTO TABLE lt_changelogs
       FOR ALL ENTRIES IN lt_chglog_rules_chgnr
       WHERE objectclas = lt_chglog_rules_chgnr-objectclas
       AND changenr    = lt_chglog_rules_chgnr-changenr
       AND tabname    = lt_chglog_rules_chgnr-tabname
       AND fname      = lt_chglog_rules_chgnr-fname
       AND value_new  = lt_chglog_rules_chgnr-newval
       AND value_old  = lt_chglog_rules_chgnr-oldval.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This will eliminate the need for the RANGE table and prevent the RSQL dump.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 11:10:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-based-on-two-internal-tables/m-p/12513287#M2004236</guid>
      <dc:creator>aminpranal</dc:creator>
      <dc:date>2021-10-12T11:10:37Z</dc:date>
    </item>
  </channel>
</rss>

