<?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: collect statement in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982888#M704277</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT ITAB1 where WERKS &amp;lt;&amp;gt; '2130'.&lt;/P&gt;&lt;P&gt;MOVE CORRESPONDING ITAB1 INTO ITAB.&lt;/P&gt;&lt;P&gt;COLLECT ITAB.&lt;/P&gt;&lt;P&gt;ENDLOOP. &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>Fri, 26 Oct 2007 13:24:52 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-10-26T13:24:52Z</dc:date>
    <item>
      <title>collect statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982885#M704274</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 am having a problem while using COLLECT statement.&lt;/P&gt;&lt;P&gt;I have a table ITAB1 with field WERKS.&lt;/P&gt;&lt;P&gt;I want collect statement to run only if ITAB-WERKS is not equal to 2130. and the output is required in table ITAB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the code i have written. without IF statement the output is coming  as expected but with IF statemnt its not working . can anyone suggest what is to be done.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;code: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT ITAB1.&lt;/P&gt;&lt;P&gt; IF ITAB1-WERKS NE '2130'.&lt;/P&gt;&lt;P&gt;    MOVE CORRESPONDING ITAB1 INTO ITAB.&lt;/P&gt;&lt;P&gt;    COLLECT ITAB.&lt;/P&gt;&lt;P&gt; ELSE.&lt;/P&gt;&lt;P&gt;    MOVE CORRESPONDING ITAB1 INTO ITAB.&lt;/P&gt;&lt;P&gt; ENDIF.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2007 13:19:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982885#M704274</guid>
      <dc:creator>gautam_totekar</dc:creator>
      <dc:date>2007-10-26T13:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: collect statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982886#M704275</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Gautam,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT ITAB1 where WERKS NE '2130'.
MOVE CORRESPONDING ITAB1 INTO ITAB.
COLLECT ITAB.
endloop.

LOOP AT ITAB1 where WERKS EQ '2130'.
MOVE CORRESPONDING ITAB1 INTO ITAB.
append itab.
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;Naimesh Patel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2007 13:22:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982886#M704275</guid>
      <dc:creator>naimesh_patel</dc:creator>
      <dc:date>2007-10-26T13:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: collect statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982887#M704276</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi gautam,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try like this...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT ITAB1 where WERKS NE '2130'.&lt;/P&gt;&lt;P&gt;MOVE CORRESPONDING ITAB1 INTO ITAB.&lt;/P&gt;&lt;P&gt;COLLECT ITAB.&lt;/P&gt;&lt;P&gt;ENDLOOP. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and can you to tell me what are all other fields in itab1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: &lt;/P&gt;&lt;P&gt;        Perez C&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2007 13:24:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982887#M704276</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-26T13:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: collect statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982888#M704277</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT ITAB1 where WERKS &amp;lt;&amp;gt; '2130'.&lt;/P&gt;&lt;P&gt;MOVE CORRESPONDING ITAB1 INTO ITAB.&lt;/P&gt;&lt;P&gt;COLLECT ITAB.&lt;/P&gt;&lt;P&gt;ENDLOOP. &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>Fri, 26 Oct 2007 13:24:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982888#M704277</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-26T13:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: collect statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982889#M704278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gautam,&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT ITAB1 where WERKS NE '2130'.&lt;/P&gt;&lt;P&gt;MOVE CORRESPONDING ITAB1 INTO ITAB.&lt;/P&gt;&lt;P&gt;COLLECT ITAB.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward if Useful&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Chitra&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2007 13:25:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982889#M704278</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-26T13:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: collect statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982890#M704279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you can not move both branches into itab&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT itab1.
  IF itab1-werks NE '2130'. 
    MOVE CORRESPONDING itab1 INTO itab.
    COLLECT itab.
  ELSE.
    MOVE CORRESPONDING itab1 INTO itab2.
    APPEND itab2.
  ENDIF.
ENDLOOP.

APPEND LINES OF itab2 to itab. 
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yours did not work because there is no append for the else branch.&lt;/P&gt;&lt;P&gt;And the Collect does not like it if you change the table itab with other &lt;/P&gt;&lt;P&gt;command. The collect will then becomes extremely slow (implicit hashed &lt;/P&gt;&lt;P&gt;key is destroyed) !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2007 13:48:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982890#M704279</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-26T13:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: collect statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982891#M704280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;be aware, the solution above with the 2 loops at WHERE is slower as the single loop!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is because the LOOP AT WHERE can not find efficiently the lines fulfilling the WHERE condition. For a standard table no sort order can be assumed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2007 15:22:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/2982891#M704280</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-26T15:22:58Z</dc:date>
    </item>
  </channel>
</rss>

