<?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: Finding the nearest value. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/finding-the-nearest-value/m-p/3888610#M934075</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;give 10 as input and execute this program&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;parameters:valin type p.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;      val type p decimals 2,&lt;/P&gt;&lt;P&gt;     end of itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val = '10.13'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val = '14.13'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val = '9.13'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val = '4.13'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val = '22.13'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort itab descending.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab where val &amp;lt;= valin.&lt;/P&gt;&lt;P&gt;write itab-val.&lt;/P&gt;&lt;P&gt;exit.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 31 May 2008 09:26:17 GMT</pubDate>
    <dc:creator>kesavadas_thekkillath</dc:creator>
    <dc:date>2008-05-31T09:26:17Z</dc:date>
    <item>
      <title>Finding the nearest value.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/finding-the-nearest-value/m-p/3888608#M934073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gurus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have an internal table with values country code and current price and using a selection screen i get a price, now i need to pick a value from the table which is nearest to the one in the screen. How do i achieve this logic? All help regarding this is very much appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 31 May 2008 08:44:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/finding-the-nearest-value/m-p/3888608#M934073</guid>
      <dc:creator>former_member216668</dc:creator>
      <dc:date>2008-05-31T08:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the nearest value.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/finding-the-nearest-value/m-p/3888609#M934074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you can do like this..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;parameters : valin type p decimals 2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;val type p decimals 2,&lt;/P&gt;&lt;P&gt;end of itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val = valin.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort itab by val descending.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;venkat&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 31 May 2008 08:59:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/finding-the-nearest-value/m-p/3888609#M934074</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-31T08:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the nearest value.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/finding-the-nearest-value/m-p/3888610#M934075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;give 10 as input and execute this program&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;parameters:valin type p.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;      val type p decimals 2,&lt;/P&gt;&lt;P&gt;     end of itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val = '10.13'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val = '14.13'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val = '9.13'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val = '4.13'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val = '22.13'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort itab descending.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab where val &amp;lt;= valin.&lt;/P&gt;&lt;P&gt;write itab-val.&lt;/P&gt;&lt;P&gt;exit.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 31 May 2008 09:26:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/finding-the-nearest-value/m-p/3888610#M934075</guid>
      <dc:creator>kesavadas_thekkillath</dc:creator>
      <dc:date>2008-05-31T09:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the nearest value.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/finding-the-nearest-value/m-p/3888611#M934076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;give 10 as input and execute this program&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

parameters:valin type p.

data:begin of itab occurs 0,
val type p decimals 2,
end of itab.

itab-val = '10.13'.
append itab.

itab-val = '14.13'.
append itab.

itab-val = '9.13'.
append itab.

itab-val = '4.13'.
append itab.

itab-val = '22.13'.
append itab.

sort itab descending.

loop at itab where val &amp;lt;= valin.
write itab-val.
exit.
endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hi Keshu,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to find the nearest , i.e., if there is 9.8 in the table and 10.11 in the table and the value i enter is 10, then my program should pick up 10.11 as nearest value.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 31 May 2008 09:58:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/finding-the-nearest-value/m-p/3888611#M934076</guid>
      <dc:creator>former_member216668</dc:creator>
      <dc:date>2008-05-31T09:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the nearest value.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/finding-the-nearest-value/m-p/3888612#M934077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;

this will work....donot forget to reward

DATA:leval TYPE p DECIMALS 2.
DATA:geval TYPE p DECIMALS 2.
DATA:final_val1 TYPE p DECIMALS 2.
DATA:final_val2 TYPE p DECIMALS 2.

DATA:BEGIN OF itab OCCURS 0,
val TYPE p DECIMALS 2,
END OF itab.


PARAMETERS:valin TYPE p.


itab-val = '10.13'.APPEND itab.

itab-val = '14.13'.APPEND itab.

itab-val = '9.8'.APPEND itab.

itab-val = '4.13'.APPEND itab.

itab-val = '10.11'.APPEND itab.

SORT itab DESCENDING BY val.

LOOP AT itab WHERE val &amp;lt;= valin.
  leval = itab-val.
  EXIT.
ENDLOOP.

SORT itab ASCENDING BY val.

LOOP AT itab WHERE val &amp;gt;= valin.
  geval = itab-val.
  EXIT.
ENDLOOP.

final_val1 = ABS( valin - leval ).
final_val2 = ABS( valin - geval ).

IF final_val1 &amp;lt; final_val2.
  WRITE leval.
ELSEIF final_val2 &amp;lt; final_val1.
  WRITE geval.
ELSEIF final_val1 = 0 AND final_val2 &amp;lt;&amp;gt; 0.
  WRITE leval.
ELSEIF final_val2 = 0 AND final_val1 &amp;lt;&amp;gt; 0.
  WRITE geval.
ENDIF.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 31 May 2008 10:41:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/finding-the-nearest-value/m-p/3888612#M934077</guid>
      <dc:creator>kesavadas_thekkillath</dc:creator>
      <dc:date>2008-05-31T10:41:25Z</dc:date>
    </item>
  </channel>
</rss>

