<?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: Weird SQL behavior (complex JOIN, VBAK+VBPA) in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565494#M2008039</link>
    <description>&lt;P&gt;Didn't knew about the ON thing. I'll give a try. Thank you very much,  &lt;SPAN class="mention-scrubbed"&gt;sandra.rossi&lt;/SPAN&gt; &lt;/P&gt;</description>
    <pubDate>Tue, 24 May 2022 12:07:43 GMT</pubDate>
    <dc:creator>VXLozano</dc:creator>
    <dc:date>2022-05-24T12:07:43Z</dc:date>
    <item>
      <title>Weird SQL behavior (complex JOIN, VBAK+VBPA)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565491#M2008036</link>
      <description>&lt;P&gt;I have a "complex" SQL. Something like this:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;    select vbak~vbeln as numpedido, vbak~auart as tipo, vbak~erdat as creado, vbak~ernam as creadopor,
           sum( pmco~wrt01 + pmco~wrt02 + pmco~wrt03 + pmco~wrt04 + pmco~wrt05 + pmco~wrt06 + pmco~wrt07
              + pmco~wrt08 + pmco~wrt09 + pmco~wrt10 + pmco~wrt11 + pmco~wrt12 ) as costes,
           vbak~waerk as moneda, pa0001~ename as vendedor, but000~mc_name1 as cliente,
           vbak~uvfak as statusfac
      from vbak
                left join vbpa on vbak~vbeln = vbpa~vbeln
                left join caufv on vbak~vbeln = caufv~kdauf
                left join pmco on caufv~objnr = pmco~objnr
                left join pa0001 on vbpa~pernr = pa0001~pernr
                left join but000 on vbak~kunnr = but000~partner
      where vbak~vbeln in @rpedidos
        and vbak~auart in @rangotipos
        and vbak~vkbur in @roficinas
        and vbak~erdat between @sqldesde and @sqlhasta
        and vbak~vkbur in @roficinas
        and caufv~autyp = '30'
        and pmco~wrttp = '04'
        and pmco~acpos &amp;lt;&amp;gt; 'ZDESP'
        and vbpa~parvw = 'Z1' "vendedor
        and vbpa~pernr in @rangovendedores
      group by vbak~vbeln, vbak~auart, vbak~erdat, vbak~ernam, vbak~waerk, pa0001~ename,
               but000~mc_name1,
               vbak~uvfak
      into corresponding fields of table @pedidos
      bypassing buffer.
