<?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: Problems with dynamic where clause in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937333#M387503</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have also tried that but didn' work.&lt;/P&gt;&lt;P&gt;Thanks anyway for your time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ezequiel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Feb 2007 20:38:43 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-02-14T20:38:43Z</dc:date>
    <item>
      <title>Problems with dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937328#M387498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have an SQL query to access table MARD. I have 3 fields in the WHERE clause: MATNR, WERKS and LGORT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The types of these 3 fields are the following:&lt;/P&gt;&lt;P&gt;-MATNR like BAPIMATVP-MATNR&lt;/P&gt;&lt;P&gt;-WERKS like BAPIMATVP-WERKS&lt;/P&gt;&lt;P&gt;-LGORT like BAPICM61V-LGORT&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using structure TWHERE to build the where clause by concateneting the 3 fields as it follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;concatenate 'matnr = ' p_matnr into w_where
separated by space.
append w_where to t_where.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The query is constructed as follows:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT werks matnr lgort labst
INTO TABLE ti_mard
FROM mard
WHERE (ti_where).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is that the query is not working and there is data on the table for the values I am looking for.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have run ST05 to check what the problem is and this is what I got:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT WHERE "MANDT" = '300' AND "MATNR" = '        110302826' &lt;/P&gt;&lt;P&gt;AND "WERKS" = '1000' AND "LGORT" = '1392' &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you can see, the 0s uo front are being trimmed. I have tried everything (pack, unpack, shift, etc) but no matter what I do, the 0s keep getting trimmed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I run the query the "usual" way, like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;select werks matnr lgort labst
into table ti_mard
from mard
where matnr = matnr and
werks = werks and
lgort = lgort.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what I get in ST05:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT WHERE "MANDT" = '300' AND "MATNR" = '000000000110302826' &lt;/P&gt;&lt;P&gt;AND "WERKS" = '1000' AND "LGORT" = '1392'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas on how to solve this issue?&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;Best Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ezequiel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Feb 2007 20:18:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937328#M387498</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-14T20:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937329#M387499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;pass p_matnr to a variable which is declared as numc(18) and in the select use that variable then the zeros are not trimmed. Try this and award points if it helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: &lt;/P&gt;&lt;P&gt;        Vinni&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Feb 2007 20:23:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937329#M387499</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-14T20:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937330#M387500</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;Add zeroes infront of P_MATNR and concatenate..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use the FM CONVERSION_EXIT_ALPHA_INPUT to put zeroes infront of P_MATNR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'&lt;/P&gt;&lt;P&gt;  EXPORTING&lt;/P&gt;&lt;P&gt;     INPUT = P_MATNR&lt;/P&gt;&lt;P&gt;  IMPORTING&lt;/P&gt;&lt;P&gt;     OUTPUT = P_MATNR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then use the concatenate..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Naren&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Feb 2007 20:27:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937330#M387500</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-14T20:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937331#M387501</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;Declare a variable of type &amp;lt;b&amp;gt;N&amp;lt;/b&amp;gt; and length &amp;lt;b&amp;gt;18&amp;lt;/b&amp;gt; and use it instead of using p_matnr. i.e.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA : v_matnr(18) TYPE n.

v_matnr = p_matnr.

concatenate 'matnr = ' v_matnr into w_where
separated by space.
append w_where to t_where.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Reward points if the answer is helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mukul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Feb 2007 20:31:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937331#M387501</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-14T20:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937332#M387502</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have tried that but didn't worked.&lt;/P&gt;&lt;P&gt;Thanks anyway for your time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ezequiel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Feb 2007 20:35:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937332#M387502</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-14T20:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937333#M387503</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have also tried that but didn' work.&lt;/P&gt;&lt;P&gt;Thanks anyway for your time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ezequiel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Feb 2007 20:38:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937333#M387503</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-14T20:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937334#M387504</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have also tried that but didn' work.&lt;/P&gt;&lt;P&gt;Thanks anyway for your time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ezequiel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Feb 2007 20:39:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937334#M387504</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-14T20:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937335#M387505</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One problem is that the material number is not converted to internal format as suggestion above.  so make those changes first.  Another is that there may be a problem with the way that you build the WHERE clause.  You need to wrap the P_MATNR value with quotes in your WHERE clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data: matnr_String type string.
data: p_matnr type mara-matnr value '000000000012345678'.

concatenate '''' p_matnr '''' into matnr_string.

concatenate 'matnr = ' matnr_string into w_where
separated by space.
append w_where to t_where.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Feb 2007 20:40:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937335#M387505</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2007-02-14T20:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with dynamic where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937336#M387506</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Rich,&lt;/P&gt;&lt;P&gt;Your solution has solved my problem.&lt;/P&gt;&lt;P&gt;I had already converted the material into an internal format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards.&lt;/P&gt;&lt;P&gt;Ezequiel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Feb 2007 21:00:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-dynamic-where-clause/m-p/1937336#M387506</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-14T21:00:00Z</dc:date>
    </item>
  </channel>
</rss>

