Calculate totals and sub totals

hi everybody
can u plz suggest me how to write code for getting sub totals and totals
regards
hridhaya

Hello hridhayanjili
SAP provides us with the ABAP statement <b>COLLECT</b> to summarize totals.
I will give you an example from which you should be able to develop you own solution.
Let's assume we have an itab containing materials. The itab has the following line structure: MANDT, MATNR, QUANTITY. To calculate subtotals we require a second itab that is identical to the first one.
Now here is the coding:
data:
  gt_itab          TYPE STANDARD TABLE OF <structure>,
  gt_itab_collect  TYPE STANDARD TABLE OF <structure>,
  gt_itab_total    TYPE STANDARD TABLE OF <structure>.
  gs_entry         TYPE <structure>.
* NOTE: <structure> stands for a named DDIC structure or
* a type definition, not a field symbol.
* gt_itab contains our materials
  LOOP AT gt_itab INTO gs_entry.
    COLLECT gs_entry INTO gt_itab_collect.
  ENDLOOP.
* NOTE: Assuming we had 10 entries in gt_itab of
* 3 different materials we end up with 3 entries in
* gt_itab_collect that contain the quantities summarized.
* To calculate the total one could LOOP over
* gt_itab_collect and summarize the values. Another way
* is shown here:
  CLEAR: gs_entry-matnr.
  MODIFY gt_itab FROM gs_entry
    TRANSPORTING matnr
    WHERE ( matnr IS NOT INITIAL ).
* We clear the material no.
  LOOP AT gt_itab INTO gs_entry.
    COLLECT gs_entry INTO gt_itab_total.
  ENDLOOP. 
* NOTE: because we have the same value for CLIENT and
* MATNR in every line we will end up with a single line
* in gt_itab_total.
Please read the documentation of the COLLECT statement carefully because the structure of your itab (i.e. the order of the fields, especially those that will be summarized) is important.
Regards
   Uwe