&lt;/CODE&gt;&lt;/PRE&gt; (the "bypassing buffer" was my last chance option) 
  &lt;BR /&gt; 
  &lt;BR /&gt;I have some documents that do NOT appear in the result. All of a concrete type (AUART). I checked the tables, and they have rows that fulfill the JOIN (even if they don't, those docs are in VBAK, and therefore, they should appear in the query result). 
  &lt;BR /&gt; 
  &lt;BR /&gt;What did I do? 
  &lt;BR /&gt;
  &lt;P&gt;I left just the vbak~vbeln begun to remove the JOIN tables one by one until those docs appeared. The guilty table was VBPA.For some reason, I decided to add the VBPA table and try again, and it worked*&lt;/P&gt;
  &lt;P&gt;"Nice", I thought, I quit the program and executed it again from scratch. BOOOO!! No more docs.&lt;/P&gt;
  &lt;P&gt;This behavior repeats each time, and it's independent of the order of the tables removed. Once I remove the VBAP, the query works each time, even when I add the VBAP table. Then I execute a second time, and the docs are missing again.&lt;/P&gt;
  &lt;P&gt;Any idea?&lt;/P&gt;
  &lt;P&gt;While I wait for some kind help, I will try to search again, it occurs (zero) to me that maybe one of those tables is one of the "new" ones (I'm in S/4 Hana) and it doesn't like JOINs.&lt;/P&gt;
  &lt;P&gt;Thanks in advance, even if you just had the patience to read 'til the end.&lt;/P&gt;
  &lt;P&gt;&lt;EM&gt;Edit: SE11 says those tables are "normal" ones, so no cookies for me.&lt;/EM&gt;&lt;/P&gt;
  &lt;P&gt;* (it's because that that I added the bypassing buffer thing).&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2022 08:20:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565491#M2008036</guid>
      <dc:creator>VXLozano</dc:creator>
      <dc:date>2022-05-24T08:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: Weird SQL behavior (complex JOIN, VBAK+VBPA)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565492#M2008037</link>
      <description>&lt;P&gt;I'm an idiot (and not just a tuly one) and my key users forget to tell me some "non-critical" information. The missing documents have a workflow that makes them to NOT fill the CAUFV-KDAUF field, but the VBAK-AUFNR one.&lt;/P&gt;&lt;P&gt;So, the JOIN will return no data for those documents.&lt;/P&gt;&lt;P&gt;The weird thing is SAP ignoring the OUTER part of the join. It's supposed "left outer" gives you a row for the left side of the join even if there's no info in the right one.&lt;/P&gt;&lt;P&gt;Or am I wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2022 11:02:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565492#M2008037</guid>
      <dc:creator>VXLozano</dc:creator>
      <dc:date>2022-05-24T11:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: Weird SQL behavior (complex JOIN, VBAK+VBPA)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565493#M2008038</link>
      <description>&lt;P&gt;You need to move your table selections from the WHERE to the ON. It's required because your joins are OUTER joins, otherwise that won't work if at least one table has no record (only IS NULL would be a successful condition).&lt;/P&gt;&lt;P&gt;PS: remember that functionally speaking, the WHERE is applied after the selection is done.&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2022 11:12:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565493#M2008038</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-05-24T11:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Weird SQL behavior (complex JOIN, VBAK+VBPA)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565494#M2008039</link>
      <description>&lt;P&gt;Didn't knew about the ON thing. I'll give a try. Thank you very much,  &lt;SPAN class="mention-scrubbed"&gt;sandra.rossi&lt;/SPAN&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2022 12:07:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565494#M2008039</guid>
      <dc:creator>VXLozano</dc:creator>
      <dc:date>2022-05-24T12:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Weird SQL behavior (complex JOIN, VBAK+VBPA)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565495#M2008040</link>
      <description>&lt;P&gt;Can you please convert your comment to an answer? So I can mark this idiotic question as answered (because it solves my problem) and prevent other people to come here to waste their time.&lt;BR /&gt;Thank you again.&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2022 12:08:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565495#M2008040</guid>
      <dc:creator>VXLozano</dc:creator>
      <dc:date>2022-05-24T12:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: Weird SQL behavior (complex JOIN, VBAK+VBPA)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565496#M2008041</link>
      <description>&lt;P&gt;It didn't work... I've got a flu, and I cannot think clearly. I am splitting the JOINs in SELECTs and will LOOP them.&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2022 12:55:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565496#M2008041</guid>
      <dc:creator>VXLozano</dc:creator>
      <dc:date>2022-05-24T12:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Weird SQL behavior (complex JOIN, VBAK+VBPA)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565497#M2008042</link>
      <description>&lt;P&gt;You need to move your table selections from the WHERE to the ON. It's required because your joins are OUTER joins, otherwise that won't work if at least one table has no record (only IS NULL would be a successful condition).&lt;/P&gt;&lt;P&gt;PS: remember that functionally speaking, the WHERE is applied after the selection is done.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;    select vbak~vbeln as numpedido, vbak~auart as tipo, vbak~erdat as creado, vbak~ernam as creadopor,
           sum( pmco~wrt01 + pmco~wrt02 + pmco~wrt03 + pmco~wrt04 + pmco~wrt05 + pmco~wrt06 + pmco~wrt07
              + pmco~wrt08 + pmco~wrt09 + pmco~wrt10 + pmco~wrt11 + pmco~wrt12 ) as costes,
           vbak~waerk as moneda, pa0001~ename as vendedor, but000~mc_name1 as cliente,
           vbak~uvfak as statusfac
      from vbak
                left join vbpa on vbak~vbeln = vbpa~vbeln
                              and vbpa~parvw = 'Z1' "vendedor
                              and vbpa~pernr in @rangovendedores
                left join caufv on vbak~vbeln = caufv~kdauf
                              and caufv~autyp = '30'
                left join pmco on caufv~objnr = pmco~objnr
                              and pmco~wrttp = '04'
                              and pmco~acpos &amp;lt;&amp;gt; 'ZDESP'
                left join pa0001 on vbpa~pernr = pa0001~pernr
                left join but000 on vbak~kunnr = but000~partner
      where vbak~vbeln in @rpedidos
        and vbak~auart in @rangotipos
        and vbak~vkbur in @roficinas
        and vbak~erdat between @sqldesde and @sqlhasta
        and vbak~vkbur in @roficinas
      group by vbak~vbeln, vbak~auart, vbak~erdat, vbak~ernam, vbak~waerk, pa0001~ename,
               but000~mc_name1, vbak~uvfak
      into corresponding fields of table @pedidos.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 May 2022 13:02:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/weird-sql-behavior-complex-join-vbak-vbpa/m-p/12565497#M2008042</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-05-24T13:02:20Z</dc:date>
    </item>
  </channel>
</rss>

