<?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 error in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-error/m-p/1079984#M97506</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. As u have said, u want totals&lt;/P&gt;&lt;P&gt;   per cuenta (only cuenta)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. do somewhat like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. Declare ITAB1 having CUENTA, and other number fields&lt;/P&gt;&lt;P&gt;   (for whom u want total)&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;4. Declare another table, same as ITAB1 &lt;/P&gt;&lt;P&gt;   (say SUMTAB, for collect purpose)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;5. Now Loop at your original table i_tran2 .&lt;/P&gt;&lt;P&gt;   CLEAR ITAB1.&lt;/P&gt;&lt;P&gt;   MOVE-CORRESPONDING I_TRAN2 TO ITAB1.&lt;/P&gt;&lt;P&gt;   APPEND ITAB1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;6. NOW FINALLY,&lt;/P&gt;&lt;P&gt;   Loop at itab1.&lt;/P&gt;&lt;P&gt;   collect itab1 into sumtab.&lt;/P&gt;&lt;P&gt;   endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will achieve what u want.&lt;/P&gt;&lt;P&gt;I have tried such thing &lt;/P&gt;&lt;P&gt;and it works fantastic.&lt;/P&gt;&lt;P&gt;&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;amit m.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 24 Dec 2005 04:40:31 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-12-24T04:40:31Z</dc:date>
    <item>
      <title>Collect statement error</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-error/m-p/1079981#M97503</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;&lt;/P&gt;&lt;P&gt;i have the fallowing problem.&lt;/P&gt;&lt;P&gt;I'm trying to do a collect statement as fallow:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SORT i_tran BY cuenta ASCENDING.
LOOP AT i_tran.             
                            
