<?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: LOOP situation in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605433#M271691</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;    follow below logic.&lt;/P&gt;&lt;P&gt;      sort itab by col1.&lt;/P&gt;&lt;P&gt;        &lt;/P&gt;&lt;P&gt;      data:begin of itab1 occurs 0 ,&lt;/P&gt;&lt;P&gt;            col1(2) type c,&lt;/P&gt;&lt;P&gt;            count00 type i,&lt;/P&gt;&lt;P&gt;            count01 type i,&lt;/P&gt;&lt;P&gt;          end of itab1.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;      loop at itab.&lt;/P&gt;&lt;P&gt;       at new col1.&lt;/P&gt;&lt;P&gt;        clear lv_cnt,lv_cnt1.&lt;/P&gt;&lt;P&gt;       endat. &lt;/P&gt;&lt;P&gt;     if itab-col2 = '00'  &lt;/P&gt;&lt;P&gt;      lv_cnt = lv_cnt  + 1.&lt;/P&gt;&lt;P&gt;     elseif itab-col2 = '01'  &lt;/P&gt;&lt;P&gt;      lv_cnt1 = lv_cnt1 + 1.&lt;/P&gt;&lt;P&gt;     endif. &lt;/P&gt;&lt;P&gt;.      at end of col1.&lt;/P&gt;&lt;P&gt;        itab1-col1 = itab-col1.&lt;/P&gt;&lt;P&gt;        itab1-count00 = lv_cnt.&lt;/P&gt;&lt;P&gt;        itab1-count01 = lv_cnt1.&lt;/P&gt;&lt;P&gt;        append itab1.&lt;/P&gt;&lt;P&gt;        clear itab1.&lt;/P&gt;&lt;P&gt;       endat. &lt;/P&gt;&lt;P&gt;   endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; loop at itab1.&lt;/P&gt;&lt;P&gt;  write:itab1. &lt;/P&gt;&lt;P&gt; endloop.&lt;/P&gt;&lt;P&gt;itab1 will have output &lt;/P&gt;&lt;P&gt;AA 2 1&lt;/P&gt;&lt;P&gt;BB 1 2 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;amole&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 18 Oct 2006 10:33:35 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-10-18T10:33:35Z</dc:date>
    <item>
      <title>LOOP situation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605428#M271686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello experts, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you help me with this.&lt;/P&gt;&lt;P&gt;Here's the scenario:&lt;/P&gt;&lt;P&gt;col1  col2&lt;/P&gt;&lt;P&gt; AA    01&lt;/P&gt;&lt;P&gt; AA    00&lt;/P&gt;&lt;P&gt; AA    01&lt;/P&gt;&lt;P&gt; BB    00&lt;/P&gt;&lt;P&gt; BB    01&lt;/P&gt;&lt;P&gt; BB    00&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wanted to know how many 01s and 00s per column 1. so in that scenario.. the result should be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AA   2    1&lt;/P&gt;&lt;P&gt;BB   1    2      &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Column2: for all 01&lt;/P&gt;&lt;P&gt;Column3: for all 00&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2006 10:11:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605428#M271686</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-18T10:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP situation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605429#M271687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Hope this helps - I've not tested it but it should work you just need to declare the count variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SORT itab BY col1 col2
LOOP AT itab.

  IF itab-col2 = '00'.
    count_0 = count_0 + 1.
  ELSEIF itab-col2 = '01'.
    count_1 = count_0 + 1.

  AT END col1.
    WRITE: /itab-col1, count_1, count_2.
    count_0 = 0.
    count_1 = 0.
  ENDAT.
