<?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 not working properly in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123954#M1618703</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sorry but i did not understand , can yo uplease be more specific.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 16 Sep 2011 04:49:18 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2011-09-16T04:49:18Z</dc:date>
    <item>
      <title>Collect statement not working properly</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123951#M1618700</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;in the below code i used collect statement to collect data from 3 differnet internal tables and then display in one final table.&lt;/P&gt;&lt;P&gt;but in the output i am getting wrong values.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
 6609001
               10,000.00           23,819.04         23,819.04          2,601.00    " last 3 coloums are wrong values
 A5400   57,495.36           95,276.16         95,276.16         10,404.00    " last 3 coloums are wrong values
 28         67,495.36          119,095.20        119,095.20         13,005.00    " last 3 coloums are wrong values
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here is the code&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  ZTEMP13 no standard page heading LINE-SIZE 300.
  perform actual.
  CLEAR WA_BSEG.
  perform sply.
  CLEAR WA_BSEG1.
  perform lyac.
  CLEAR WA_BSEG2.
  perform TACT.
  CLEAR WA_BSEG3.
  perform pri_actual.
  perform final.
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  ACTUAL
FORM ACTUAL .
  SELECT hkont
  belnr
  gjahr
  KOSTL
  AUFNR
  BUKRS
  PSWBT
  WRBTR FROM BSEG
  INTO TABLE IT_BSEG
  WHERE GJAHR EQ S_GJAHR
  AND HKONT IN S_HKONT
  and kostl in s_kostl.
  IF not it_bseg[] IS INITIAL.
    SELECT belnr
    GJAHR
    MONAT
    BUKRS
    BUDAT FROM BKPF
    INTO TABLE IT_BKPF
    FOR ALL ENTRIES IN IT_BSEG
    WHERE MONAT eq s_monat
          AND belnr = it_BSEG-belnr
          AND GJAHR = it_BSEG-GJAHR
          AND BUKRS = it_BSEG-BUKRS.
  ENDIF.
ENDFORM.                    " ACTUAL
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  PRI_ACTUAL
FORM PRI_ACTUAL .
  sort it_bseg by hkont aufnr kostl pswbt.
  LOOP AT IT_BSEG INTO WA_BSEG.
    wa_coll-hkont = wa_bseg-hkont.
    wa_coll-aufnr = wa_bseg-aufnr.
    wa_coll-kostl = wa_bseg-kostl.
    wa_coll-pswbt = wa_bseg-pswbt.
    read table IT_BSEG1 INTO WA_BSEG1 with key hkont = wa_coll-hkont.
    wa_coll-hkont1 = wa_bseg1-hkont.
    wa_coll-aufnr1 = wa_bseg1-aufnr.
    wa_coll-kostl1 = wa_bseg1-kostl.
    wa_coll-pswbt1 = wa_bseg1-pswbt.
    read table IT_BSEG2 INTO WA_BSEG2 with key hkont = wa_coll-hkont.
    wa_coll-hkont2 = wa_bseg2-hkont.
    wa_coll-aufnr2 = wa_bseg2-aufnr.
    wa_coll-kostl2 = wa_bseg2-kostl.
    wa_coll-pswbt2 = wa_bseg2-pswbt.
    read table IT_BSEG3 INTO WA_BSEG3 with key hkont = wa_coll-hkont.
    wa_coll-hkont3 = wa_bseg3-hkont.
    wa_coll-aufnr3 = wa_bseg3-aufnr.
    wa_coll-kostl3 = wa_bseg3-kostl.
    wa_coll-pswbt3 = wa_bseg3-pswbt.
    collect wa_coll into it_coll.
    clear : wa_coll,wa_bseg3,wa_bseg2,wa_bseg1.
  endloop.
ENDFORM.                    " PRI_ACTUAL
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  SPLY
*&amp;amp;---------------------------------------------------------------------*
FORM SPLY .
  S_GJAHR1 = S_GJAHR - 1.
  SELECT hkont
  belnr
  gjahr
  KOSTL
  AUFNR
  BUKRS
  PSWBT
  WRBTR FROM BSEG
  INTO TABLE IT_BSEG1
  WHERE GJAHR EQ S_GJAHR1
  AND HKONT IN S_HKONT
  and kostl in s_kostl.
  IF not it_bseg1[] IS INITIAL.
    SELECT belnr
    GJAHR
    MONAT
    BUKRS
    BUDAT FROM BKPF
    INTO TABLE IT_BKPF1
    FOR ALL ENTRIES IN IT_BSEG1
    WHERE MONAT eq s_monat
          AND belnr = it_BSEG1-belnr
          AND GJAHR = it_BSEG1-GJAHR
          AND BUKRS = it_BSEG1-BUKRS.
  endif.
  clear s_gjahr1.
ENDFORM.                    " SPLY
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  LYAC
FORM LYAC .

  S_GJAHR1 = S_GJAHR - 1.

  SELECT gjahr
         hkont
         KOSTL
         AUFNR
         BUKRS
         PSWBT
         belnr
         WRBTR FROM BSEG
         INTO TABLE IT_BSEG2
         WHERE GJAHR EQ S_GJAHR1
         AND   HKONT IN S_HKONT
         and   kostl in s_kostl.
  clear s_gjahr1.
ENDFORM.                    " LYAC
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  TACT
FORM TACT .
  SELECT hkont
         belnr
         gjahr
         KOSTL
         AUFNR
         BUKRS
         PSWBT
         WRBTR FROM BSEG
         INTO TABLE IT_BSEG3
         WHERE GJAHR EQ S_GJAHR
         AND HKONT IN S_HKONT
         and kostl in s_kostl.

  IF not it_bseg3[] IS INITIAL.
    SELECT belnr
           GJAHR
           MONAT
           BUKRS
           BUDAT FROM BKPF
           INTO TABLE IT_BKPF3
           FOR ALL ENTRIES IN IT_BSEG3
           WHERE MONAT gt 0 and monat le s_monat
           AND belnr = it_BSEG3-belnr
           AND GJAHR = it_BSEG3-GJAHR
           AND BUKRS = it_BSEG3-BUKRS.
  ENDIF.