AT NEW cuenta.              
COLLECT i_tran INTO i_tran2.
APPEND i_tran2.             
CLEAR i_tran.               
CLEAR i_tran2.              
ENDAT.                      
endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where i_tran is a collect internal table and i_tran2 is another internal table.&lt;/P&gt;&lt;P&gt;when I execute the collect statement all the fields are fill with asterics and the field that Im interested in is set to zero.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;another problem is that is not doing the collect per cuenta. (is doing it per record, ex. if cuenta 123 has three records it executes at the collect statement for each one of them.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this is the structure of i_tran:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;* Registro de Transacciones
TYPES: BEGIN OF E_TRAN,
      RECTYPE TYPE C,             "Tipo Registro N
      CCODE(15) TYPE C,           "Id Empresa (RNC)
      SEQNR(7) TYPE C,            "Secuencia Header
      SECTR(7) TYPE C,            "Secuencia Transaccion
      CUENTA(20) TYPE C,          "Cuenta Suplidor
      MONTRN TYPE I,              "Montro Transaccion (13)
      TIPCTA TYPE C,              "Tipo de Cuenta
      WAERS(3) TYPE C,            "Moneda
      CODBAN(8) TYPE C,           "Banco Destino (No. Cuenta Banco)
      DIGVER TYPE C,              "Digito Verificacion
      CODOPR(2) TYPE C,           "Codigo Operacion
      TIPIDN(2) TYPE C,           "Tipo de Identificacion
      IDENTF(15) TYPE C,          "Identificacion
      NOMBRE(35) TYPE C,          "Nombre Beneficiario
      REFERN(12) TYPE C,          "Referencia
      DESCRED(40) TYPE C,         "Descripcion Estado Destino
      FECVEN(4) TYPE C,           "Fecha Vencimiento
      FCONTC TYPE C,              "Forma de Contacto
      EMAIL(40) TYPE C,           "E-mail Beneficiario
      NUMFAX(12) TYPE C,          "Numero de Fax
      RESERV(2) TYPE C,           "Reservado para uso futuro
      NUMAUT(15) TYPE C,          "Numero Autorizacion
      CODRET(3) TYPE C,           "Codigo Retorno Remoto
      CODRZR(3) TYPE C,           "Codigo Razon Remoto
      CODRZI(3) TYPE C,           "Codigo Razon Interno
      PROCTR TYPE C,              "Procesador Transaccion
      STATS(2) TYPE C,            "Status Transaccion
      FILLER(52),                 "En blanco
END OF E_TRAN.
DATA: IT_TRAN TYPE  E_TRAN.
DATA: I_TRAN TYPE STANDARD TABLE OF E_TRAN WITH HEADER LINE,
      I_TRAN2 TYPE STANDARD TABLE OF E_TRAN WITH HEADER LINE.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;if anyone can help me I'll appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks in advanced,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Gregorio.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Dec 2005 21:55:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-error/m-p/1079981#M97503</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-23T21:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Collect statement error</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-error/m-p/1079982#M97504</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gregorio,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have only one field 'MONTRN' in the table.. all the rest are CHAR fields.. I guess you want to total this field  for eahc 'CUENTA'. In that case, you don't need to use COLLECT (it is an expensive statement). Also, when you use AT NEW, you must ensure that the CHAR fields are to the left of the field you are controlling on.( this is the reason for the ASTERICS you see). In your type declaration, move the CUENTA as the  last field.You can then use the SUM statement. I manot logged into SAP, otherwise, I would have put in some code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Suresh Datti&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Dec 2005 22:15:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-error/m-p/1079982#M97504</guid>
      <dc:creator>suresh_datti</dc:creator>
      <dc:date>2005-12-23T22:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: Collect statement error</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-error/m-p/1079983#M97505</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gergorio,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. I think that the way you have used COLLECT&lt;/P&gt;&lt;P&gt;   is incorrect.&lt;/P&gt;&lt;P&gt;   (There is no need to use AT NEW for collect)&lt;/P&gt;&lt;P&gt;   (only Loop, Collect will do the work)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. U have said that :&lt;/P&gt;&lt;P&gt;   tran is a collect internal table and i_tran2 is   &lt;/P&gt;&lt;P&gt;   another internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. Meaning, that,&lt;/P&gt;&lt;P&gt;   i_trans2 has many records &lt;/P&gt;&lt;P&gt;   tran  is the SUMMARY table (to gather totals)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4. Now, on what base,&lt;/P&gt;&lt;P&gt;   do u want to do summary ?&lt;/P&gt;&lt;P&gt;   ie. What will be the key/main/criteria fields?&lt;/P&gt;&lt;P&gt;   (all char fields of your internal table,&lt;/P&gt;&lt;P&gt;    or some of them)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   (If only some are required, then your logic won't work)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;5. Moreover, we should have numeric/integer&lt;/P&gt;&lt;P&gt;   fields in our internal table so that  &lt;/P&gt;&lt;P&gt;   summation is done automatically.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;6. The simple logic is like this.&lt;/P&gt;&lt;P&gt;   LOOP AT DETAILITAB.&lt;/P&gt;&lt;P&gt;   COLLECT DETAILTAB INTO SUMMARYTAB.&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;7. The above will take care of &lt;/P&gt;&lt;P&gt;   all summations&lt;/P&gt;&lt;P&gt;   (with respect to DISTINCT COMBAINATION&lt;/P&gt;&lt;P&gt;    of ALL CHAR FIELDS)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;8. If your criteria for summation is&lt;/P&gt;&lt;P&gt;    less fields then some little more work&lt;/P&gt;&lt;P&gt;    is required. If this is so, let me know.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope it helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amit M.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 24 Dec 2005 04:35:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-error/m-p/1079983#M97505</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-24T04:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: Collect statement error</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-error/m-p/1079984#M97506</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. As u have said, u want totals&lt;/P&gt;&lt;P&gt;   per cuenta (only cuenta)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. do somewhat like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. Declare ITAB1 having CUENTA, and other number fields&lt;/P&gt;&lt;P&gt;   (for whom u want total)&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;4. Declare another table, same as ITAB1 &lt;/P&gt;&lt;P&gt;   (say SUMTAB, for collect purpose)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;5. Now Loop at your original table i_tran2 .&lt;/P&gt;&lt;P&gt;   CLEAR ITAB1.&lt;/P&gt;&lt;P&gt;   MOVE-CORRESPONDING I_TRAN2 TO ITAB1.&lt;/P&gt;&lt;P&gt;   APPEND ITAB1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;6. NOW FINALLY,&lt;/P&gt;&lt;P&gt;   Loop at itab1.&lt;/P&gt;&lt;P&gt;   collect itab1 into sumtab.&lt;/P&gt;&lt;P&gt;   endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will achieve what u want.&lt;/P&gt;&lt;P&gt;I have tried such thing &lt;/P&gt;&lt;P&gt;and it works fantastic.&lt;/P&gt;&lt;P&gt;&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;amit m.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 24 Dec 2005 04:40:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-error/m-p/1079984#M97506</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-24T04:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: Collect statement error</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-error/m-p/1079985#M97507</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;  when using AT NEW , u have to read the internal table&lt;/P&gt;&lt;P&gt;  IF U DONT USE READ STATEMENT , IT WILL DISPLAY AS ASTREIK.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  LOOP AT I_TRAN.&lt;/P&gt;&lt;P&gt;     L_TABIX = SY_TABIX.&lt;/P&gt;&lt;P&gt;     AT NEW cuenta.&lt;/P&gt;&lt;P&gt;       &amp;lt;b&amp;gt;READ TABLE i_tran index l_TABIX.&amp;lt;/b&amp;gt;     ENDAT.&lt;/P&gt;&lt;P&gt;  ENDLOOP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 24 Dec 2005 09:36:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-error/m-p/1079985#M97507</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-24T09:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: Collect statement error</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-error/m-p/1079986#M97508</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Change your code to this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SORT i_tran BY cuenta ASCENDING.
LOOP AT i_tran.
  COLLECT i_tran INTO i_tran2.
  CLEAR i_tran2.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or if for some reason, you need to do the collect only for new CUENTA, then you have to change your i_tran2 to have only two fields, CUENTA and MONTRN. This is the only way you can get the totals for unique CUENTA.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SORT i_tran BY cuenta ASCENDING.
LOOP AT i_tran.
  COLLECT i_tran INTO i_tran2.
  CLEAR i_tran2.              
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Srinivas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 24 Dec 2005 16:40:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/collect-statement-error/m-p/1079986#M97508</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-24T16:40:07Z</dc:date>
    </item>
  </channel>
</rss>

