<?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/12660040#M2015591</link>
    <description>&lt;P&gt;As &lt;SPAN class="mention-scrubbed"&gt;frdric.girod&lt;/SPAN&gt; suggested, the documentation helps.&lt;/P&gt;&lt;P&gt;COLLECT will use all alphanumeric fields as key and sum all numeric fields, no questions asked. If you need finer control over either key or sum, then code it explicitly.&lt;/P&gt;</description>
    <pubDate>Fri, 18 Nov 2022 07:09:28 GMT</pubDate>
    <dc:creator>abo</dc:creator>
    <dc:date>2022-11-18T07:09:28Z</dc:date>
    <item>
      <title>Collect Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660038#M2015589</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
  &lt;P&gt; In internal table 'gt_item' I have got all the values by line item wise, client requirement to merge the feilds if the (vbeln-d,tline,steuc,cmpre) are same , for that I used the 'Collect' statement, the issue is 'GST' % also got merged, kindly provide the solution&lt;/P&gt;
  &lt;P&gt; LOOP AT gt_item INTO gs_item.&lt;/P&gt;
  &lt;BR /&gt; gs_item1-vbeln_d4 = gs_item-vbeln_d.
  &lt;BR /&gt; gs_item1-tline4 = gs_item-tline.
  &lt;BR /&gt; gs_item1-steuc4 = gs_item-steuc.
  &lt;BR /&gt; gs_item1-qty4 = gs_item-qty.
  &lt;BR /&gt; gs_item1-mtr4 = gs_item-mtr.
  &lt;BR /&gt; gs_item1-cmpre4 = gs_item-cmpre.
  &lt;BR /&gt; gs_item1-cgst4 = gs_item-cgst.
  &lt;BR /&gt; gs_item1-sgst4 = gs_item-sgst.
  &lt;BR /&gt; gs_item1-igst4 = gs_item-igst.
  &lt;BR /&gt; gs_item1-cgst_amt4 = gs_item-cgst_amt.
  &lt;BR /&gt; gs_item1-sgst_amt4 = gs_item-sgst_amt.
  &lt;BR /&gt; gs_item1-igst_amt4 = gs_item-igst_amt.
  &lt;BR /&gt;
  &lt;BR /&gt; COLLECT gs_item1 INTO gt_item1.
  &lt;BR /&gt; CLEAR gs_item1.
  &lt;BR /&gt;
  &lt;P&gt; ENDLOOP.&lt;/P&gt;
  &lt;P&gt;** Invioce has 10 line items each contains 2.5% cgst and 2.5% sgst&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2115450-image.png" /&gt;&lt;/P&gt;
  &lt;P&gt;** The final result has attached below for your reference&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2115451-image.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 06:12:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660038#M2015589</guid>
      <dc:creator>thangeswaran</dc:creator>
      <dc:date>2022-11-18T06:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: Collect Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660039#M2015590</link>
      <description>&lt;P&gt;Do you read the documentastion ? &lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 06:56:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660039#M2015590</guid>
      <dc:creator>FredericGirod</dc:creator>
      <dc:date>2022-11-18T06:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: Collect Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660040#M2015591</link>
      <description>&lt;P&gt;As &lt;SPAN class="mention-scrubbed"&gt;frdric.girod&lt;/SPAN&gt; suggested, the documentation helps.&lt;/P&gt;&lt;P&gt;COLLECT will use all alphanumeric fields as key and sum all numeric fields, no questions asked. If you need finer control over either key or sum, then code it explicitly.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 07:09:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660040#M2015591</guid>
      <dc:creator>abo</dc:creator>
      <dc:date>2022-11-18T07:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: Collect Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660041#M2015592</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;As per SAP Help documentation of &lt;A href="https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapcollect.htm" target="_blank"&gt;COLLECT&lt;/A&gt; statement:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;This statement inserts the content of a work area wa either as a single row in an internal table itab or &lt;STRONG&gt;adds the values of its numeric components to the corresponding values of existing rows with the same primary table key&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Looks like CGST4 and SGST4 fields are numeric and they got summarized as described in the documentation. The COLLECT statement worked as expected.&lt;/P&gt;&lt;P&gt;What are you trying to achieve?&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Dominik Tylczynski&lt;/P&gt;&lt;P&gt;&lt;I&gt;&lt;/I&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 07:26:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660041#M2015592</guid>
      <dc:creator>Dominik_Tylczynski</dc:creator>
      <dc:date>2022-11-18T07:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: Collect Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660042#M2015593</link>
      <description>&lt;P&gt;Use CODE formatting when sharing ABAP code:&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2116448-image.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 07:26:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660042#M2015593</guid>
      <dc:creator>Dominik_Tylczynski</dc:creator>
      <dc:date>2022-11-18T07:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Collect Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660043#M2015594</link>
      <description>&lt;P&gt;Please edit your question, select your code and click the button below, otherwise it's a pain to read it:&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2113458-image.png" /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT gt_item INTO gs_item.

  gs_item1-vbeln_d4 = gs_item-vbeln_d.
  gs_item1-tline4 = gs_item-tline.
  gs_item1-steuc4 = gs_item-steuc.
  gs_item1-qty4 = gs_item-qty.
  gs_item1-mtr4 = gs_item-mtr.
  gs_item1-cmpre4 = gs_item-cmpre.
  gs_item1-cgst4 = gs_item-cgst.
  gs_item1-sgst4 = gs_item-sgst.
  gs_item1-igst4 = gs_item-igst.
  gs_item1-cgst_amt4 = gs_item-cgst_amt.
  gs_item1-sgst_amt4 = gs_item-sgst_amt.
  gs_item1-igst_amt4 = gs_item-igst_amt.

  COLLECT gs_item1 INTO gt_item1.
  CLEAR gs_item1.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Nov 2022 08:27:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660043#M2015594</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-11-18T08:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: Collect Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660044#M2015595</link>
      <description>&lt;P&gt;As already mentioned by the others. Collect sums up all numerical values in the structure. But you might try something like this, to calculate only the fields necessary:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF ty_tap,
         lgnum TYPE ltap-lgnum,
         tanum TYPE ltap-tanum,
         vsolm TYPE ltap-vsolm,
         brgew TYPE ltap-brgew,
       END OF ty_tap.