ENDLOOP.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2006 10:17:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605429#M271687</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-18T10:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP situation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605430#M271688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Lana,&lt;/P&gt;&lt;P&gt;try it with collect.&lt;/P&gt;&lt;P&gt;copy your internal table to itab1 an add&lt;/P&gt;&lt;P&gt;a field like I type I.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab.&lt;/P&gt;&lt;P&gt;itab1 = itab.&lt;/P&gt;&lt;P&gt;itab1-i = 1.&lt;/P&gt;&lt;P&gt;collect itab1.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in Itab1 you get your Information.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards, Dieter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2006 10:18:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605430#M271688</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-18T10:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP situation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605431#M271689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;define itab with fields col1 cnt0 cnt1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itable-&amp;gt;is the internal table with your data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort itable.&lt;/P&gt;&lt;P&gt;Loop at itable.&lt;/P&gt;&lt;P&gt;  at new col1.&lt;/P&gt;&lt;P&gt;     clear : lcnt0, lcnt1.&lt;/P&gt;&lt;P&gt;  endat.&lt;/P&gt;&lt;P&gt;  if itable-col2 = '00'.&lt;/P&gt;&lt;P&gt;     add 1 to lcnt0.&lt;/P&gt;&lt;P&gt;  elseif itable-col2 = '01'.&lt;/P&gt;&lt;P&gt;     add 1 to lcnt1.&lt;/P&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt;  at end of col1.&lt;/P&gt;&lt;P&gt;     move itable-col1 to itab-col1.&lt;/P&gt;&lt;P&gt;     move lcnt0 to itab-cnt0.&lt;/P&gt;&lt;P&gt;     move lcnt1 to itab-cnt1.&lt;/P&gt;&lt;P&gt;     append itab.&lt;/P&gt;&lt;P&gt;  endat.&lt;/P&gt;&lt;P&gt;Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab has the data you require&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2006 10:22:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605431#M271689</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-18T10:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP situation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605432#M271690</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;Pl find eg below.&lt;/P&gt;&lt;P&gt;LOOP AT  internal table   .&lt;/P&gt;&lt;P&gt;    l_count  = l_count  + 1.&lt;/P&gt;&lt;P&gt;    at end of column 1  .&lt;/P&gt;&lt;P&gt;      &amp;lt;logic &amp;gt;&lt;/P&gt;&lt;P&gt;       sum.&lt;/P&gt;&lt;P&gt;       on change of internal table- column 1.&lt;/P&gt;&lt;P&gt;      endon.&lt;/P&gt;&lt;P&gt;    endat.&lt;/P&gt;&lt;P&gt;  ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pl reward if it helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2006 10:23:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605432#M271690</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-18T10:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP situation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605433#M271691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;    follow below logic.&lt;/P&gt;&lt;P&gt;      sort itab by col1.&lt;/P&gt;&lt;P&gt;        &lt;/P&gt;&lt;P&gt;      data:begin of itab1 occurs 0 ,&lt;/P&gt;&lt;P&gt;            col1(2) type c,&lt;/P&gt;&lt;P&gt;            count00 type i,&lt;/P&gt;&lt;P&gt;            count01 type i,&lt;/P&gt;&lt;P&gt;          end of itab1.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;      loop at itab.&lt;/P&gt;&lt;P&gt;       at new col1.&lt;/P&gt;&lt;P&gt;        clear lv_cnt,lv_cnt1.&lt;/P&gt;&lt;P&gt;       endat. &lt;/P&gt;&lt;P&gt;     if itab-col2 = '00'  &lt;/P&gt;&lt;P&gt;      lv_cnt = lv_cnt  + 1.&lt;/P&gt;&lt;P&gt;     elseif itab-col2 = '01'  &lt;/P&gt;&lt;P&gt;      lv_cnt1 = lv_cnt1 + 1.&lt;/P&gt;&lt;P&gt;     endif. &lt;/P&gt;&lt;P&gt;.      at end of col1.&lt;/P&gt;&lt;P&gt;        itab1-col1 = itab-col1.&lt;/P&gt;&lt;P&gt;        itab1-count00 = lv_cnt.&lt;/P&gt;&lt;P&gt;        itab1-count01 = lv_cnt1.&lt;/P&gt;&lt;P&gt;        append itab1.&lt;/P&gt;&lt;P&gt;        clear itab1.&lt;/P&gt;&lt;P&gt;       endat. &lt;/P&gt;&lt;P&gt;   endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; loop at itab1.&lt;/P&gt;&lt;P&gt;  write:itab1. &lt;/P&gt;&lt;P&gt; endloop.&lt;/P&gt;&lt;P&gt;itab1 will have output &lt;/P&gt;&lt;P&gt;AA 2 1&lt;/P&gt;&lt;P&gt;BB 1 2 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;amole&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2006 10:33:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605433#M271691</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-18T10:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP situation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605434#M271692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;check this code it may help u.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;report z_example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;     col1(3) type c,&lt;/P&gt;&lt;P&gt;     col2(3) type c,&lt;/P&gt;&lt;P&gt;    end of itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:begin of itab1 occurs 0,&lt;/P&gt;&lt;P&gt;     col1(3) type c,&lt;/P&gt;&lt;P&gt;     count1 type i,&lt;/P&gt;&lt;P&gt;     count2 type i,&lt;/P&gt;&lt;P&gt;     end of itab1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-col1 = 'AA'.&lt;/P&gt;&lt;P&gt;itab-col2 = '01'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-col1 = 'AA'.&lt;/P&gt;&lt;P&gt;itab-col2 = '00'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-col1 = 'AA'.&lt;/P&gt;&lt;P&gt;itab-col2 = '01'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-col1 = 'BB'.&lt;/P&gt;&lt;P&gt;itab-col2 = '01'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-col1 = 'BB'.&lt;/P&gt;&lt;P&gt;itab-col2 = '00'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort itab by col1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab.&lt;/P&gt;&lt;P&gt;at new col1.&lt;/P&gt;&lt;P&gt;itab1-col1 = itab-col1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endat.&lt;/P&gt;&lt;P&gt;if itab-col2 = '01'.&lt;/P&gt;&lt;P&gt;itab1-count1 = itab1-count1 + 1.&lt;/P&gt;&lt;P&gt;elseif itab-col2 = '00'.&lt;/P&gt;&lt;P&gt;itab1-count2 = itab1-count2 + 1.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;at end of col1.&lt;/P&gt;&lt;P&gt;append itab1.&lt;/P&gt;&lt;P&gt;clear itab1.&lt;/P&gt;&lt;P&gt;endat.&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;&lt;/P&gt;&lt;P&gt;loop at itab1.&lt;/P&gt;&lt;P&gt;write:/ itab1-col1,itab1-count1,itab1-count2.&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;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2006 10:39:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605434#M271692</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-18T10:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP situation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605435#M271693</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;Below is the source code for this scenario.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maintain swap internal table and also Counts internal table as shown in the below source code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;report abc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  data:&lt;/P&gt;&lt;P&gt;    v_count type i,&lt;/P&gt;&lt;P&gt;    v_tabix type sy-tabix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*-- Actual Data&lt;/P&gt;&lt;P&gt;  data:begin of it_actual occurs 0,&lt;/P&gt;&lt;P&gt;    f1(3) type c,&lt;/P&gt;&lt;P&gt;    f2(3) type c,&lt;/P&gt;&lt;P&gt;  end of it_actual.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*-- Swap Actual Data&lt;/P&gt;&lt;P&gt;  data:begin of it_swap occurs 0,&lt;/P&gt;&lt;P&gt;    f1(3) type c,&lt;/P&gt;&lt;P&gt;    f2(3) type c,&lt;/P&gt;&lt;P&gt;  end of it_swap.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*-- Holds Counts for sorted data&lt;/P&gt;&lt;P&gt;  data:begin of it_sort occurs 0,&lt;/P&gt;&lt;P&gt;    col1(3) type c,&lt;/P&gt;&lt;P&gt;    col2(3) type c,&lt;/P&gt;&lt;P&gt;    count type i,&lt;/P&gt;&lt;P&gt;  end of it_sort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  start-of-selection.&lt;/P&gt;&lt;P&gt;*-- Append Test Data&lt;/P&gt;&lt;P&gt;    perform append.&lt;/P&gt;&lt;P&gt;*-- Sort Data&lt;/P&gt;&lt;P&gt;    perform sort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  append&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      text&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; --&amp;gt;  p1        text&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; &amp;lt;--  p2        text&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FORM append .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  it_actual-f1 = 'AA'.&lt;/P&gt;&lt;P&gt;  it_actual-f2 = '01'.&lt;/P&gt;&lt;P&gt;  append it_actual.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  it_actual-f1 = 'AA'.&lt;/P&gt;&lt;P&gt;  it_actual-f2 = '00'.&lt;/P&gt;&lt;P&gt;  append it_actual.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  it_actual-f1 = 'AA'.&lt;/P&gt;&lt;P&gt;  it_actual-f2 = '01'.&lt;/P&gt;&lt;P&gt;  append it_actual.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  it_actual-f1 = 'BB'.&lt;/P&gt;&lt;P&gt;  it_actual-f2 = '00'.&lt;/P&gt;&lt;P&gt;  append it_actual.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  it_actual-f1 = 'BB'.&lt;/P&gt;&lt;P&gt;  it_actual-f2 = '01'.&lt;/P&gt;&lt;P&gt;  append it_actual.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  it_actual-f1 = 'BB'.&lt;/P&gt;&lt;P&gt;  it_actual-f2 = '00'.&lt;/P&gt;&lt;P&gt;  append it_actual.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*-- Your actual format&lt;/P&gt;&lt;P&gt;  loop at it_actual.&lt;/P&gt;&lt;P&gt;      write:/ it_actual-f1, it_actual-f2.&lt;/P&gt;&lt;P&gt;  endloop.&lt;/P&gt;&lt;P&gt;  skip 2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*-- Populate other table which swaps the fields&lt;/P&gt;&lt;P&gt;  loop at it_actual.&lt;/P&gt;&lt;P&gt;    it_swap-f1 = it_actual-f2.&lt;/P&gt;&lt;P&gt;    it_swap-f2 = it_actual-f1.&lt;/P&gt;&lt;P&gt;    append it_swap.&lt;/P&gt;&lt;P&gt;    clear  it_swap.&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;ENDFORM.                    " append&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  sort&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      text&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; --&amp;gt;  p1        text&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; &amp;lt;--  p2        text&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FORM sort .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*-- Sort as per requirement&lt;/P&gt;&lt;P&gt;  sort it_swap by f1 f2.&lt;/P&gt;&lt;P&gt;  loop at it_swap.&lt;/P&gt;&lt;P&gt;    write:/ it_swap-f1, it_swap-f2.&lt;/P&gt;&lt;P&gt;  endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  loop at it_swap.&lt;/P&gt;&lt;P&gt;*-- Populate Loop index&lt;/P&gt;&lt;P&gt;    v_tabix = sy-tabix.&lt;/P&gt;&lt;P&gt;    at new f2.&lt;/P&gt;&lt;P&gt;*-- Initialize counter&lt;/P&gt;&lt;P&gt;      clear v_count.&lt;/P&gt;&lt;P&gt;    endat.&lt;/P&gt;&lt;P&gt;*-- Add counter&lt;/P&gt;&lt;P&gt;    v_count = v_count + 1.&lt;/P&gt;&lt;P&gt;    at end of f2.&lt;/P&gt;&lt;P&gt;*-- Read to avoid STARS&lt;/P&gt;&lt;P&gt;      read table it_swap index v_tabix.&lt;/P&gt;&lt;P&gt;*-- Append other table&lt;/P&gt;&lt;P&gt;      it_sort-col1 = it_swap-f2.&lt;/P&gt;&lt;P&gt;      it_sort-col2 = it_swap-f1.&lt;/P&gt;&lt;P&gt;      it_sort-count = v_count.&lt;/P&gt;&lt;P&gt;      append it_sort.&lt;/P&gt;&lt;P&gt;      clear  it_sort.&lt;/P&gt;&lt;P&gt;    endat.&lt;/P&gt;&lt;P&gt;  endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*-- Now you have the below Internal table which holds counts&lt;/P&gt;&lt;P&gt;  skip 2.&lt;/P&gt;&lt;P&gt;  loop at it_sort.&lt;/P&gt;&lt;P&gt;    write: / it_sort-col1, it_sort-col2, it_sort-count.&lt;/P&gt;&lt;P&gt;  endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*-- You can sort this again to have the proper output&lt;/P&gt;&lt;P&gt;  skip 2.&lt;/P&gt;&lt;P&gt;  sort it_sort by col1 col2.&lt;/P&gt;&lt;P&gt;  loop at it_sort.&lt;/P&gt;&lt;P&gt;    v_tabix = sy-tabix.&lt;/P&gt;&lt;P&gt;    at new col1.&lt;/P&gt;&lt;P&gt;      write: / it_sort-col1.&lt;/P&gt;&lt;P&gt;    endat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    at end of col2.&lt;/P&gt;&lt;P&gt;      read table it_sort index v_tabix.&lt;/P&gt;&lt;P&gt;      write: it_sort-count.&lt;/P&gt;&lt;P&gt;    endat.&lt;/P&gt;&lt;P&gt;  endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDFORM.                    " sort&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2006 11:38:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605435#M271693</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-18T11:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP situation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605436#M271694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi anurag, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks.. that was a very helpful tip..&lt;/P&gt;&lt;P&gt;btw, we are trying to eliminate the use of AT NEW and in the coding.. instead were using ON CHANGE OF and ENDON to close the statement.. &lt;/P&gt;&lt;P&gt;I wonder wat could be the alternate for:&lt;/P&gt;&lt;P&gt;AT NEW (ON CHANGE OF)&lt;/P&gt;&lt;P&gt;ENDAT (ENDON)&lt;/P&gt;&lt;P&gt;AT END ???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Oct 2006 02:36:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605436#M271694</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-19T02:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP situation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605437#M271695</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;data:begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;cl1(2) type c,&lt;/P&gt;&lt;P&gt;cl2(2) type c,&lt;/P&gt;&lt;P&gt;end of itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:begin of itab2 occurs 0,&lt;/P&gt;&lt;P&gt;cl1(2) type c,&lt;/P&gt;&lt;P&gt;ca0 type i,&lt;/P&gt;&lt;P&gt;ca1 type i,&lt;/P&gt;&lt;P&gt;end of itab2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:ca0 type i value 0,ca1 type i value 0,&lt;/P&gt;&lt;P&gt;count type i value 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-cl1 = 'AA'.&lt;/P&gt;&lt;P&gt;itab-cl2 = '01'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;itab-cl1 = 'AA'.&lt;/P&gt;&lt;P&gt;itab-cl2 = '00'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;itab-cl1 = 'AA'.&lt;/P&gt;&lt;P&gt;itab-cl2 = '01'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;itab-cl1 = 'BB'.&lt;/P&gt;&lt;P&gt;itab-cl2 = '00'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;itab-cl1 = 'BB'.&lt;/P&gt;&lt;P&gt;itab-cl2 = '01'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;itab-cl1 = 'BB'.&lt;/P&gt;&lt;P&gt;itab-cl2 = '00'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;sort itab.&lt;/P&gt;&lt;P&gt;loop at itab.&lt;/P&gt;&lt;P&gt;  on change of itab-cl1.&lt;/P&gt;&lt;P&gt;    clear: ca0,ca1,count.&lt;/P&gt;&lt;P&gt;  endon.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  if itab-cl2 = '00'.&lt;/P&gt;&lt;P&gt;    ca0 = ca0 + 1.&lt;/P&gt;&lt;P&gt;  else.&lt;/P&gt;&lt;P&gt;    ca1 = ca1 + 1.&lt;/P&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  perform outdata.&lt;/P&gt;&lt;P&gt;endloop.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  outdata&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      text&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; --&amp;gt;  p1        text&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; &amp;lt;--  p2        text&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form outdata .&lt;/P&gt;&lt;P&gt;  if count &amp;gt; 0.&lt;/P&gt;&lt;P&gt;    if itab2-cl1 &amp;lt;&amp;gt; itab-cl1.&lt;/P&gt;&lt;P&gt;      itab2-cl1 = itab-cl1.&lt;/P&gt;&lt;P&gt;      itab2-ca0 = ca0.&lt;/P&gt;&lt;P&gt;      itab2-ca1 = ca1.&lt;/P&gt;&lt;P&gt;      append itab2.&lt;/P&gt;&lt;P&gt;    else.&lt;/P&gt;&lt;P&gt;      itab2-cl1 = itab-cl1.&lt;/P&gt;&lt;P&gt;      itab2-ca0 = ca0.&lt;/P&gt;&lt;P&gt;      itab2-ca1 = ca1.&lt;/P&gt;&lt;P&gt;      append itab2.&lt;/P&gt;&lt;P&gt;      write:/ itab2-cl1,itab2-ca0,itab2-ca1.&lt;/P&gt;&lt;P&gt;    endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt; count  = count + 1.&lt;/P&gt;&lt;P&gt;endform.                    " outdata&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please do reward points if it solves your problem&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sowjanya&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Oct 2006 06:33:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605437#M271695</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-19T06:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP situation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605438#M271696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;or in simple way without using any control breaks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab.&lt;/P&gt;&lt;P&gt;if itab-cl1 = 'AA'.&lt;/P&gt;&lt;P&gt;  if itab-cl2 = '00'.&lt;/P&gt;&lt;P&gt;  ca0 = ca0 + 1.&lt;/P&gt;&lt;P&gt;  else.&lt;/P&gt;&lt;P&gt;  ca1 = ca1 + 1.&lt;/P&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt;else.&lt;/P&gt;&lt;P&gt;  if itab-cl2 = '00'.&lt;/P&gt;&lt;P&gt;  cb0 = cb0 + 1.&lt;/P&gt;&lt;P&gt;  else.&lt;/P&gt;&lt;P&gt;  cb1 = cb1 + 1.&lt;/P&gt;&lt;P&gt;  endif.&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;Regards,&lt;/P&gt;&lt;P&gt;Sowjanya&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Oct 2006 06:49:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605438#M271696</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-19T06:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP situation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605439#M271697</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;To replicate the END AT you will need to record the relevant column data on each iteration of the loop.  Then on the next iteration you can compare the current field with the last one to see if they have changed.  Something like the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA:
  tmp_field TYPE itab-col1.

