<?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: internal table - select if in range ? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107750#M105294</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt; You can use as&lt;/P&gt;&lt;P&gt;LOOP AT i_gl_account WHERE glacctfrom &amp;gt;= gl_account_fix &lt;/P&gt;&lt;P&gt;                       and glacctto &amp;lt;= gl_account_fix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 19 Dec 2005 19:24:51 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-12-19T19:24:51Z</dc:date>
    <item>
      <title>internal table - select if in range ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107748#M105292</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello ABAP Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a internal i_gl_account table which has some of the following fields:&lt;/P&gt;&lt;P&gt;glacctfrom, glacctto, flag&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i have to select a record from this internal table based on a fixed gl_account_fix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i cannot write this statement &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table i_gl_account with key&lt;/P&gt;&lt;P&gt;           glacctfrom &amp;gt;= gl_account_fix&lt;/P&gt;&lt;P&gt;           glacctto &amp;lt;= gl_account_fix&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;since read does not allow the '&amp;gt;' or '&amp;lt;' operators.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;one alternative possible is:&lt;/P&gt;&lt;P&gt;loop i_gl_account.&lt;/P&gt;&lt;P&gt;  if ( glacctfrom &amp;gt;= gl_account_fix and &lt;/P&gt;&lt;P&gt;       glacctto &amp;lt;= gl_account_fix).&lt;/P&gt;&lt;P&gt;     .....&lt;/P&gt;&lt;P&gt;     .....&lt;/P&gt;&lt;P&gt;  exit.&lt;/P&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This solutions, lookups at each and every record one by one and then does the if comparisions. Incase the i_gl_account is large then this is huge cost and processing. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wondering if there is any other possible method of achieving the same with lesser processing and cost.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggetions are appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;BWer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Dec 2005 19:22:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107748#M105292</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-19T19:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: internal table - select if in range ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107749#M105293</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried the WHERE clause for the LOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;


loop i_gl_account.
   where glacctfrom &amp;gt;= gl_account_fix
     and   glacctto &amp;lt;= gl_account_fix.
.....
exit.
endloop.



&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&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>Mon, 19 Dec 2005 19:24:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107749#M105293</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-12-19T19:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: internal table - select if in range ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107750#M105294</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt; You can use as&lt;/P&gt;&lt;P&gt;LOOP AT i_gl_account WHERE glacctfrom &amp;gt;= gl_account_fix &lt;/P&gt;&lt;P&gt;                       and glacctto &amp;lt;= gl_account_fix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Dec 2005 19:24:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107750#M105294</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-19T19:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: internal table - select if in range ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107751#M105295</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi BWer,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use the where claus einstead of the IF statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop i_gl_account where&lt;/P&gt;&lt;P&gt;   ( glacctfrom &amp;gt;= gl_account_fix and &lt;/P&gt;&lt;P&gt;   glacctto &amp;lt;= gl_account_fix).&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;exit.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Suresh Datti&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Dec 2005 19:26:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107751#M105295</guid>
      <dc:creator>suresh_datti</dc:creator>
      <dc:date>2005-12-19T19:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: internal table - select if in range ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107752#M105296</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;Put the condition in the where clause of the loop stmt.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at i_gl_account where &lt;/P&gt;&lt;P&gt;  glacctfrom &amp;gt;= gl_account_fix and &lt;/P&gt;&lt;P&gt;glacctto &amp;lt;= gl_account_fix .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; ...........&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Kalpana&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Dec 2005 19:26:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107752#M105296</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-19T19:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: internal table - select if in range ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107753#M105297</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could also something simular to this sample program.  If know that the start point is in the table.  Here the program is reading the first line where the start value is =,  then it is reading each line after that untill it reaches the end point.  But it is not reading the entire internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report  zrich_0001.


data: begin of itab occurs 0,
      field1(10) type c,
       field2(10) type c,
       field3(10) type c,
      end of itab.

itab-field1 = 'A'.
itab-field2 = '1'.
itab-field3 = '001'.
append itab.

itab-field1 = 'A'.
itab-field2 = '2'.
itab-field3 = '123'.
append itab.

itab-field1 = 'A'.
itab-field2 = '3'.
itab-field3 = '124'.
append itab.

itab-field1 = 'A'.
itab-field2 = '4'.
itab-field3 = '125'.
append itab.

itab-field1 = 'A'.
itab-field2 = '5'.
itab-field3 = '999'.
append itab.

sort itab ascending by field1 field2 field3.


data: index type sy-index.
data: start like itab-field3 value '123'.
data: end like itab-field3 value '125'.

read table itab with key field3 = start.
if sy-subrc  = 0.
  write:/ itab-field1, itab-field2, itab-field3.
  index = sy-tabix + 1.
  while sy-subrc = 0.
    read table itab index index.
    if sy-subrc = 0
        and itab-field3 &amp;lt;= end.
      write:/ itab-field1, itab-field2, itab-field3.
    else.
      sy-subrc  = 4.
    endif.
    index = index + 1.
  endwhile.
endif.


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&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>Mon, 19 Dec 2005 19:37:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107753#M105297</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-12-19T19:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: internal table - select if in range ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107754#M105298</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi BWer,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If a standard internal table is already sorted and you perform a binary search on it for a &amp;lt;b&amp;gt;non-existent&amp;lt;/b&amp;gt; key value, the SY_TABIX always point to the index &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;where that key value can be inserted while keeping the table sorted&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;. You can use this property to write very simple and very fast program. Please see the following example. Please copy and test this example. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;report zsharad.

data :begin of l_tab  ,
       n type i,
       end of l_tab.

data : i_tab like table of l_tab with header line.

*-----Selection screen
parameters: p_st type I,  "Start value
            p_en type I.  "End value
*-------Main program
start-of-selection.
*-----Prepare internal table
  i_tab-n = '3'.
  append i_tab.

  i_tab-n = '5'.
  append i_tab.

  i_tab-n = '6'.
  append i_tab.

  i_tab-n = '8'.
  append i_tab.

  i_tab-n = '9'.
  append i_tab.

  i_tab-n = '12'.
  append i_tab.

  i_tab-n = '16'.
  append i_tab.

  i_tab-n = '20'.
  append i_tab.

  sort i_tab.
*----Get start index by reading table by starting value
  read table i_tab with key n =  p_st
                        binary search.

  loop at i_tab from sy-tabix.
*-----Keep on reading till end of the table or value becomes greater
*-----than end value  
    if i_tab-n GT p_en.
      exit.
    endif.
    
    write :/01 i_tab-n.
  endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Dec 2005 20:41:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-select-if-in-range/m-p/1107754#M105298</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-19T20:41:06Z</dc:date>
    </item>
  </channel>
</rss>