TYPES: ty_t_tap TYPE HASHED TABLE OF ty_tap WITH UNIQUE KEY lgnum tanum.
DATA: lt_result TYPE ty_t_tap.
SELECT lgnum, tanum, tapos, vsolm, brgew FROM ltap UP TO 1000 ROWS INTO TABLE @DATA(lt_ltap) WHERE lgnum = 101.
"Loop at group
LOOP AT lt_ltap ASSIGNING FIELD-SYMBOL(&amp;lt;fs_grp&amp;gt;) GROUP BY ( lgnum = &amp;lt;fs_grp&amp;gt;-lgnum
                                                            tanum = &amp;lt;fs_grp&amp;gt;-tanum
   ) ASCENDING REFERENCE INTO DATA(grp_ref).

  "Calculate subtotals
  DATA(ls_result) = REDUCE ty_tap( INIT result = VALUE ty_tap( lgnum = grp_ref-&amp;gt;lgnum
                                                          tanum = grp_ref-&amp;gt;tanum
                                                          vsolm = CONV ltap_vsolm( 0 )
                                                          brgew = CONV ltap_brgew( 0 ) )
                                  FOR ls_ltap IN lt_ltap WHERE ( lgnum = grp_ref-&amp;gt;lgnum
                                                                 AND tanum = grp_ref-&amp;gt;tanum )
                                     NEXT result-vsolm = result-vsolm + ls_ltap-vsolm
                                          result-brgew = result-brgew + ls_ltap-brgew
                                     ).
  "Append subtotals to new table
  INSERT ls_result INTO TABLE lt_result.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Nov 2022 14:16:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660044#M2015595</guid>
      <dc:creator>BH91976</dc:creator>
      <dc:date>2022-11-18T14:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Collect Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660045#M2015596</link>
      <description>&lt;P&gt;Or maybe even better, it might be that you have to add your sgs4 to the group by:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;lt_result1 = VALUE #( FOR GROUPS grp OF ls_ltap IN lt_ltap GROUP BY ( lgnum = ls_ltap-lgnum
                                                                      tanum = ls_ltap-tanum ) ASCENDING
                      ( REDUCE ty_tap( INIT result = VALUE ty_tap( lgnum = grp-lgnum
                                                                   tanum = grp-tanum
                                                                   vsolm = CONV ltap_vsolm( 0 )                                                                       
                                                                   brgew = CONV ltap_brgew( 0 ) 
                                      )
                                      FOR ls_ltap1 IN lt_ltap WHERE ( lgnum = grp-lgnum 
                                                                      AND tanum    = grp-tanum )
                                            NEXT result-vsolm = result-vsolm + ls_ltap1-vsolm
                                                 result-brgew = result-brgew + ls_ltap1-brgew )                                             
                       )

                    ).&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Nov 2022 14:42:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660045#M2015596</guid>
      <dc:creator>BH91976</dc:creator>
      <dc:date>2022-11-18T14:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: Collect Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660046#M2015597</link>
      <description>&lt;P&gt;Either use up to date syntax as already posted (values/group by) or just define the target table as a sorted or hashed table with those numeric fields part of the primary key of the table.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 15:22:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement/m-p/12660046#M2015597</guid>
      <dc:creator>RaymondGiuseppi</dc:creator>
      <dc:date>2022-11-18T15:22:01Z</dc:date>
    </item>
  </channel>
</rss>

