<?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 Select Statment Error (SQL) in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341505#M1230245</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Friends,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  LOOP AT IT_ZSD012_001 INTO WA_ZSD012_001.
    SELECT  A~MATNR A~LABST A~UMLME A~INSME A~EINME A~SPEME A~RETME B~MTART
      APPENDING TABLE IT_INVENTORY
      FROM  MARD AS A
      INNER JOIN MARA AS B ON B~MATNR EQ A~MATNR
      WHERE A~MATNR = '1.1.1'
      and   A~WERKS EQ  WA_ZSD012_001-PARAM_1
      AND   A~LGORT EQ  WA_ZSD012_001-VALUE
      AND   A~LABST GT 0
      OR    ( A~UMLME GT 0
      OR    A~INSME GT 0
      OR    A~EINME GT 0
      OR    A~SPEME GT 0
      OR    A~RETME GT 0 )
      AND   B~MTART IN ('ZFG1' , 'ZFG4' , 'ZR12' ).
  ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this is my code (select statement)&lt;/P&gt;&lt;P&gt;but this is not working, when i execute this so many materials came to the itab it should come only "1.1.1"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;my requirement is i want to get data from MARD agaist WERKS, LGORT and also MARA-MTART in that groups.&lt;/P&gt;&lt;P&gt;its came with zero inventory, i want to avid them how can i do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope you can understand what i an said? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advanced&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Mar 2009 03:37:20 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-03-11T03:37:20Z</dc:date>
    <item>
      <title>Select Statment Error (SQL)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341505#M1230245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Friends,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  LOOP AT IT_ZSD012_001 INTO WA_ZSD012_001.
    SELECT  A~MATNR A~LABST A~UMLME A~INSME A~EINME A~SPEME A~RETME B~MTART
      APPENDING TABLE IT_INVENTORY
      FROM  MARD AS A
      INNER JOIN MARA AS B ON B~MATNR EQ A~MATNR
      WHERE A~MATNR = '1.1.1'
      and   A~WERKS EQ  WA_ZSD012_001-PARAM_1
      AND   A~LGORT EQ  WA_ZSD012_001-VALUE
      AND   A~LABST GT 0
      OR    ( A~UMLME GT 0
      OR    A~INSME GT 0
      OR    A~EINME GT 0
      OR    A~SPEME GT 0
      OR    A~RETME GT 0 )
      AND   B~MTART IN ('ZFG1' , 'ZFG4' , 'ZR12' ).
  ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this is my code (select statement)&lt;/P&gt;&lt;P&gt;but this is not working, when i execute this so many materials came to the itab it should come only "1.1.1"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;my requirement is i want to get data from MARD agaist WERKS, LGORT and also MARA-MTART in that groups.&lt;/P&gt;&lt;P&gt;its came with zero inventory, i want to avid them how can i do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope you can understand what i an said? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advanced&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2009 03:37:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341505#M1230245</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-11T03:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: Select Statment Error (SQL)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341506#M1230246</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nelson, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, you can try to remove your select statement outside the loop since this will result in slow performance and just use FOR ALL ENTRIES. Check first the values you compare against in the tables if how many records are there or if there is none.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2009 03:44:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341506#M1230246</guid>
      <dc:creator>aris_hidalgo</dc:creator>
      <dc:date>2009-03-11T03:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Select Statment Error (SQL)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341507#M1230247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;when i execute this so many materials came to the itab it should come only "1.1.1"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You mean different material numbers are coming or same material 1.1.1 is coming number of times.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2009 03:44:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341507#M1230247</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-11T03:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Select Statment Error (SQL)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341508#M1230248</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;&lt;/P&gt;&lt;P&gt;There are 2 problems . &lt;/P&gt;&lt;P&gt;One is use for all entries . Second is that since ur using AND , OR in the same select it will consider &lt;/P&gt;&lt;P&gt;the conditions of AND and the conditions of OR .&lt;/P&gt;&lt;P&gt;Jus rephrase ur select as : &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT  A&lt;SUB&gt;MATNR A&lt;/SUB&gt;LABST A&lt;SUB&gt;UMLME A&lt;/SUB&gt;INSME A&lt;SUB&gt;EINME A&lt;/SUB&gt;SPEME A&lt;SUB&gt;RETME B&lt;/SUB&gt;MTART&lt;/P&gt;&lt;P&gt;      APPENDING TABLE IT_INVENTORY&lt;/P&gt;&lt;P&gt;      FROM  MARD AS A&lt;/P&gt;&lt;P&gt;      INNER JOIN MARA AS B ON B&lt;SUB&gt;MATNR EQ A&lt;/SUB&gt;MATNR&lt;/P&gt;&lt;P&gt;      WHERE A~MATNR = '1.1.1'&lt;/P&gt;&lt;P&gt;      and   A~WERKS EQ  WA_ZSD012_001-PARAM_1&lt;/P&gt;&lt;P&gt;      AND   A~LGORT EQ  WA_ZSD012_001-VALUE&lt;/P&gt;&lt;P&gt;      AND   ( A&lt;SUB&gt;LABST GT 0     OR    A&lt;/SUB&gt;UMLME GT 0   OR    A&lt;SUB&gt;INSME GT 0      OR    A&lt;/SUB&gt;EINME GT 0&lt;/P&gt;&lt;P&gt;      OR    A&lt;SUB&gt;SPEME GT 0      OR    A&lt;/SUB&gt;RETME GT 0 )      &lt;/P&gt;&lt;P&gt;      AND   B~MTART IN ('ZFG1' , 'ZFG4' , 'ZR12' ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should work !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2009 03:50:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341508#M1230248</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-11T03:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: Select Statment Error (SQL)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341509#M1230249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi nelson,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For performance issue never do a select statement into a loop. wat you can do is fill an internal table and then read internal table inside your loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For your problem try this alternative.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select mard&lt;SUB&gt;matnr mard&lt;/SUB&gt; ....... into table it_inventory &lt;/P&gt;&lt;P&gt;from mard &lt;/P&gt;&lt;P&gt;inner join mara on mara&lt;SUB&gt;matnr eq mard&lt;/SUB&gt;matnr&lt;/P&gt;&lt;P&gt;for all entries in it_2sd012&lt;/P&gt;&lt;P&gt;where (conditions).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this should solve your problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers&lt;/P&gt;&lt;P&gt;kevin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2009 04:26:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341509#M1230249</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-11T04:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: Select Statment Error (SQL)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341510#M1230250</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;Make this change,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; LOOP AT IT_ZSD012_001 INTO WA_ZSD012_001.&lt;/P&gt;&lt;P&gt;    SELECT  A&lt;SUB&gt;MATNR A&lt;/SUB&gt;LABST A&lt;SUB&gt;UMLME A&lt;/SUB&gt;INSME A&lt;SUB&gt;EINME A&lt;/SUB&gt;SPEME A&lt;SUB&gt;RETME B&lt;/SUB&gt;MTART&lt;/P&gt;&lt;P&gt;      APPENDING TABLE IT_INVENTORY&lt;/P&gt;&lt;P&gt;      FROM  MARD AS A&lt;/P&gt;&lt;P&gt;      INNER JOIN MARA AS B ON B&lt;SUB&gt;MATNR EQ A&lt;/SUB&gt;MATNR&lt;/P&gt;&lt;P&gt;      WHERE A~MATNR = '1.1.1'&lt;/P&gt;&lt;P&gt;      and   A~WERKS EQ  WA_ZSD012_001-PARAM_1&lt;/P&gt;&lt;P&gt;      AND   A~LGORT EQ  WA_ZSD012_001-VALUE&lt;/P&gt;&lt;P&gt;      AND   A~LABST GT 0&lt;/P&gt;&lt;P&gt;      AND    ( A~UMLME GT 0 -&lt;/P&gt;&lt;HR originaltext="-------------------" /&gt;&lt;P&gt;&amp;gt;change OR from AND&lt;/P&gt;&lt;P&gt;      OR    A~INSME GT 0&lt;/P&gt;&lt;P&gt;      OR    A~EINME GT 0&lt;/P&gt;&lt;P&gt;      OR    A~SPEME GT 0&lt;/P&gt;&lt;P&gt;      OR    A~RETME GT 0 )&lt;/P&gt;&lt;P&gt;      AND   B~MTART IN ('ZFG1' , 'ZFG4' , 'ZR12' ).&lt;/P&gt;&lt;P&gt;  ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;According to ur select query, OR conditions should be inside the  brackets (  ).&lt;/P&gt;&lt;P&gt;When u put OR condition outside of the bracket. if any one condition gets true, it'll fetch that record that's why u r getting multiple record. If u use AND, it'll fetch the record onlyif both the condition are true.&lt;/P&gt;&lt;P&gt;Just check the above select query.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2009 04:34:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341510#M1230250</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-11T04:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Select Statment Error (SQL)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341511#M1230251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nelson,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For better performance try to avoid using join statements. Use for all entries instead.&lt;/P&gt;&lt;P&gt;Never use select staments in Loops.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try your code following way&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;if it_zsd012_001 is not initial.
  
   select matnr labst umlme insme einme speme retme 
      from mard
      appending table it_inventory
      for all entries in it_asd012_001
      where matnr = '1.1.1'
      and   werks = it_asd012_001-param_1
      and   lgort = it_asd012_001-value
      and  (labst gt 0 or insme gt 0 or einme gt 0 or speme gt 0 or retme gt 0).

       if sy-subrc eq o.
            select mtart from mara
                   into table it_mara 
                    for all entries in it_inventory
                    where matnr = it_enventoty-matnr
                    and   mtart in ('ZFG1' , 'ZFG4' , 'ZR12' ).
    
        endif.
        endif.

"Then just merge two table into third one.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it will help to solve your query,&lt;/P&gt;&lt;P&gt;Pratik&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2009 04:40:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341511#M1230251</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-11T04:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Select Statment Error (SQL)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341512#M1230252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Friends&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help it solved.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know there are some performance issue but i unable to use for all entries because there are some type mismatch.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyhow thanks again.&lt;/P&gt;&lt;P&gt;Have you a nice day!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2009 06:55:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statment-error-sql/m-p/5341512#M1230252</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-11T06:55:43Z</dc:date>
    </item>
  </channel>
</rss>

