Sum group records in itab

How can I sum up into one record the records in itab.
ex.
group amount
0001    50
0001    60
0003    10
0004    10
0004    20
should be:
group amount
0001   110
0003    10
0004    30

Hi Adrian,
Take another internal table <b>ITAB1</b> and use following code:
<b>LOOP AT ITAB INTO ITAB1.
COLLECT ITAB1.
ENDLOOP.</b>
Here at the end ITAB1 will be having your desired result.
This will definitely help you.
Regards,
Pragya

Similar Messages

  • Want to get sum/avg first 90% records  in each grouped record set.

    Hi Gurus,
    Need your help or example query which help me to achieve sum/avg first 90% records in each grouped record set. Let me show you the basic query and output and proposed output.
    select Pid, Sum(SalesAmt) TotalSaleAmt, Avg(SalesAmt) AvgSaleAmt, count(*) NoOfSales from ProductSales group by Pid;
    PID TotalSaleAmt AvgSaleAmt NoOfSales
    1 12000 100 120
    2 24000 50 480
    Now I need for PID =1 TotalSaleAmt of first 90% of NoOfSale i.e.120(this is basically nuber of rows found in PrdocutSales Table).
    I hope I am clear enough explain my requirement... I would appreciate if we have some Analytical function available..
    Gurus Pls help me asap..
    Thanks In adavance...
    Srichan.

    Now I need for PID =1 TotalSaleAmt of first 90% of NoOfSale i.e.120(this is basically nuber of rows found in PrdocutSales Table).
    first 90% should mean first 90% by some order, so in this case, which 108 rows (of the 120) do you want to take into consideration?
    with
    the_sample as
    (select 1 the_pid,10 the_sale,1 the_order from dual union all
    select 1 the_pid,20 the_sale,2 the_order from dual union all
    select 1 the_pid,15 the_sale,3 the_order from dual union all
    select 1 the_pid,12 the_sale,4 the_order from dual union all
    select 1 the_pid,12 the_sale,5 the_order from dual union all
    select 1 the_pid,13 the_sale,6 the_order from dual union all
    select 1 the_pid,19 the_sale,7 the_order from dual union all
    select 1 the_pid,11 the_sale,8 the_order from dual union all
    select 1 the_pid,15 the_sale,9 the_order from dual union all
    select 1 the_pid,12 the_sale,10 the_order from dual union all
    select 2 the_pid,25 the_sale,1 the_order from dual union all
    select 2 the_pid,22 the_sale,2 the_order from dual union all
    select 2 the_pid,22 the_sale,3 the_order from dual union all
    select 2 the_pid,23 the_sale,4 the_order from dual union all
    select 2 the_pid,29 the_sale,5 the_order from dual union all
    select 2 the_pid,21 the_sale,6 the_order from dual union all
    select 2 the_pid,25 the_sale,7 the_order from dual union all
    select 2 the_pid,22 the_sale,8 the_order from dual
    select the_pid,the_sum,the_avg
      from (select the_pid,
                   sum(the_sale) over (partition by the_pid order by the_order) the_sum,
                   round(avg(the_sale) over (partition by the_pid order by the_order),2) the_avg,
                   the_order,
                   floor((0.9 * max(the_order) over (partition by the_pid))) to_pick
              from the_sample
    where the_order = to_pickRegards
    Etbin

  • GroupFilter and sum(); filtered records should not be included in the sum()

    Hi All,
    I am working on a report that has the following requirement.
    1. Query records from the database (multiple queries)
    2. Filter records based on a certain criteria.
    3. Sum() the rows.
    4. Cannot use where clause because of the complexity of the report.
    I have achieved the above requirement using data-template with one exception where my sum() is including all the filtered rows in the summation. I DO NOT want the filtered rows to be included in the sum(). I know I could do sum() in layout-template using xslt.
    Is there a way to do this in data-template?
    My data-template looks something like
    <group name="g_dept" source="q_dept">
        <element name="dname" value="dname"/>
        <element name="d_salary" value="g_emp.salary" function="sum()"/>
        <group name="g_emp" source="q_emp" groupFilter="filterEmployees(:empno)">
           <element name="ename" value="ename"/>
           <element name="empno" value="empno"/>
           <element name="salary" value="salary"/>
        </group>
    </group>
    My data looks like
    10    Scott1    7865    $100
    10    Scott2    6875    $200
    10    Scott3    5678    $300
    10    Scott4    8657    $500 <-- filtered with pl/sql package
    My output should look like
    Dept: 10
    Scott1    7865    $100
    Scott2    6875    $200
    Scott3    5678    $300
    Total for 10: $600
    instead my output looks like
    Total for 10: $1100 <-- including filtered row Steve.
    Is this a feature or a bug in the data-template? not sure the order of events querying, filtering & summation. If anyone could answer, I really appreciate it.
    Thanks

    Was there ever an answer the original question with the groupfilter and sum()?
    I have a GL Report (bi pub 5.6.3 with ebusiness suite 11.5.10.2) that uses the oracle.apps.fnd.flex.kff.select (with security as the output type). In my lowest group (lines) i have a group filter that eliminates the row if the security is Y (to eliminate it from the XML and report). However, the sums that I'm doing are including all rows, not just the ones included in the data file.
    I too have the same issue as Kalagara, where I can't use the where clause to exclude the rows.
    Thanks - Jennifer

  • How Journal Import groups records from GL_INTERFACE into Journal Headers

    Hello,
    Does anyone know how or using what criteria the Journal Import program groups records from the GL_INTERFACE into Journal Entries?
    The R12 User Guide says that :
    REFERENCE4 (Journal entry name): Enter a journal entry name for your journal entry.
    Journal Import creates a default journal entry name using the following format:
    (Category Name) (Currency) (Encumbrance Type ID, if applicable) (Currency
    Conversion Rate, if applicable) (Currency Conversion Date, if applicable) (Originating
    Balancing Segment Value), chopped to the first 100 characters. If the above results in
    multiple journals in the same batch with the same name, then additional characters are
    chopped off, and a 2, 3, 4, and so on, is added for the second, third, fourth, journals with
    the same name.
    Does it mean that for every unique combination of Category+Currency+CurrencyConversion Rate+Currency Conversion Date, a Journal Header would be created? I also found that although not mentioned in the user guide, if the Accounting Date within a group of records is different, the import program includes accounting date to the above criteria and tries to create separate Journal headers per Accounting Date.
    Also, is there a way to override this ( Category+Currency+CurrencyConversion Rate+Currency Conversion Date) criteria?
    Thanks,
    Manish

    any suggessions on the above query?
    Thanks & regards
    Aboo

  • How to calculate Sum of records that are not Suppressed

    Hi All Experts,
    I have Created A layout for SAP B1 in crystal report.Because of Some Condition I have  to Suppress Detail Section.
    The Suppress Condition is As Follows
    {ExcisePur.ItemCode}=Previous({ExcisePur.ItemCode}) And {ExcisePur.Batchnum}=Previous({ExcisePur.Batchnum})
    And it is Working Fine,the Desired Detail Section is Suppressed.
    Now I Have to take Sum of Records ,But that records are also Calculated which are Suppressed.
    For these I have Read Several post where someone had same problem,
    there they have Asked to Create A Running Total And use the Formula in evaluate section same as in Suppress Condition but opposite of it.
    I did the same thing using these Formula
    {ExcisePur.ItemCode}<>Previous({ExcisePur.ItemCode}) And {ExcisePur.Batchnum}<>Previous({ExcisePur.Batchnum})
    But it is Calculating only the Suppressed Record But Not the Record which is to be Calculated.
    Please help me to Accomplish this.
    I am very Much blank where I am  going wrong.
    Regards,
    Gayatri Shukla

    Hi Gayatri,
    I'm not too sure why this isn't working as the logic seems correct.
    Here's another way to do this:
    1) Create another formula and place this on the Details Section:
    whileprintingrecords;
    numbervar x;
    if onfirstrecord then
    x := {Field_to_summarize}
    else if {ExcisePur.ItemCode} <> Previous({ExcisePur.ItemCode}) And {ExcisePur.Batchnum} <> Previous({ExcisePur.Batchnum}) then
    x := x + {Field_to_summarize};
    2) Create another formula and place this on the Report Footer:
    whileprintingrecords;
    numbervar x;
    -Abhilash

  • Dynamically group records by date

    I am attempting to create a report that will dynamically group records into a set number of date buckets.  This is similar to grouping records by a date field and setting the days, weeks, months, etc property but instead of grouping by a set time span I want to a specific number of date groups regardless of date span.  So say i have records where the first date is today at 1am and the last record is today at 9 pm.  I want the data grouped into 10 groups and the time calculated for that group based on total time span / 10.  The first group would be 1AM to 3AM, the second would group 3AM to 5AM, etc..  The reason I am doing this is for a chart that displays record counts over time but the overall timespan will never be known until runtime.  Setting the chart for hourly or weekly doesn't work because if the user runs the report over a year the dates will be illegible.
    Thanks in advance!

    Well this SHOULD be easy. But leave it to CR make not...
    You can start by finding the minimum & maximum dates within your range:
    Local DateTimeVar MinDate;
    MinDate := Minimum({Table.DateField})
    and
    Local DateTimeVar MaxDate;
    MaxDate := Maximum({Person.ModifiedDate})
    Then figure out what the the interval would be if the span is broken down into 10 equal parts"
    DateDiff("n", {@MinDate}, {@MaxDate}) / 10
    From there just use a formula to segregate each records into the appropriate groups:
    EvaluateAfter({@Interval});
    IF {Table.DateField} >= {@MinDate}
        AND {Table.DateField} <= DateAdd("n",{@Interval}, {@MinDate}) THEN 1 ELSE
    IF {Table.DateField} > DateAdd("n",{@Interval}, {@MinDate})
        AND {Table.DateField} <= DateAdd("n",{@Interval} * 2, {@MinDate}) THEN 2 ELSE
    IF {Table.DateField} > DateAdd("n",{@Interval} * 2, {@MinDate})
        AND {Table.DateField} <= DateAdd("n",{@Interval} * 3, {@MinDate}) THEN 3 ELSE
    IF{Table.DateField} > DateAdd("n",{@Interval} * 3, {@MinDate})
        AND{Table.DateField} <= DateAdd("n",{@Interval} * 4, {@MinDate}) THEN 4 ELSE
    IF {Table.DateField} > DateAdd("n",{@Interval} * 4, {@MinDate})
        AND {Table.DateField} <= DateAdd("n",{@Interval} * 5, {@MinDate}) THEN 5 ELSE
    IF {Table.DateField} > DateAdd("n",{@Interval} * 5, {@MinDate})
        AND {Table.DateField} <= DateAdd("n",{@Interval} * 6, {@MinDate}) THEN 6 ELSE
    IF {Table.DateField} > DateAdd("n",{@Interval} * 6, {@MinDate})
        AND {Table.DateField} <= DateAdd("n",{@Interval} * 7, {@MinDate}) THEN 7 ELSE
    IF {Table.DateField} > DateAdd("n",{@Interval} * 7, {@MinDate})
        AND{Table.DateField} <= DateAdd("n",{@Interval} * 8, {@MinDate}) THEN 8 ELSE
    IF {Table.DateField} > DateAdd("n",{@Interval} * 8, {@MinDate})
        AND {Table.DateField} <= DateAdd("n",{@Interval} * 9, {@MinDate}) THEN 9 ELSE
    IF {Table.DateField} > DateAdd("n",{@Interval} * 9, {@MinDate})
        AND {Table.DateField}  <= {@MaxDate} THEN 10
    This is where CR drops the ball... IMHO... it WON'T allow you to to group by a formula field that uses an aggregate in the formula (in this case Minimum & Maximum)... It will however allow to to graph on it, which I assume is what you are actually trying to do.  If anyone knows a way to work around the grouping issue, I'd love to know it myself.
    HTH,
    Jason

  • To create a table control in se51 to display 1000 records from ITAB toscr

    Hi Sapall.
    here i have got a requirement just to display the records from itab to table created in se51.
    can any body help me in this.
    regards.
    Vrma.

    Hi,
    There is no problem with 1000 records you can use table control.
    please follow this link to get idea about the table control.
    saptechnical dot com/Tutorials/ABAP/TableControl/Demo.htm
    Regards
    Bikas

  • Dscl: unable to ad/delete/amend user/group records - eDSPermissionError

    hello,
    i am unable to add/delete/amend opendirectory user and group records. users are still connecting but when i try do any of the above if get the follow error within a dscl session:
    create Users qawsed
    <main> attribute status: eDSPermissionError
    <dscl_cmd> DS Error: -14120 (eDSPermissionError)
    on investigation i noticed the error in system.log indicating that /System/Library/LaunchDaemons/edu.mit.kadmind.plist was missing.
    so my questions are:-
    1 has anyone seen the above error condition when using dscl and
    2 can anyone explain how edu.mit.kadmind.plist is created or post an example of this file
    your assistance is appreciated
    regards
    john

    Post Unix queries to the Unix forum under OS X Technologies and server queries to the server forums.

  • Grouping records in an internal table

    Dear all,
    Pls follow the code and suggest me to get the specified format.
    Consider that  i have created a view to populate the reqd data and collect those in an internal table and do a calculation for one field and modify the internal table.
    when i pass this internal table to the function reuse_alv_grid , it throws out a report. But if i need to group the records of the internal table based on three fields, can i do that , if so , how should i do that, if not what method shud i adopt to get the grouped listing in ALV.
    kindly give your views.
    Code goes here..........
    select distinct edatu j_3akvgr6 mvgr4 matnr bismt vbeln auart bstkd bstkd_e ihrez_e
    bstdk_e bstdk bezei vrvez brgew ntgew volum werks kwmeng j_3asize posnr
    INTO CORRESPONDING FIELDS OF TABLE  itabdelshd
    from ZVDELISHED
    where J_3AKVGR6 IN CUSTOMER AND AUART IN ORDTYP
    AND BISMT IN STYLE  AND MATNR in FGMtrl AND bstdk_e IN PLNDATE
    AND J_3ASIZE IN GRIDVAL and werks in plant and mvgr4 in ppmon and
    bstkd in cpono and vbeln in Sales.
    LOOP AT itabdelshd INTO wadelshd.
          select sum( wmeng ) as tqty into wasumqty-tqty
          from vbep where edatu = wadelshd-edatu and vbeln = wadelshd-vbeln
          and j_3asize = wadelshd-j_3asize.
          select sum( lfimg ) as dqty into wasumqty-dqty
          from lips where vbelv = wadelshd-vbeln and j_3asize = wadelshd-j_3asize
          wadelshd-PLND_QTY = wasumqty-tqty - wasumqty-dqty.
          wadelshd-PLND_QTY = wadelshd-wmeng - wadelshd-lfimg.
          wadelshd-COLOR = wadelshd-j_3asize(4).
          MODIFY itabdelshd  FROM  wadelshd.
    ENDLOOP.
      PERFORM build_fieldcatalog.
      PERFORM build_layout.
      PERFORM display_alv_report.

    Dear Jorge,
    It is working out, But i need to do the sum for the grouped data, for instance , if the below data is grouped data seen in the alv,
    sales ord      | color    line.Item|  Ord.qty   | Pld.Qty     | Date          "
    | 0001000551  | 002V | 100       | 6,800.000 | 1,200.000 | 25.09.2006"
    | 0001000551  | 002V | 100       | 6,800.000 | 2,500.000 | 25.09.2006"
    | 0001000551  | 002V | 100       | 6,800.000 | 3,100.000 | 25.09.2006"
    | 0001000551  | 003K | 200       | 3,200.000 | 700.000    | 25.09.2006"
    | 0001000551  | 003K | 200       | 3,200.000 | 1,200.000 | 25.09.2006"
    | 0001000551  | 003K | 200       | 3,200.000  | 1,300.000 | 25.09.2006"
    and if want to sum the the planed qty based on the line.Item Grouping, meaning, can i get the report in the below form.
    sales ord      | color    line.Item|  Ord.qty   | Pld.Qty     | Date          "
    | 0001000551  | 002V | 100       | 6,800.000 | 6,800.000 | 25.09.2006"
    | 0001000551  | 003K | 200       | 6,800.000 | 3,200.000 | 25.09.2006"
    what should i do to get this form.

  • Summing Last Record

    Hi All,
    I have a crystal report which has 4 groups. The details line shows 2 records per group 4.
    I want only want to sum the last two records from the details line and make that sum available in
    GF1.
    Is that possible.....???
    Many Thanks for your help...

    HI,
    Can you make it more clear with some sample data.
    Regards,
    Salah.

  • Query to Group records based on

    Hello,
    I need a help.
    I have a errortable with 4 columns (pk, errordate, activestatus, errormsg). I need to get a count of the records with a pattern of errormsg but im getting lost on this, not sure where is the problem.
    For example there are records with errormsg column which has logged some error msgs like say
    'xxxIn-Housexxx'
    'yyyCheckedInyyy',
    aaaIn-Hoouseaaa',
    bbbCheckedInbbb'
    I'm only interested to have a count of all those with the pattern match of 'In-House' and 'CheckedIn'
    this is the one i was trying, which is giving me some syntax error not sure what it is
    select count(*) from error_table where errordate > sysdate - 3
    group by errormsg
    having
    errormsg like '%In-House%'
    or
    errormsg like '%CheckedIn%'
    I'm really confused to get a working sql for this. can you please help me.
    thanks

    select sum(case
                   when upper(errormsg) like '%IN-HOUSE%' then 1
                   else 0
               end
              ) in_house_error
          ,sum(case
                   when upper(errormsg) like '%CHECKEDIN%' then 1
                   else 0
               end
              ) checkedin_error         
    from   error_table
    where  errordate > sysdate - 3
    ;

  • Formula to get sum of records per page

    Post Author: dreamer_0244
    CA Forum: Formula
    Hi! I'm trying to create a formula that would get the sum of a field within each page of the report.
    Does anyone have an idea on this? Thanks!

    Post Author: bettername
    CA Forum: Formula
    If you want something at the bottom of the page that says "Total sales for this page = £1385.55", then you'd create a formula in the group header that sets a variable to be 0.  Then add to this variable for each record, and then display it in the page footer:
    In page header (suppress formula):
    whileprintingrecords;
    numbervar mytotal:=0;
    In details section (suppress formula):
    whileprintingrecords;
    numbervar mytotal:=mytotal+
    In page footer:
    whileprintingrecords;
    "Page total = "+totext(numbervar mytotal)

  • Summing groups by selection

    I have created a report with two gropings. The details are project costs(estimate at complete) I grouped the details by project type(group 1) and then by year of each estimate at complete(group 2), the grouping works well. The problem is I must sum certain projects from group 1 and sum by each year. To further clarify my problem I need to sum the first grouping by just selecting "committed projects", "active", "not active", Sum them by year (group 2) and then have another sum that adds "grey', "green"  sum them by year....so on. Then I need to graph the yearly gropings of group 1, group 2,...etc. Where I am stuck is the summing. PLEASE HELP ANY ONE

    Yes I have. Here is what my screen looks like
    Group 1 : Comitted.aic         41,100,198*(sum of BASEHIST.EAC)
    Group 2  :     1996                       0.00(sum of BASEHIST.EAC)
                       1997                       41,000,00
                       1998                       100,000
                       1999                        198
    *Group 1 :     Active                   333,768*
    Group 2  :     1996                       0.00
                       1997                       45,391
                       1998                     290,985
                       1999                        0.00
    So on and so on
    so the running totals work well
    I need to total individual projects that are selected(group 1) and get a yearly number(group 2)
    I tried inserting a Running total field
    selecting summize field...basehist.eac(field on the detail line that I have supressed)
    I evaluate a record by using a formula.(CAWP.C7 is the field which group 1 is derived:)formula: {CAWP.C7}="COMMITTED.AIC" and {CAWP.C7}="COMMITTED.ANIC" and {CAWP.C7}="COMMITTED.CLOSE" and {CAWP.C7}="COMMITTED.SUNK"
    and I reset on group 2.
    When I inserted this in the report I get all blanks
    That is where I am stuck at

  • Sum grouped in alv report

    Hi experts,
    I have a alv report (REUSE_ALV_GRID_DISPLAY) currently sum the Ctd column but sum all regardless of the value of the UM column
    I need to sum the values ​​of the Ctd column but grouping it by the code of the UM column as the following example
    I insert 'X' in the do_sum field of fieldcat of the Ctd and UM columns but did not work.
    Please help.
    Best regards,
    Robert

    Hi Robert,
    ENABLE SORT IN REUSE_ALV_GRID_DISPLAY AND DO SUBTOTAL FOR UM FIELD :
    DATA : it_sort TYPE slis_t_sortinfo_alv,
                wa_sort TYPE slis_sortinfo_alv.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
          IT_SORT                           = it_sort
       CLEAR wa_sort.
       wa_sort-fieldname = '   '.   """  (um)
       wa_sort-tabname = '    '.   ""  int table name
       wa_sort-subtot    = ' X '.
       APPEND wa_sort TO it_sort.

  • Help needed regarding SUM keyword in an ITAB loop

    Hello,
    I am maintaining a code as given below.
    LOOP AT itab INTO totwa.
    SUM.
    ENDLOOP.
    totwa is defined as a workarea which is needed to hold the sum totals of the fields in the itab. According to the documentation of SUM, it should calculate the sum totals and should put the totals in the workarea mentioned. But somehow its not calculating the value. Could anyone please help me in resolving this issue. Please guide me with your thoughts as to what might have gone wrong.
    Note: the itab fields are of type P.
    Thanks in advance
    Sudha Naik

    Hello Suha
    According to the ABAP documentation the SUM statement is used in a specific situation:
    <b>Syntax
    SUM. </b>
    <b>Effect </b>
    <i>The statement SUM can only be specified within a loop starting with LOOP, and is only considered within a AT-ENDAT control structure. Prerequisites for using the statement SUM include using the addition INTO in the LOOP statement, and that the specified work area wa is compatible with the row type of the internal table. In addition, SUM cannot be used when the row type of the internal table itab contains components that are tables. </i>
    <i>The statement SUM calculates the component total with the numeric data type ( i, p, f) of all rows in the current control level and assigns these to the components of the work area wa. In the control levels FIRST, LAST , and outside of an AT-ENDAT control structure, the system calculates the sum of numeric components of all rows in the internal table.</i>
    I hope the following sample report will clarify the use of <b>SUM </b>and <b>COLLECT</b>.
    *& Report  ZUS_SDN_COLLECT
    REPORT  zus_sdn_collect.
    TYPES: BEGIN OF ty_s_line.
    TYPES:   key(1)    TYPE n.
    TYPES:   value     TYPE p DECIMALS 2.
    TYPES: END OF ty_s_line.
    TYPES: ty_t_itab    TYPE STANDARD TABLE OF ty_s_line
                        WITH DEFAULT KEY.
    DATA:
      gs_line       TYPE ty_s_line,
      gt_itab       TYPE ty_t_itab,
      gt_itab_coll  TYPE ty_t_itab.
    START-OF-SELECTION.
      DO 3 TIMES.
        gs_line-key = syst-index.
        gs_line-value = syst-index * '2.3'.
        APPEND gs_line TO gt_itab.
        APPEND gs_line TO gt_itab.
      ENDDO.
      gs_line-key = 4.
      gs_line-value = '5.5'.
      APPEND gs_line TO gt_itab.
      WRITE: / 'Initial list'.
      LOOP AT gt_itab INTO gs_line.
        WRITE: / gs_line-key,
                 gs_line-value.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using SUM statement with AT END OF'.
      SORT gt_itab BY key.
      LOOP AT gt_itab INTO gs_line.
        AT END OF key.
          SUM.
          WRITE: / gs_line-key,
                   gs_line-value.
        ENDAT.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using SUM statement without control structure (1)'.
      SORT gt_itab BY key.
      LOOP AT gt_itab INTO gs_line.
        SUM.
        WRITE: / gs_line-key,
                 gs_line-value.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using SUM statement without control structure (2)'.
      SORT gt_itab BY key.
      LOOP AT gt_itab INTO gs_line.
        SUM.
        WRITE: / gs_line-key,
                 gs_line-value.
        EXIT.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using COLLECT statement'.
      REFRESH: gt_itab_coll.
      LOOP AT gt_itab INTO gs_line.
        COLLECT gs_line INTO gt_itab_coll.
      ENDLOOP.
      LOOP AT gt_itab_coll INTO gs_line.
        WRITE: / gs_line-key,
                 gs_line-value.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using COLLECT statement for total sum'.
      REFRESH: gt_itab_coll.
      LOOP AT gt_itab INTO gs_line.
        gs_line-key = 0.
        COLLECT gs_line INTO gt_itab_coll.
      ENDLOOP.
      LOOP AT gt_itab_coll INTO gs_line.
        WRITE: / gs_line-key,
                 gs_line-value.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
    END-OF-SELECTION.
    Regards
      Uwe

Maybe you are looking for