<?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: Help with a COLLECT statement. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568707#M858860</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Chandrasekhar, it doesn't work in my case and it did work, and suit my requirements, before I added fields to the table.  This has been working since 2003.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;venkat, thanks for that but how can I give the table a header line?  If I can't give it a header line then I will have to make more changes than I want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Davis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Mar 2008 14:48:36 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-03-28T14:48:36Z</dc:date>
    <item>
      <title>Help with a COLLECT statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568703#M858856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I had to make changes to some code and these changes required me to add some fields to an internal table.  Below is what the table looked like before I made any changes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : BEGIN OF t_frgroup OCCURS 0,&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    BEGIN CHANGE 02/11/03 &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;        hazmat       TYPE c,&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    END CHANGE 02/11/03 &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;        mfrgr        LIKE lips-mfrgr,&lt;/P&gt;&lt;P&gt;        brgew        LIKE lips-brgew,&lt;/P&gt;&lt;P&gt;        lfimg        LIKE lips-lfimg,&lt;/P&gt;&lt;P&gt;        qtypal       LIKE w_nbr_palletsx,&lt;/P&gt;&lt;P&gt;        qtypce       LIKE w_nbr_palletsx,&lt;/P&gt;&lt;P&gt;        vstel        LIKE likp-vstel,&lt;/P&gt;&lt;P&gt;        no_cnvrt     TYPE c,&lt;/P&gt;&lt;P&gt;END OF t_frgroup.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what it looked like after I made the changes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : BEGIN OF t_frgroup OCCURS 0,&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    BEGIN CHANGE 02/11/03&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;        hazmat       TYPE c,&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    END CHANGE 02/11/03&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;        mfrgr        LIKE lips-mfrgr,&lt;/P&gt;&lt;P&gt;        brgew        LIKE lips-brgew,&lt;/P&gt;&lt;P&gt;        lfimg        LIKE lips-lfimg,&lt;/P&gt;&lt;P&gt;        qtypal       LIKE w_nbr_palletsx,&lt;/P&gt;&lt;P&gt;        qtypce       LIKE w_nbr_palletsx,&lt;/P&gt;&lt;P&gt;        vstel        LIKE likp-vstel,&lt;/P&gt;&lt;P&gt;        no_cnvrt     TYPE c,&lt;/P&gt;&lt;P&gt;        matnr        TYPE lips-matnr,&lt;/P&gt;&lt;P&gt;        vbeln        TYPE lips-vbeln,&lt;/P&gt;&lt;P&gt;        posnr        TYPE lips-posnr,&lt;/P&gt;&lt;P&gt;        qty          LIKE vblkp-lfimg,&lt;/P&gt;&lt;P&gt;        vrkme        LIKE lips-vrkme,&lt;/P&gt;&lt;P&gt;        converted(1) TYPE c VALUE 'N',&lt;/P&gt;&lt;P&gt;END OF t_frgroup.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My issue is, after adding those fields, my collect statement no longer works:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      LOOP AT t_lips.&lt;/P&gt;&lt;P&gt;        MOVE-CORRESPONDING t_lips TO t_frgroup.&lt;/P&gt;&lt;P&gt;        COLLECT t_frgroup.&lt;/P&gt;&lt;P&gt;      ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need it to collect with the key being mfrgr.  How can I do this?  After adding the fields the collect statement now acts as an insert (I assume that matnr is now acting as the key) instead of collect.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Aaron&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2008 14:36:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568703#M858856</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-28T14:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: Help with a COLLECT statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568704#M858857</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;check this ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF seats, &lt;/P&gt;&lt;P&gt;        carrid   TYPE sflight-carrid, &lt;/P&gt;&lt;P&gt;        connid   TYPE sflight-connid, &lt;/P&gt;&lt;P&gt;        seatsocc TYPE sflight-seatsocc, &lt;/P&gt;&lt;P&gt;      END OF seats. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA seats_tab LIKE HASHED TABLE OF seats &lt;/P&gt;&lt;P&gt;               WITH UNIQUE KEY carrid connid. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT carrid connid seatsocc &lt;/P&gt;&lt;P&gt;       FROM sflight &lt;/P&gt;&lt;P&gt;       INTO seats. &lt;/P&gt;&lt;P&gt;  COLLECT seats INTO seats_tab. &lt;/P&gt;&lt;P&gt;ENDSELECT. &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>Fri, 28 Mar 2008 14:41:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568704#M858857</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-28T14:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Help with a COLLECT statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568705#M858858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi  Davis,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     COLLECT statement  will work pefectly in your case , but that will not suit your requirement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    you need to use  AT END OF &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT t_lips.
   MOVE-CORRESPONDING t_lips TO t_frgroup.
  append t_frgroup.
