<?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 identifying consecutive values in internal table. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/identifying-consecutive-values-in-internal-table/m-p/1927255#M384587</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have an internal table with field A.&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="---" /&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;6&lt;/P&gt;&lt;P&gt;7&lt;/P&gt;&lt;P&gt;10&lt;/P&gt;&lt;P&gt;12&lt;/P&gt;&lt;P&gt;13&lt;/P&gt;&lt;P&gt;14&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------" /&gt;&lt;P&gt;the values 4-7 are consecutive.&lt;/P&gt;&lt;P&gt;I need to print output as &lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;4 to 7&lt;/P&gt;&lt;P&gt;10 &lt;/P&gt;&lt;P&gt;12 to 14&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please help me to find the logic for implementing this. Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Pranati.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 25 Feb 2007 00:40:34 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-02-25T00:40:34Z</dc:date>
    <item>
      <title>identifying consecutive values in internal table.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/identifying-consecutive-values-in-internal-table/m-p/1927255#M384587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have an internal table with field A.&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="---" /&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;6&lt;/P&gt;&lt;P&gt;7&lt;/P&gt;&lt;P&gt;10&lt;/P&gt;&lt;P&gt;12&lt;/P&gt;&lt;P&gt;13&lt;/P&gt;&lt;P&gt;14&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------" /&gt;&lt;P&gt;the values 4-7 are consecutive.&lt;/P&gt;&lt;P&gt;I need to print output as &lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;4 to 7&lt;/P&gt;&lt;P&gt;10 &lt;/P&gt;&lt;P&gt;12 to 14&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please help me to find the logic for implementing this. Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Pranati.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Feb 2007 00:40:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/identifying-consecutive-values-in-internal-table/m-p/1927255#M384587</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-25T00:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: identifying consecutive values in internal table.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/identifying-consecutive-values-in-internal-table/m-p/1927256#M384588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi please look at the following code. I am not sitting on an sap system and hence there might be small bugs as i have not tested it at all. But this should give you atleast a basic idea of the logic and u should be able to do it from henceforth.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
types: begin of ty_itab,
       field type int4,
       end   of ty_itab.

data: li_main_tab type standard table of ty_itab,
      lx_first_no type ty_itab,
      lx_loop_no  type ty_itab,
      lx_prev_no  type ty_itab.
* Now populate data however you are doing it.
* the above data statements are only for your reference.

sort li_main_tab by field.
read table li_main_tab
     index 1 
     into lx_first_no-field.
write:/ lx_first_no-field.
loop at li_main_tab into lx_loop_no.
  l_diff = lx_loop_no-field - l_prev_no-field.
  if l_diff NE 1.
    if l_gap NE c_x.
      write:/ lx_prev_no-field.
      l_gap = c_null.
    else.
      write: /c_first_no ' to ' c_prev_no.
      lx_first_no-field = lx_loop_no-field.
      lx_prev_no-field  = lx_loop_no-field.
    endif.
  else.
    lx_prev_no-field = lx_loop_no-field.
  endif.
endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do let me know if there are any issues.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Feb 2007 02:42:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/identifying-consecutive-values-in-internal-table/m-p/1927256#M384588</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-25T02:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: identifying consecutive values in internal table.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/identifying-consecutive-values-in-internal-table/m-p/1927257#M384589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have solved this problem. Here is the code which has worked for me.....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;l_t_runids is the internal table which has the values i have mentioned in the question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;ix = 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort l_t_runids.&lt;/P&gt;&lt;P&gt;delete adjacent duplicates from l_t_runids.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at l_t_runids.&lt;/P&gt;&lt;P&gt;l_t_runids-index = ix.&lt;/P&gt;&lt;P&gt;ix = ix + 1.&lt;/P&gt;&lt;P&gt;modify l_t_runids.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;clear count.&lt;/P&gt;&lt;P&gt;ix = 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at l_t_runids.&lt;/P&gt;&lt;P&gt;  var1 = l_t_runids-runid.&lt;/P&gt;&lt;P&gt;  cx = ix + 1.&lt;/P&gt;&lt;P&gt;  read table l_t_runids index cx.&lt;/P&gt;&lt;P&gt;  var2 = l_t_runids-runid.&lt;/P&gt;&lt;P&gt;  var3 = var1 + 1.&lt;/P&gt;&lt;P&gt;  if var2 = var3.&lt;/P&gt;&lt;P&gt;    count = count + 1.&lt;/P&gt;&lt;P&gt;    if count = 1.&lt;/P&gt;&lt;P&gt;      l_t_runid-runid = var1.&lt;/P&gt;&lt;P&gt;      append l_t_runid.&lt;/P&gt;&lt;P&gt;      l_t_runid-runid = var2.&lt;/P&gt;&lt;P&gt;      append l_t_runid.&lt;/P&gt;&lt;P&gt;    else.&lt;/P&gt;&lt;P&gt;      l_t_runid-runid = var2.&lt;/P&gt;&lt;P&gt;      append l_t_runid.&lt;/P&gt;&lt;P&gt;    endif.&lt;/P&gt;&lt;P&gt;  elseif count &amp;gt; 0.&lt;/P&gt;&lt;P&gt;    describe table l_t_runid lines line.&lt;/P&gt;&lt;P&gt;    read table l_t_runid index line.&lt;/P&gt;&lt;P&gt;    hrunid = l_t_runid-runid.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    line = 1.&lt;/P&gt;&lt;P&gt;    read table l_t_runid index line.&lt;/P&gt;&lt;P&gt;    lrunid = l_t_runid-runid.&lt;/P&gt;&lt;P&gt;    clear l_t_runid.&lt;/P&gt;&lt;P&gt;    refresh l_t_runid.&lt;/P&gt;&lt;P&gt;    clear line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    write :/20 lrunid, 'to' , hrunid.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    clear count.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  else.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    write :/20 var1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ix = ix + 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  endloop.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Feb 2007 22:10:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/identifying-consecutive-values-in-internal-table/m-p/1927257#M384589</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-25T22:10:02Z</dc:date>
    </item>
  </channel>
</rss>

