<?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: JOIN optimize PROJ - AFRU in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-optimize-proj-afru/m-p/5967516#M1338715</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This message was moderated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 27 Aug 2009 14:36:53 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-08-27T14:36:53Z</dc:date>
    <item>
      <title>JOIN optimize PROJ - AFRU</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-optimize-proj-afru/m-p/5967512#M1338711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Has anybody idea if it is possible to optimize this query? &lt;/P&gt;&lt;P&gt;I suppose that join should be the best, what I can get... but it is still very very slow. I need data from AFRU, AFVC, AFVV per project num (PROJ), so there are thousands of lines in result. Now I am able to get data only per one AUFNR(AFPO) - few minutes, per POSID(PRPS) or PSPID(PROJ) it falls down after 10 minutes.&lt;/P&gt;&lt;P&gt;Is it better to divide so difficult query or use another techniques? Or change order of tables in query?&lt;/P&gt;&lt;P&gt;Thanks for help  in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT proj&lt;SUB&gt;pspid prps&lt;/SUB&gt;posid afru&lt;SUB&gt;aufnr afpo&lt;/SUB&gt;matnr makt&lt;SUB&gt;maktx afpo&lt;/SUB&gt;aufnr&lt;/P&gt;&lt;P&gt;      afvc&lt;SUB&gt;vornr afvc&lt;/SUB&gt;ltxa1 afvv&lt;SUB&gt;mgvrg crhd&lt;/SUB&gt;arbpl crtx&lt;SUB&gt;ktext afvv&lt;/SUB&gt;vgw01&lt;/P&gt;&lt;P&gt;      afvv&lt;SUB&gt;vgw02 afru&lt;/SUB&gt;lmnga afru&lt;SUB&gt;ism01 afru&lt;/SUB&gt;ism02 afru&lt;SUB&gt;ersda afru&lt;/SUB&gt;ernam&lt;/P&gt;&lt;P&gt;      afru&lt;SUB&gt;pernr afru&lt;/SUB&gt;rueck afru&lt;SUB&gt;ile01 afvv&lt;/SUB&gt;vge01 afvv~meinh&lt;/P&gt;&lt;P&gt;    INTO CORRESPONDING FIELDS OF TABLE it_zppprodtime&lt;/P&gt;&lt;P&gt;    FROM afru&lt;/P&gt;&lt;P&gt;    INNER JOIN afpo&lt;/P&gt;&lt;P&gt;      ON afru&lt;SUB&gt;aufnr = afpo&lt;/SUB&gt;aufnr&lt;/P&gt;&lt;P&gt;    INNER JOIN prps&lt;/P&gt;&lt;P&gt;      ON afpo&lt;SUB&gt;projn = prps&lt;/SUB&gt;pspnr&lt;/P&gt;&lt;P&gt;    INNER JOIN proj&lt;/P&gt;&lt;P&gt;      ON prps&lt;SUB&gt;psphi = proj&lt;/SUB&gt;pspnr&lt;/P&gt;&lt;P&gt;    INNER JOIN crhd&lt;/P&gt;&lt;P&gt;      ON crhd&lt;SUB&gt;objid = afru&lt;/SUB&gt;arbid&lt;/P&gt;&lt;P&gt;    INNER JOIN afvc&lt;/P&gt;&lt;P&gt;      ON afvc&lt;SUB&gt;aufpl = afru&lt;/SUB&gt;aufpl&lt;/P&gt;&lt;P&gt;        AND afvc&lt;SUB&gt;aplzl = afru&lt;/SUB&gt;aplzl&lt;/P&gt;&lt;P&gt;    INNER JOIN afvv&lt;/P&gt;&lt;P&gt;      ON afvv&lt;SUB&gt;aufpl = afru&lt;/SUB&gt;aufpl&lt;/P&gt;&lt;P&gt;        AND afvv&lt;SUB&gt;aplzl = afru&lt;/SUB&gt;aplzl&lt;/P&gt;&lt;P&gt;    INNER JOIN makt&lt;/P&gt;&lt;P&gt;      ON makt&lt;SUB&gt;matnr = afpo&lt;/SUB&gt;matnr&lt;/P&gt;&lt;P&gt;    INNER JOIN crtx&lt;/P&gt;&lt;P&gt;      ON crtx&lt;SUB&gt;objid = crhd&lt;/SUB&gt;objid&lt;/P&gt;&lt;P&gt;    WHERE&lt;/P&gt;&lt;P&gt;      proj~pspid IN s_pspid&lt;/P&gt;&lt;P&gt;      AND prps~posid IN s_projn&lt;/P&gt;&lt;P&gt;      AND crhd~arbpl IN s_arbpl&lt;/P&gt;&lt;P&gt;      AND afru~aufnr IN s_aufnr&lt;/P&gt;&lt;P&gt;      AND makt~spras = 'CS'&lt;/P&gt;&lt;P&gt;      and crtx~spras = 'CS'.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2009 07:30:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/join-optimize-proj-afru/m-p/5967512#M1338711</guid>
      <dc:creator>former_member378419</dc:creator>
      <dc:date>2009-08-10T07:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: JOIN optimize PROJ - AFRU</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-optimize-proj-afru/m-p/5967513#M1338712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; Is it better to divide so difficult query or use another techniques? Or change order of tables in query?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;no, it should not be necessary to divide the query. The table order is (and normally should be) decided&lt;/P&gt;&lt;P&gt;by the optimizer based on the statistics.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What matters is the access to the individual tables. The AUFNR is probaly supported by an index (primary key of AFPO)&lt;/P&gt;&lt;P&gt;while the others are probably not supported.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For your most selective WHERE condition: check if there is an index support and if the optimzer chooses the index and the&lt;/P&gt;&lt;P&gt;table to be processed first.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need further help please post details from ST05 (execution plan, available indexes, statement like it is sent to the database (which variables are filled with what values), time per execution, how much records are returned, ...)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hermann&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2009 09:12:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/join-optimize-proj-afru/m-p/5967513#M1338712</guid>
      <dc:creator>HermannGahm</dc:creator>
      <dc:date>2009-08-10T09:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: JOIN optimize PROJ - AFRU</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-optimize-proj-afru/m-p/5967514#M1338713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Martin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had a few concerns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) In real life it is unlikely that that you will get users to make queries on all the orders. It appears more likely to me that users would enter a project number/s in the selection screen. Given that it makes more sense constructing your query to begin with project number rather than order number. I have taken the liberty of modifying the query to give you an example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) I noticed that your query reads table CRHD using field OBJID. The primary key is based on fields OBJTY and OBJID. If you know the OBJTY you can use it in the where clause. This will let you use the primary key. Remember CRHD is a huge table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3) You can use the OBJID from CRHD table to join table CRTX. (Look at the query below).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT proj~pspid
       prps~posid
       afru~aufnr
       afpo~matnr
       makt~maktx
       afpo~aufnr
       afvc~vornr
       afvc~ltxa1
       afvv~mgvrg
       crhd~arbpl
       crtx~ktext
       afvv~vgw01
       afvv~vgw02
       afru~lmnga
       afru~ism01
       afru~ism02
       afru~ersda
       afru~ernam
       afru~pernr
       afru~rueck
       afru~ile01
       afvv~vge01
       afvv~meinh
