<?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>Question Re: why left join is not working in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655318#M4823783</link>
    <description>I recommend not saying "is not working", but instead explain your input data, what result you get and what you expect.</description>
    <pubDate>Tue, 02 Apr 2024 07:18:46 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2024-04-02T07:18:46Z</dc:date>
    <item>
      <title>why left join is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaq-p/13655314</link>
      <description>&lt;P&gt;Hello, can you tell me why in the following select the LEFT join is working as INNER join.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;SELECT FROM @it_selected_data AS selected
      LEFT JOIN zkrh_scmt_invh AS invh
        ON invh~ebeln = selected~ebeln
    FIELDS selected~*, invh~invkind
    WHERE invh~invkind = ( SELECT MAX( invkind ) FROM zkrh_scmt_invh 
                                               WHERE ebeln = invh~ebeln ) 
    INTO CORRESPONDING FIELDS OF TABLE @it_final_data.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;Elias&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 07:33:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaq-p/13655314</guid>
      <dc:creator>ekekakos</dc:creator>
      <dc:date>2024-04-02T07:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: why left join is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655318#M4823783</link>
      <description>I recommend not saying "is not working", but instead explain your input data, what result you get and what you expect.</description>
      <pubDate>Tue, 02 Apr 2024 07:18:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655318#M4823783</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2024-04-02T07:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: why left join is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655333#M4823787</link>
      <description>Sorry my mistake. It is working as INNER JOIN and not as LEFT.</description>
      <pubDate>Tue, 02 Apr 2024 07:32:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655333#M4823787</guid>
      <dc:creator>ekekakos</dc:creator>
      <dc:date>2024-04-02T07:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: why left join is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655495#M4823797</link>
      <description>&lt;P&gt;I searched more deeply in the internet and I found the reason in this answer&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A title="LEFT JOIN restrictions" href="https://community.sap.com/t5/application-development-discussions/left-join-restrictions-that-opensql-poses-discussion/m-p/1104790" target="_self"&gt;https://community.sap.com/t5/application-development-discussions/left-join-restrictions-that-opensql-poses-discussion/m-p/1104790&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I changed the select using CTE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;WITH
    +invkind AS ( SELECT ebeln, MAX( invkind ) AS invkind FROM zkrh_scmt_invh GROUP BY ebeln )
    SELECT FROM @it_selected_data AS selected
      LEFT JOIN +invkind AS invh
        ON invh~ebeln = selected~ebeln
      LEFT JOIN dd07t
        ON invh~invkind = dd07t~domvalue_l AND
           dd07t~domname = 'ZKRH_SCMD_MMKIND' AND
           dd07t~ddlanguage = -langu
    FIELDS selected~*, concat_with_space( invh~invkind, dd07t~ddtext, 2 ) AS invkind
    INTO CORRESPONDING FIELDS OF TABLE @it_final_data.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Elias&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 08:57:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655495#M4823797</guid>
      <dc:creator>ekekakos</dc:creator>
      <dc:date>2024-04-02T08:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: why left join is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655500#M4823798</link>
      <description>&lt;P&gt;It's because you are doing a WHERE on a column of the left join table.&lt;/P&gt;&lt;P&gt;If there's no line in the left join table, its columns will be considered as NULL value, so it will fail on the WHERE.&lt;/P&gt;&lt;P&gt;You should indicate it in the ON condition.&lt;/P&gt;&lt;P&gt;EDIT: but it's not accepted (ABAP 7.58) to have a complex function in the ON part (= ( SELECT ... )), so in your case you can keep it in the WHERE part and indicate OR IS NULL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;SELECT FROM @it_selected_data AS selected
      LEFT JOIN zkrh_scmt_invh AS invh
        ON invh~ebeln = selected~ebeln 
    FIELDS selected~*, invh~invkind
    WHERE ( invh~invkind IS NULL
         OR invh~invkind = ( SELECT MAX( invkind ) 
                             FROM zkrh_scmt_invh 
                             WHERE ebeln = invh~ebeln ) )
    INTO CORRESPONDING FIELDS OF TABLE @it_final_data.&lt;/LI-CODE&gt;&lt;P&gt;Test reproducible by anyone:&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;TYPES tt_land1 TYPE STANDARD TABLE OF t005-land1 WITH EMPTY KEY.
TYPES: BEGIN OF ts_country_code_and_name,
         land1 TYPE t005t-land1,
         landx TYPE t005t-landx,
       END OF ts_country_code_and_name.
TYPES tt_country_codes_and_names TYPE STANDARD TABLE OF ts_country_code_and_name WITH EMPTY KEY.

DATA(countries) = VALUE tt_land1( ( 'DE' ) ( 'ZY' ) ).
DATA(country_codes_and_names) = VALUE tt_country_codes_and_names( ).
SELECT
    FROM @countries AS countries
    LEFT JOIN t005t
     ON t005t~land1 = countries~table_line
    AND t005t~spras = 'E'
    FIELDS countries~table_line AS land1, t005t~landx
    WHERE ( t005t~LAND1 IS NULL
         OR t005t~LAND1 IN ( SELECT land1 from t005 WHERE land1 LIKE 'D%' ) )
    INTO TABLE @country_codes_and_names.
ASSERT country_codes_and_names = VALUE tt_country_codes_and_names(
    ( land1 = 'DE' landx = 'Germany' )
    ( land1 = 'ZY' landx = '' ) ).&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 09:04:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655500#M4823798</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2024-04-02T09:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: why left join is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655504#M4823800</link>
      <description>See my answer, it's more simple.</description>
      <pubDate>Tue, 02 Apr 2024 08:54:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655504#M4823800</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2024-04-02T08:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: why left join is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655528#M4823802</link>
      <description>Which answer Sandra?</description>
      <pubDate>Tue, 02 Apr 2024 09:07:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655528#M4823802</guid>
      <dc:creator>ekekakos</dc:creator>
      <dc:date>2024-04-02T09:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: why left join is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655535#M4823804</link>
      <description>&lt;P&gt;This one:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sandra_Rossi_0-1712049036609.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/89635iCB72ACCA8770231B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sandra_Rossi_0-1712049036609.png" alt="Sandra_Rossi_0-1712049036609.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 09:10:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655535#M4823804</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2024-04-02T09:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: why left join is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655540#M4823805</link>
      <description>Thanks Sandra. And I did it but without parenthesis and instead of IS NULL I put = '' but mine of course did not work.</description>
      <pubDate>Tue, 02 Apr 2024 09:13:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/why-left-join-is-not-working/qaa-p/13655540#M4823805</guid>
      <dc:creator>ekekakos</dc:creator>
      <dc:date>2024-04-02T09:13:24Z</dc:date>
    </item>
  </channel>
</rss>

