<?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: Comparing two values in if condition in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617439#M2012337</link>
    <description>&lt;P&gt;Or you can use try catch and then do your if statement as below&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TRY.
gv_numeric = gv_string.
CATCH CX_SY_CONVERSION_NO_NUMBER.
MESSAGE 'no number' type 'S' DISPLAY LIKE 'S'.
ENDTRY.

  if gv_numeric &amp;lt; 0.
    write 'Negative'.
  elseif gv_numeric &amp;gt; 0..
    write 'Positive'.
  else.
    write 'Zero - Not numeric'.
  endif.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jul 2022 06:03:25 GMT</pubDate>
    <dc:creator>venkateswaran_k</dc:creator>
    <dc:date>2022-07-13T06:03:25Z</dc:date>
    <item>
      <title>Comparing two values in if condition</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617437#M2012335</link>
      <description>&lt;P&gt;Hello everyone.&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;i have a scenario where i get a value into a variable which is type string at runtime and i have to write it is positive or negative or zero in the output.&lt;/P&gt;
  &lt;P&gt;Here is the code&lt;/P&gt;
  &lt;P&gt;Consider a variable GV_STRING type string.&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;if gv_string gt 0.&lt;BR /&gt;write ‘positive’.&lt;/P&gt;
  &lt;P&gt;Elseif gv_string lt 0.&lt;/P&gt;
  &lt;P&gt;Write ‘negative’.&lt;/P&gt;
  &lt;P&gt;Else.&lt;/P&gt;
  &lt;P&gt;Write ’zero’.&lt;/P&gt;
  &lt;P&gt;Endif.&lt;BR /&gt;&lt;/P&gt;
  &lt;P&gt;If the value i am getting is between -0.4 to -0.1 and 0.1 to 0.4 it is writing as zero which is not the expected output.&lt;/P&gt;
  &lt;P&gt;And when i get a character it leads to run time error but the expected output is to write zero.&lt;/P&gt;
  &lt;P&gt;So i have done some experiments and i modified my code a little.&lt;/P&gt;
  &lt;P&gt;On the above code instead of giving zero simply, i gave them in single quotation as shown in below.&lt;/P&gt;
  &lt;P&gt;if gv_string gt ‘0’.&lt;BR /&gt;write ‘positive’.&lt;/P&gt;
  &lt;P&gt;Elseif gv_string lt ‘0’.&lt;/P&gt;
  &lt;P&gt;Write ‘negative’.&lt;/P&gt;
  &lt;P&gt;Else.&lt;/P&gt;
  &lt;P&gt;Write ’zero’.&lt;/P&gt;
  &lt;P&gt;Endif.&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;its output is as i expected but i don’t know why it is working when i gave them in single quotation and in the above code also when an character comes then it write as positive but i want when a character comes i need to write it as zero&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2022 05:34:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617437#M2012335</guid>
      <dc:creator>former_member798210</dc:creator>
      <dc:date>2022-07-13T05:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two values in if condition</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617438#M2012336</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;You are trying to compare the string variable to numeri value. It will not work. You need to do like this.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data gv_string type string.&lt;BR /&gt;data gv_numeric type p DECIMALS 2.&lt;BR /&gt;data gv_type type DD01V-DATATYPE.&lt;BR /&gt;&lt;BR /&gt;gv_string = '-0.4'.&lt;BR /&gt;CALL FUNCTION 'NUMERIC_CHECK'&lt;BR /&gt;  EXPORTING&lt;BR /&gt;    string_in        = gv_string&lt;BR /&gt; IMPORTING&lt;BR /&gt;*   STRING_OUT       =&lt;BR /&gt;    HTYPE            = gv_type.&lt;BR /&gt;&lt;BR /&gt;if gv_type = 'NUMC'.&lt;BR /&gt;  gv_numeric = gv_numeric.&lt;BR /&gt;  if gv_numeric &amp;lt; 0.&lt;BR /&gt;    write 'Negative'.&lt;BR /&gt;  else.&lt;BR /&gt;    write 'Positive'.&lt;BR /&gt;  endif.&lt;BR /&gt;else.&lt;BR /&gt;  write 'Not Numeric = Zero'.&lt;BR /&gt;endif.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Venkat&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2022 05:48:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617438#M2012336</guid>
      <dc:creator>venkateswaran_k</dc:creator>
      <dc:date>2022-07-13T05:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two values in if condition</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617439#M2012337</link>
      <description>&lt;P&gt;Or you can use try catch and then do your if statement as below&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TRY.
gv_numeric = gv_string.
CATCH CX_SY_CONVERSION_NO_NUMBER.
MESSAGE 'no number' type 'S' DISPLAY LIKE 'S'.
ENDTRY.

  if gv_numeric &amp;lt; 0.
    write 'Negative'.
  elseif gv_numeric &amp;gt; 0..
    write 'Positive'.
  else.
    write 'Zero - Not numeric'.
  endif.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2022 06:03:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617439#M2012337</guid>
      <dc:creator>venkateswaran_k</dc:creator>
      <dc:date>2022-07-13T06:03:25Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two values in if condition</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617440#M2012338</link>
      <description>&lt;P&gt;Please in future use the CODE button in the editor to display code. Like &lt;SPAN class="mention-scrubbed"&gt;venkateswaran.k&lt;/SPAN&gt; has.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2022 08:39:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617440#M2012338</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2022-07-13T08:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two values in if condition</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617441#M2012339</link>
      <description>&lt;P&gt;In your first code, your string is converted to an integer because you're comparing with a number without quotes, which is always treated as an integer. In the second, because you're comparing with a number in quotes, the string is converted to a floating point number.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2022 08:40:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617441#M2012339</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2022-07-13T08:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two values in if condition</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617442#M2012340</link>
      <description>&lt;P&gt;hai Matthew Billingham.&lt;/P&gt;&lt;P&gt;While i was providing input as GE 0.5 or  0.5-it is giving output as expected in the first code means upto my understanding it is rounding the value to a nearest whole number.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;i am correct, if wrong please guide me.&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;Venkata kalyan&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2022 14:31:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617442#M2012340</guid>
      <dc:creator>former_member798210</dc:creator>
      <dc:date>2022-07-13T14:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two values in if condition</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617443#M2012341</link>
      <description>&lt;P&gt;STEP 1. You can check input parameters is number. &lt;/P&gt;&lt;P&gt;STEP 2. Compare two value in If conditions &lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 00:44:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-values-in-if-condition/m-p/12617443#M2012341</guid>
      <dc:creator>former_member808116</dc:creator>
      <dc:date>2022-07-15T00:44:07Z</dc:date>
    </item>
  </channel>
</rss>