INTO CORRESPONDING FIELDS OF TABLE it_zppprodtime
FROM       proj
inner join prps
on  prps~psphi = proj~pspnr
inner join afpo
ON  afpo~projn = prps~pspnr
inner join afru
on  afru~aufnr = afpo~aufnr
INNER JOIN afvc
ON  afvc~aufpl  = afru~aufpl
AND afvc~aplzl = afru~aplzl
INNER JOIN afvv
ON  afvv~aufpl = afru~aufpl
AND afvv~aplzl = afru~aplzl
INNER JOIN makt
ON  makt~matnr = afpo~matnr
INNER JOIN crhd
ON  crhd~objid = afru~arbid
INNER JOIN crtx
ON  crtx~objTY = crhd~objty
AND crtx~objid = crhd~objid
WHERE proj~pspid IN s_pspid
AND   prps~posid IN s_projn
AND   crhd~arbpl IN s_arbpl
AND   afru~aufnr IN s_aufnr
AND   makt~spras = 'CS'
AND   crhd~objty = ????
AND   crtx~spras = 'CS'.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2009 15:18:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/join-optimize-proj-afru/m-p/5967514#M1338713</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-10T15:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: JOIN optimize PROJ - AFRU</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-optimize-proj-afru/m-p/5967515#M1338714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for answers. Finally I changed few things in program and surprisingly it works OK, now:-) &lt;/P&gt;&lt;P&gt;Worse is that I don't know what exactly made this program running so slow, but I didn't change query very much. I think it was something connected to sorting in ALV grid. I have switched off sorting in program at all.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Aug 2009 11:41:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/join-optimize-proj-afru/m-p/5967515#M1338714</guid>
      <dc:creator>former_member378419</dc:creator>
      <dc:date>2009-08-17T11:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: JOIN optimize PROJ - AFRU</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-optimize-proj-afru/m-p/5967516#M1338715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This message was moderated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Aug 2009 14:36:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/join-optimize-proj-afru/m-p/5967516#M1338715</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-27T14:36:53Z</dc:date>
    </item>
  </channel>
</rss>