ENDFORM.                    " TACT
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN __default_attr="red" __jive_macro_name="color"&gt;Moderator message : Duplicate post locked. Continue with Original thread : [collect statement not working properly |&lt;A class="jive_macro jive_macro_thread" href="https://community.sap.com/" __jive_macro_name="thread" modifiedtitle="true" __default_attr="2037308"&gt;&lt;/A&gt;;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Vinod Kumar on Sep 16, 2011 1:38 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Sep 2011 04:32:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123951#M1618700</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-09-16T04:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: Collect statement not working properly</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123952#M1618701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  FINAL
FORM FINAL .
  data: lv_index type sy-tabix.
  sort it_coll by HKONT kostl aufnr.
  loop at it_coll into wa_coll.
    lv_index = sy-tabix.
    at new hkont.
      NEW-PAGE.
      write:1 sy-uline(90).
      write:/1 sy-vline(1),
             2 wa_coll-HKONT COLOR 3.
    endat.
    at new aufnr.
      sum.
      write:90 sy-vline(1).
      write:/1 sy-uline(90),
            /1 sy-vline(1),
             2 wa_coll-aufnr color 1,
            10 wa_coll-pswbt,
            30 wa_coll-pswbt1,
            48 wa_coll-pswbt2,
            66 wa_coll-pswbt3,
            90 sy-vline(1).
    endat.
    AT END OF hkont.
      read table it_coll into wa_coll index lv_index.
      write:/1 sy-uline(90),
            /1 sy-vline(1),
             2 wa_coll-kostl,
            90 sy-vline(1).
    endat.
    at end of hkont.
      sum.
      write:10 wa_coll-pswbt.
      write:30 wa_coll-pswbt1.
      write:48 wa_coll-pswbt2.
      write:66 wa_coll-pswbt3.
      write:/1 sy-uline(90).
    endat.
    CLEAR WA_COLL.
  endloop.
ENDFORM.                    " FINAL
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Kindly please suggest me,&lt;/P&gt;&lt;P&gt;thanks in advance,&lt;/P&gt;&lt;P&gt;ben.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Sep 2011 04:33:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123952#M1618701</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-09-16T04:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Collect statement not working properly</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123953#M1618702</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;Have you declared all non numeric fields as a key fields for hashed table where you are collecting the values?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g. if you want to collect values in field c and table having fields a b c d then a,b and d has to be key fields of hashed tables so for primary key of a,b and d values will be collected in C.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i.e. suppose internal table has values a = name1, b = name2 and d = name3 C = 100&lt;/P&gt;&lt;P&gt;                                                             a = name1, b = name2 and d = name3 C = 10&lt;/P&gt;&lt;P&gt;                                                             a = x1      , b =  name2 and d = name3 C = 10&lt;/P&gt;&lt;P&gt;                                                             a = name1, b = X2        and d = X3       C = 10&lt;/P&gt;&lt;P&gt;                                                             a = name1, b = name2 and d = name3 C = 20&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Final output in hashed table would be  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;name1   name2   130   name3&lt;/P&gt;&lt;P&gt;  X1       name2   10     name3&lt;/P&gt;&lt;P&gt;name1   X2         10     X3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it is clear to you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Sep 2011 04:42:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123953#M1618702</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-09-16T04:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: Collect statement not working properly</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123954#M1618703</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sorry but i did not understand , can yo uplease be more specific.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Sep 2011 04:49:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123954#M1618703</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-09-16T04:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Collect statement not working properly</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123955#M1618704</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you please be more specific?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Sep 2011 06:20:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123955#M1618704</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-09-16T06:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: Collect statement not working properly</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123956#M1618705</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The design of your internal table is important for COLLECT statement to work correctly. Few things to note-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. All fields that are of 'Character Nature' automatically become the key of internal table, i.e. against their unique combination the numeric values get added, there by leaving a single line in the internal table against a unique combination of key fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. All fields of type C(CHAR) and N(NUMC) are treated as character fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. In the internal table declaration, these fields must appear from the begining. After all character natured fields, all numeric fields should be declared.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Begin of it_tab occurs 0, &lt;/P&gt;&lt;P&gt;   field1(4) type c,&lt;/P&gt;&lt;P&gt;   field2(2) type n,&lt;/P&gt;&lt;P&gt;   field3(6) type c,&lt;/P&gt;&lt;P&gt;   field4(4) type n,&lt;/P&gt;&lt;P&gt;   menge like  mseg-menge,&lt;/P&gt;&lt;P&gt;End of it_tab.                      " This will give right results&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Begin of it_tab occurs 0,&lt;/P&gt;&lt;P&gt;   field1(4) type c,&lt;/P&gt;&lt;P&gt;   field2(2) type n,&lt;/P&gt;&lt;P&gt;   field3(6) type c,&lt;/P&gt;&lt;P&gt;   menge like  mseg-menge,&lt;/P&gt;&lt;P&gt;   field4(4) type n,&lt;/P&gt;&lt;P&gt;End of it_tab.                      " The result won't be appropriate&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Sep 2011 07:15:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123956#M1618705</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-09-16T07:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Collect statement not working properly</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123957#M1618706</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks for your reply&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;now wat to do in my code?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Sep 2011 07:36:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-not-working-properly/m-p/8123957#M1618706</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-09-16T07:36:02Z</dc:date>
    </item>
  </channel>
</rss>