Similar Messages

  • This is regarding totals and sub totals in sap-scripts

    Hi to all...............
    1...How to print totals and subtotals in sap-scripts? where we have to code the logic.what sort of logic is needed to print the same?
    regards,
    swaminath.

    Hi
    HI,
    To calculate totals and sub totals in sap scripts you have to use subroutines.
    Say if you have to add the unit price (KOMVD-KBERT) then in the main window whereever tat value is picked write this routine
    /: DEFINE &TOT_PRICE&
    /: PERFORM F_GET_PRICE IN PROGRAM <subroutine prog name> /:USING &KOMVD-KBERT& /:CHANGING &TOT_PRICE& /:ENDPERFORM
    Then write the variable where ever you want it to be printed (mostly it will be in footer window)
    Then create subroutine pool program and you have to write the code.
    FORM F_GET_PRICE tables int_cond structure itcsy
    outt_cond structure itcsy. data : value type kbert.
    statics value1 type kbert.
    Read int_cond table index 1.
    value = int_cond-value.
    value1 = value1 + value.
    Read outt_cond table index 1.
    outt_cond-value = value1.
    Modify outt_cond index 1.
    ENDFORM.
    To know more, have a look at this thread ..
    Re: SAP Script: Display Total calculated  on page 2 in page 1
    <b>Reward if usefull</b>

  • BIWS with Breaks and Sub-Total

    Hi All,
    Created a simple report with Breaks and sub-total and then i exported that report block as BIWS. When I test it in the BIWS Manager, I can able to see the break data with sub-totals. But when i try to connect the same BIWS with Dashboard, am getting only the detail rows and am not getting the sub-total rows.
    Please suggest how to go over this issue.Thanks for your time and support.

    You have any idea now  ‘nbLines’ works? If its returning total row count, then i think we can try some options with it. Basically am trying to get data like below to apply combo box selectors on Year and Country.
    Year
    Country
    Sales
    2013
    India
    100
    2013
    US
    200
    2013
    UK
    100
    2013
    Total
    400
    2014
    India
    100
    2014
    US
    200
    2014
    UK
    100
    2014
    Total
    400
    Total
    Total
    800
    But am getting it as below, if i apply combox box on Year and Countyr, am getting blank value in between list of values.
    Year
    Country
    Sales
    2013
    India
    100
    2013
    US
    200
    2013
    UK
    100
    2014
    India
    100
    2014
    US
    200
    2014
    UK
    100
    2013
    Total
    400
    2014
    Total
    400
    Total
    Total
    800
    Thanks

  • How to count and calculate total percentage for field

    hi all,
    i have two tables as follow:
    i have a inner join as follow :
    SELECT distinct dbo.Motor_Story.Name, dbo.Goods.kala, dbo.Goods.type, dbo.Goods.id_story FROM 
    dbo.Goods INNER JOIN dbo.Motor_Story ON dbo.Goods.id_story = dbo.Motor_Story.Id
    I have the following data are entered
    in my database,
    type
    kala
    no
    Panaconic                       
    Monitor
    1
    Sony                            
    Telvision
    2
    Samsung                         
    Phone
    3
    Vaio                            
    Computer
    4
    Panaconic                       
    Monitor
    5
    Sony                            
    Telvision
    6
    Panaconic                       
    Phone
    7
    Panaconic                       
    Printer
    8
    Sony                            
    Computer
    9
    Panaconic                       
    Monitor
    10
    Sony                            
    Telvision
    11
    Samsung                         
    Phone
    12
    Panaconic                       
    Printer
    13
    i want create a view so that, count 'dbo.Goods.type' and calculate total percentage of ' dbo.Goods.type, than other products based on 'dbo.Goods.kala'.
    pls hlp me.
    best regards.

    Hi,
    Welcome to MSDN.
    I am afraid this is not the proper forum for this issue, since it is not a specific vb.net issue.
    I would suggest you consider posting this issue in sql forum for more dedicated support.
    http://social.msdn.microsoft.com/Forums/en-US/home?category=sqlserver
    Thanks for your understanding.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Calculate total and average for same key figure

    Hi Experts,
    I have a requirement where I need to calculate total and average for same key figure no of employees.
    eg:                
    If I enter 03,2009 as Input the reuslt should give from financiual year starting to current month.
         11.2008      12.2008     1.2009     2.2009     3.2009        average
             11          10       12       10        10         10.6
             10         10       11       12        10         10.6
    total         21         20       23       22        20          21.2
    we have only one characteristic in rows... companycode.
    Waiting for your Inputs.
    Regards
    Prasad Nannuri

    no it will work for u
    you have to use variable on 0calmonth or fiscal period depending on what Time characteristic u are using.
    lets say that variable is zcalmonth
    it is based on 0calmonth for e.g.
    now u restrict keyfigure with this variable zcalmonth with time char. = 0CALMONTH
    copy and paste the restricted keyfigure
    now set offset for variable in  variable selection screen dialog box = -1
    repeat this until u want
    make this variable mandatory
    now at query execution user will select any value for month/year
    and u will see all 5 months in result set
    now there can be maximum 12 months in a year, so u end up creating only 12 restricted keyfigures.
    use YEAR in restricted keyfigure too, and restrict it with YEAR VARIABLE processing by CUSTOMER EXIT = CURRENT YEAR
    in this case it will automatically removes any additional values...
    for e.e.g
    YEAR = 2008 only
    User entered 6/2008
    so lets say ur financial year starts in  april 2007 and ends in april 2008
    so u expect to see
    4/08
    5/08
    6/08
    but u created 12 restricted keyfigures , so it will show upto
    4,5,6 months only

  • How to calculate totals in Blocked ALV Report

    Hi All,
    Can any body tell how to calculate totals & sub totals in
    Blocked ALV Report[Blocked List].
    Thanks in advance
    Thanks & Regards,
    Rayeezuddin.

    read this it might help
    Sums                                                       
    15. No_sumchoice(1) TYPE c : This parameter allows the choice for summing up
    Only by fieldcatalog.
    Value set: SPACE, 'X'
    'X' = fields which are to be summed, passed by the calling program (FIELDCAT-DO_SUM = 'X'). The user should not be able to change this value interactively.
    16. No_totalline(1) TYPE c : Removes the option of having totals after sub-totals.
    Value set: SPACE, 'X'
    'X' = no total record is to be output. Subtotals can still be calculated and output. The fields in the subtotals are flagged DO_SUM = 'X' in the field list.
    17. No_subchoice(1) TYPE c : Does not allow the user to interactively change the field chosen for subtotals.
    Value set: SPACE, 'X'
    'X' = value whose change triggers subtotals, provided by the calling program. The user should not be able to change this value interactively.
    18. No_subtotals(1) TYPE c : No subtotals possible          
    Value set: SPACE, 'X'
    'X' = no subtotals.
    19. Numc_sum(1)  TYPE c : Totals only possible for NUMC-Fields.
    20. No_unit_splitting TYPE c: No separate total lines by inh.units   
    21.totals_before_items TYPE c: Display totals before the items   
    22. Totals_only(1) TYPE c :  Show only totals      
    Value set: SPACE, 'X'
    'X' = only total records are output.
    23. Totals_text(60) TYPE c : Text for 1st col. in totals   
    Value set: SPACE, string (max.60)
    ' ' = The first column in the total record contains an appropriate number of '*'s to indicate the total by default. If the first column is wide enough, the string 'Total' is output after the asterisks.
    'String’ = The string passed is output after the total indicated by '*', if the column is wide enough.
    24. Subtotals_text(60) TYPE c : Texts for subtotals
    Value set: SPACE, string (max.60)
    ' ' = In the first column of subtotal records, the subtotal is indicated by an appropriate number of '*' by default. If the first column is not a subtotal criterion, the string 'Total' is output after the asterisks, if the column is wide enough.
    'String’ = the string passed is output after the subtotal indicated by '*', if the column is wide enough and the first column is not a subtotal criterion. If it is a subtotal criterion, its value is repeated after the total, if the column is wide enough.
    ELSE TELL ME I WILL PASTE COMPLETE HELP
    regards

  • How to calculate total number of pages in a script

    hi
    how to calculate total number of pages in a script

    Jyothsna,
    Date:-&sy-datum&
    Time:-&sy-timlo&
    Total No.of Pages:-&sapscript-formpages&
    Page No:-&PAGE&/&SAPSCRIPT-FORMPAGES&
    Give the above said lines in your text editor,and given the paragraph format.Better create one more window and give the above said lines in the text editor.
    K.Kiran.

  • You Can't Calculate Totals on that!...SO #@!%#! WHAT, YOU GREAT PILE OF !@#

    In Access you have an asterix which represents every field in the table. Useful if you want to see all the data in a table for a single record. I've done it a million times before.
    So why is it telling me that I can't calculate totals on the *, so I should remove it from the query grid and replace it with the fields I want and calculate totals then.
    I DON'T WANT TO CALCULATE ANY #!@%#@!! TOTALS!!
    I AM PUTTING THE FIELDS I #@!%$#! WANT - I WANT ALL OF THEM!! I JUST DON'T WANT TO DOUBLE CLICK 30 TIMES WHEN ONCE WILL DO!
    It's driving me insane because I'm going through hundreds of Oracle tables and it takes so long to browse to the record I'm looking for and it should work to use the asterix, I've done it so many times before.
    How do I override this utterly unhelpful behaviour? Am I stuck in some sort of "Queries will only calculate Totals! mode that I don't know about?
    I know, I know, Access is a micro$loth invention, not Oracle, but we have to use an ODBC link to the SQL database via Acces and it's going to kill me.
    Unless I slam my PC into my neighbour's head first!
    Any help greatly apprciated.
    Sorry for the rant!
    Cheers
    IsNull

    IsNull wrote:
    Cheers,
    I am serious and I know this isn't an Access site, and I know there are differences between SQL in Access and SQL in Oracle, and I'm trying to get funding to do some proper SQL and VBA training, but if anyone can help I'd be very grateful.What? with the funding? Sorry, there's a credit crisis doncha know! ;)
    In the Access/ODBC/Oracle query design view you can create a query by linking fields in tables and then choosing fields you want to output in the query results. At the top of each table is an asterix which uses all the fields from the entire table in a query and outputs the data from all the fields. I'm looking through various tables to find useful fields and using one particular record as my example so I get consistent data output.
    Now, I can look in the actual linked tables and see what they contain, but I want the data for a single record, not the general table contents and there are hundreds of thousands of records. So I'm using the query design to search for the data for a single record and using only one table per query. But if I double click on the asterix to indicate "Use All Fields from this Tabel" I get the "But you can't calculate totals on that!" message. If I add them all individually I get an "Illegal use of LONG data".I once looked at Access, many moons ago. Didn't like it.
    However, from what you describe, it would seem that you need to somehow join the tables as you're doing, but also apply some restrictions on the data so that you're not trying to retieve all the rows back. As for it's error complaining about the totals, I would expect something like you've got an aggregate function in there and things aren't being grouped together. Either that or there's some "setting" somewhere that automatically tries to total things, which hopefully you could turn off. The best thing is to take the error message/number and lookup what that means via some website/documentation that lists Access errors and how to resolve them.
    You'll be lucky to find anyone here who will know (or care about) Access.

  • Calculate total while designing query

    Hi All,
    I have a keyfigure purchase value . I am taking it in one column.
    Now I want to calculate total of purchase value for particular month.
    I can restrict time characteristic with variable but m not getting how to calculate total of this keyfigure.
    Please advise.
    Regards
    Shweta Goel

    what type of calculations?
    when you restrict a query by month you get the total in the result.
    if you want to use the purchase value for a month in a calculation, remove dates or order number from the query, have a aggregated result on which you can do the calculation and users can drill down if they need to see detail.
    regards
    Ramesh

  • How to calculate total time of mouse movement

    Hi Everyone.
    I am doing project on gesture recognition with touchpad. I need to find out the total time of completion of gesture on touchpad. For that I need to calculate total time of cursor movement on laptop touchpad. When cursor starts moving, that time I need to capture time and when it stops also. I need to find out difference between the start time and stop time. Please help me to do this task. Presently I am trying with event structure and timed structure but I am getting only present time only. I tried with counter but unable to get the difference.

    I missed the mouse move event when I saw this earlier, and for some reason I thought the first attempt would give you what you wanted. 
    Here is a different VI. It uses mouse move event with some logic that remembers the first mouse move event. Otherwise, you won't get the correct time.
    Attachments:
    Mouse Move Time.vi ‏11 KB

  • Calculate total size of clob column in a table

    how to Calculate total size of clob column in a table.
    Thanks ,
    Sakthivel

    SAKTHIVEL wrote:
    I would like to calculate table size and particular clob column size inside that table. The size of the table and the size of the LOB are two totally different things.
    Barring cases where the LOB is less than 4k and stored inline, the LOB data is stored outside the table in a separate segment.
    If you want to get the combined size of the table and of its LOB segments, you could do something like
    SELECT SUM(bytes)/1024/1024 gb
      FROM dba_segments
    WHERE (owner = <<table owner>> and
           segment_name = <<table name>>)
        OR (owner, segment_name) IN (
            SELECT owner, segment_name
              FROM dba_lobs
             WHERE owner = <<table owner>>
                AND table_name = <<table name>> )Justin

  • Need to calculate %Total of scenario members

    Hi,
    I need to calculate %Total for members of scenario dimension across some measures.
    M1, M2, M3, M4 are measures. Actual and Model are scenarios.
    My Pivot should look like:
    !http://lh4.ggpht.com/_mTVouNRWdy4/SyACLxgwNbI/AAAAAAAAEJs/5uWAgDmA7CQ/myPivot.GIF!
    I can't make scenario as account dimension due to some other business requirements.
    I have tried using new calculated items on pivot but didn't succeed.
    Please suggest.
    Thanks in advance!!!
    Regards,
    S Anand

    Hi S Anand,
    The best way to accomplish this is creating the % measure in the RPD.
    You'll need the following setup
    Actual = SUM(ACTUAL)
    Total = SUM(ACTUAL) with logical level for Dimension set to total
    % Total = 100.0*(Actual/Total)
    Model = SUM(MODEL)
    Total Model = SUM(MODEL) with logical level for Dimension set to total
    % Total Model = 100.0*(Model/Total Model)
    Put those measures into the Presentation layer and throw them into your report.
    Best regards,
    -Joe

  • How to calculate total no of days in List column

    Hi,
    I've start date and end date. Can you please help me how to calculate total number of days.
    Column Name = Leave Start Date (05/02/2015)
    Column Name = Leave End Date (19/02/2015)
    Column Name = Total Days (This is calculated column)
    I used below formula but its showing only 14 days however it should show 15 days
    =DATEDIF([Start Date], [End Date],"d")
    Thanks,

    I got the answer
    Formula is
    =DATEDIF([Start Date], [End Date]+1,"d")
    Thanks.:)

  • Creating a table based on Category and Sub-Categories

    Hi
    I am building an extensive home budget. I have 3 tables showing, monthly, quarterly and annual costs. These tables contain Categories and Sub-Categories. I have created a table and chart to show the percentage of the total costs for each Category. For the two Categories with the largest percentage of the total cost I would like to create a table (and chart, no problem, based on my first template) showing the breakdown of the Sub-Categories. However this information is to be retrieved from 3 tables, and I was hoping to create the table automatically. If not I must individually go to each different table and find the relevant Sub-Category and manually input the text and link the cell for the value to my new table. This gives room for error in my opinion and is a nuisance as my budget file now contains about 8 sheets so even on 27" iMac requires a considerable amount of scrolling around.
    Am I expecting too much of Numbers or missing something totally? I do not have much experience of spreadsheets, just basic tables and calculations in Excel before coming over from the Dark Side!
    Many thanks for any advice
    Shirley

    Hi Barry
    Many thanks for your reply and apologies for my delay in responding.
    Hope I am doing this photo embedding correctly via Flikr:
    Page 1
    I apologise also for my incorrect terminology - please bear with me on this, unfortunately I never used Excel much so terminology is pretty much my own . I believe that I have one sheet, which then changes into different numbers of pages depending on the page size I set, so with these examples 4 pages. 14 tables and one chart at this time
    The tables on the second screenshot were the only way I could figure out how to retrieve the data for the final table and chart (% Total Monthly Expenses)
    Now what I want to do is for each (or in fact the three largest) budget categories is to give a breakdown of what in that category is, percentage wise, costing the most. Preferably, I want to get this breakdown category information automatically so that human error is ruled out (that I cannot overlook an entry in the any of the tables in my first example). Perhaps I am asking too much, but I thought it was worth asking!
    Again many thanks for responding and for your help with this
    regards
    Shirley

  • Same Query for both Main and Sub Report

    I have a report whichs works but I don't think i'm getting the data to both the Main Report and Sub Report in the most effcient manner...  I have a report that totals users call subject counts.  But then end user wishes to see all users total counts and the grand totals of call counts on the first page then then the breakdown of types of calls on subsuquent pages...  so I created a report with a subreport in the report header....  I use the same query in both the sub and main report... however it asks the user to enter the parameters once for the main report and once for the sub report... Parameters are both the same for each; month and year...  so it currently runs the query twice I want to run it once and use the data for both reports...  I group by name and then sum the call subject counts for the user totals... and in the sub report I hide the detail section and I'm just left with the sub total line for each user, then in the main report use the same grouping and suming again and I start a new page for every user... 
    Using CR 9
    Thanks for any advice
    Vincent

    i think you need to link the main report parameter with the subreport parameters inorder to pass the parameter values from main report to subreport. So right click on subreport and go to change subreport links and add parameter fields and select parameter fields from your subreport and un check the databse fields in subreport.
    Regards,
    Raghavendra.G

  • ALV - Count and Sub Count

    Hello,
    I have an ALV Report.Could any one tell me the code for Count and Sub Count.
    Example is belwo.
    Number     Name     Type
    1     af     A
    2     werg     A
    3     weg     A
              Subcount =3
    4     t2423     B
    5     24t2     B
              Subcount =2
    6     24t2     C
    7     2442422     C
    8     fdghs     C
    9     sghs     C
              Subcount =4
    10     rghqwegtwq     D
              Subcount =1
              Total = 10
    - Varun
    Basic questions are not allowed. Please put some effort from your side, before turning to the forums for help. Use the existing tools (F1 Help, ABAPDOCU, Google, SAP Help, etc) first to resolve your issue. Thread locked
    Edited by: kishan P on Aug 24, 2010 9:43 AM

    Hello,
    I have an ALV Report.Could any one tell me the code for Count and Sub Count.
    Example is belwo.
    Number     Name     Type
    1     af     A
    2     werg     A
    3     weg     A
              Subcount =3
    4     t2423     B
    5     24t2     B
              Subcount =2
    6     24t2     C
    7     2442422     C
    8     fdghs     C
    9     sghs     C
              Subcount =4
    10     rghqwegtwq     D
              Subcount =1
              Total = 10
    - Varun
    Basic questions are not allowed. Please put some effort from your side, before turning to the forums for help. Use the existing tools (F1 Help, ABAPDOCU, Google, SAP Help, etc) first to resolve your issue. Thread locked
    Edited by: kishan P on Aug 24, 2010 9:43 AM

Maybe you are looking for

  • Error during creation of new movement types

    hi frnds,     while creating a new movement type for 311 with z11....in help text tab..it is showing an error.. " Entry HULIST does not exist in TSTC (check entry) "...how do i resolve this. Regards, Prasath

  • Photo app not showing chunk of photos from 2009 to 2013 (says it's "downloading")

    For some reason when I click on the photos tab it says downloading below my most recent picture. When I scroll up it will show me back to april 29th of 2013. Then there is a large gap between 2013 and 2009 and there are image placeholders there. When

  • Verity categoryTree Bug?

    I have a verity index that has categories enabled. I am using both category and categoryTree to narrow the search. I am using search type="internet". This issue does not occur in CF8, but is occurring in CF7. Correct Results: <cfsearch name="searchRe

  • EMAIL COPY to the DISTRIBUTOR?

    I've created a website which is to be linked in our DISTRIBUTORS websites. Customers could place an order through the distributors website. Currently it sends data to a PHP script on the server and gets the details to my mail. My problem: When a cust

  • Can not change size the itunes screen cannot read all opitions

    I am trying to sync my photos to my ipad and I cannot get to the photos because my page is not large enough I get Summay thru podcast how can i get the rest