ENDLOOP.

SORT T_FRGROUP BY MFRGR.

loop at t_frgroup.
  at end of  MFRGR.
     SUM.
   ENDAT.
ENDLOOP.  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2008 14:44:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568705#M858858</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-28T14:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: Help with a COLLECT statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568706#M858859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Aaron,&lt;/P&gt;&lt;P&gt;1. Define the table keys while defining your internal table.&lt;/P&gt;&lt;P&gt;2. The order of the fields in the structure should be that the key fields come first , then the quantity fields and amount fields next. &lt;/P&gt;&lt;P&gt;3. Sort the table by the key fields before the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The collect statment is creating news entries because If the system finds an entry with the key fields , the numeric fields that are not part of the table key are added to the sum total of the existing entries. If it does not find an entry, the system creates a new entry instead. Clearly the system is unable to find the existing entry because the key fields are not defined in your internal table or the fields are are out of order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A simple example depicting this is as follows :&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
TYPES: BEGIN OF COMPANY, 
        NAME(20) TYPE C, 
        SALES    TYPE I, 
      END OF COMPANY. 

DATA: COMP    TYPE COMPANY, 
      COMPTAB TYPE HASHED TABLE OF COMPANY 
                                WITH UNIQUE KEY NAME. 

COMP-NAME = 'Duck'.  COMP-SALES = 10. COLLECT COMP INTO COMPTAB. 
COMP-NAME = 'Tiger'. COMP-SALES = 20. COLLECT COMP INTO COMPTAB. 
COMP-NAME = 'Duck'.  COMP-SALES = 30. COLLECT COMP INTO COMPTAB. 

&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;Advait Gode.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Advait Gode on Mar 28, 2008 3:50 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2008 14:48:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568706#M858859</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-28T14:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: Help with a COLLECT statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568707#M858860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Chandrasekhar, it doesn't work in my case and it did work, and suit my requirements, before I added fields to the table.  This has been working since 2003.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;venkat, thanks for that but how can I give the table a header line?  If I can't give it a header line then I will have to make more changes than I want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Davis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2008 14:48:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568707#M858860</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-28T14:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: Help with a COLLECT statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568708#M858861</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The COLLECT will compare fields of the header of t_frgroup with corresponding fields in the internal table that are not of type P,I and F when trying to do a collect and then either insert a new line or add the PIF type fields to each other.  Since you added at least one new C type field you have effectively modified the key of the table.  You can avoid the problem by delcaring your internal table with an explicit unique key(mfrgr) as was suggested by an earlier post.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards &lt;/P&gt;&lt;P&gt;Greg Kern&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2008 14:50:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568708#M858861</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-28T14:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: Help with a COLLECT statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568709#M858862</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Davis,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      Yes its true that it worked perfectly before&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      but now after adding some more fields it will not work the same way as it worked before &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     COLLECT  will sum up the numeric fields when the character fields are same , so in this case the newly added field values may be different&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2008 14:51:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568709#M858862</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-28T14:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Help with a COLLECT statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568710#M858863</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Chandrasekhar, thanks for that explanation.  So, because the material number is different it won't sum.  OK, back to the drawing board.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Davis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2008 14:53:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568710#M858863</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-28T14:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: Help with a COLLECT statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568711#M858864</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;*Collect statement inserts the contents of a work area wa either as single row into an internal table itab or adds the &lt;/P&gt;&lt;P&gt;values of its numeric components to the corresponding values &lt;/P&gt;&lt;P&gt;of existing rows with the same key*  ... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your case ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(I need it to collect with the key being mfrgr. How can I do &lt;/P&gt;&lt;P&gt;this? After adding the fields the collect statement now acts as &lt;/P&gt;&lt;P&gt;an insert (I assume that matnr is now acting as the key) &lt;/P&gt;&lt;P&gt;instead of collect. )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think MATNR is changing and a new record is being inserted&lt;/P&gt;&lt;P&gt;into the internal table ...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2008 14:53:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568711#M858864</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-28T14:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: Help with a COLLECT statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568712#M858865</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Greg,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I declare the table, with a key, while preserving the header line?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Davis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2008 14:54:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/help-with-a-collect-statement/m-p/3568712#M858865</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-28T14:54:41Z</dc:date>
    </item>
  </channel>
</rss>