LOOP AT itab.
* This is like AT END
  IF tmp_field &amp;lt;&amp;gt; itab-col1 AND
     NOT tmp_field IS INITIAL.

*   Do stuff here...
  END IF.
  tmp_field = itab-col1.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, why are you trying to eliminate the AT control breaks and replace them with ON CHANGE OF?  As I understand it, SAP do not recommend using ON CHANGE OF for two reasons:&lt;/P&gt;&lt;P&gt;1. It does not work with ABAP objects.&lt;/P&gt;&lt;P&gt;2. It can produce unpredicatable results when used within a Loop structure.  The following is extracted from the SAP online help:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"There are special control structures for processing control breaks in LOOP s on internal tables or extract datasets (AT). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ON CHANGE OF is unsuitable for recognizing control levels in loops of this type because it always creates a global auxiliary field which is used to check for changes. This global auxiliary field is only changed in the relevant ON CHANGE OF statement. It is not reset when the processing enters loops or subroutines, so unwanted effects can occur if the loop or subroutine is executed again. Also, since it is set to its initial value when created (like any other field), any ON CHANGE OF processing will be executed after the first test, unless the contents of the field concerned happen to be identical to the initial value. "&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps &lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Oct 2006 08:18:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605439#M271697</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-19T08:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP situation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605440#M271698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would advice you to use AT events rather than ON CHANGE, as they are now obselte. But in case you still wish to use them here is the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort itable.&lt;/P&gt;&lt;P&gt;read table itable index 1.&lt;/P&gt;&lt;P&gt;Loop at itable.&lt;/P&gt;&lt;P&gt;if itable-col2 = '00'.&lt;/P&gt;&lt;P&gt; lcnt0 = lcnt0 + 1.&lt;/P&gt;&lt;P&gt;elseif itable-col2 = '01'.&lt;/P&gt;&lt;P&gt; lcnt1 = lcnt1 + 1.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;on change of itable-col1 or itable-col2.&lt;/P&gt;&lt;P&gt;move itable-col1 to itab-col1.&lt;/P&gt;&lt;P&gt;move lcnt0 to itab-cnt0.&lt;/P&gt;&lt;P&gt;move lcnt1 to itab-cnt1.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;endon.&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;Message was edited by: Anurag Bankley&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Oct 2006 09:00:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-situation/m-p/1605440#M271698</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-19T09:00:12Z</dc:date>
    </item>
  </channel>
</rss>

