Calculate Sum Tricky one

Hello Gurus,
A text file has data is in the following manner
I have read the file and all properly the only problem
here is summing up the data so below is how my data looks.
Please make a note this is not stored in DDIC database table it will be read in an Internal table
Also Col3 is not a integer so I cannot use COLLECT
Please suggest a way out to handle this tricky part.
I don;t thik At New On change will work please try this program using the same test data given below , please send me the abap code if you are able to crack this nut.
Col1 Col2 Col3
ABC A 1
ABC A 2
ABC B 3
BBC A 4
BBC A 5
I want to Sum up COL3 by grouping COL1 and COL2
so First Record = ABC A 3 ( 1+ 2)
Second Record = ABC B 3
Third Record = BBC A 9 ( 4 + 5 )
Please let me know I tired many logic but nothing seems to be working.. your help is greatly apprecaited .
Points guranteeed !!
Reagrds,
Aryan

Hi Aryan,
I was able to do the sum... check the code below...hope it helps..
TYPES: BEGIN OF TY_ITAB,
        COL1(3) TYPE C,
        COL2    TYPE C,
        COL3(2)    TYPE C,
  END OF TY_ITAB.
DATA: ITAB TYPE TABLE OF TY_ITAB,
      IT_FINAL TYPE TABLE OF TY_ITAB WITH HEADER LINE,
      WA TYPE TY_ITAB,
      WA1 TYPE TY_ITAB,
      COUNT TYPE I,
      SUM TYPE I,
      FLAG TYPE FLAG.
WA-COL1 = 'ABC'.
WA-COL2 = 'A'.
WA-COL3 = '1'.
APPEND WA TO ITAB.
WA-COL1 = 'ABC'.
WA-COL2 = 'A'.
WA-COL3 = '1'.
APPEND WA TO ITAB.
WA-COL1 = 'ABC'.
WA-COL2 = 'A'.
WA-COL3 = '2'.
APPEND WA TO ITAB.
WA-COL1 = 'ABC'.
WA-COL2 = 'B'.
WA-COL3 = '23'.
APPEND WA TO ITAB.
WA-COL1 = 'ABC'.
WA-COL2 = 'A'.
WA-COL3 = '10'.
APPEND WA TO ITAB.
WA-COL1 = 'ABC'.
WA-COL2 = 'B'.
WA-COL3 = '12'.
APPEND WA TO ITAB.
WA-COL1 = 'ABC'.
WA-COL2 = 'B'.
WA-COL3 = '9'.
APPEND WA TO ITAB.
WA-COL1 = 'ABC'.
WA-COL2 = 'A'.
WA-COL3 = '2'.
APPEND WA TO ITAB.
SORT ITAB BY COL1 COL2.
LOOP AT ITAB INTO WA.
  READ TABLE IT_FINAL WITH KEY COL1 = WA-COL1
                               COL2 = WA-COL2.
  IF SY-SUBRC = 0.
    CONTINUE.
    ENDIF.
  CLEAR: WA1 , SUM ,FLAG.
  READ TABLE ITAB INTO WA1 WITH KEY COL1 = WA-COL1
                                   COL2 = WA-COL2
                                   BINARY SEARCH.
  IF SY-SUBRC = 0.
    COUNT = SY-TABIX + 1.
    SUM = WA1-COL3.
    CLEAR WA1.
    WHILE ( FLAG NE 'X').
      READ TABLE ITAB INTO WA1 INDEX COUNT.
      IF WA1-COL1 = WA-COL1 AND WA1-COL2 = WA-COL2.
        SUM = SUM + WA1-COL3.
        COUNT = SY-TABIX + 1.
      ELSE.
        FLAG = 'X'.
      ENDIF.
    ENDWHILE.
  ENDIF.
IT_FINAL-COL1 = WA-COL1.
IT_FINAL-COL2 = WA-COL2.
IT_FINAL-COL3 = SUM.
APPEND IT_FINAL.
CLEAR IT_FINAL.
ENDLOOP.
LOOP AT IT_FINAL.
  WRITE:/ IT_FINAL-COL1 , 10 IT_FINAL-COL2 , 20 IT_FINAL-COL3.
  ENDLOOP.

Similar Messages

  • How to calculate SUM from multiple numbers in one cell

    Is it possible to calculate SUM if I want to put multiple numbers in one cell?
    Many thanks in advance

    you can sum cell by using the sum() function.
    you can sum a row:
    =sum(1:1)
    will sum ALL cells in row 1
    you can sum a column:
    =sum(C)
    will sum all cells in column C
    you can sum a list of cells:
    =sum(A1, C5, E76, B1:5)
    will add together cells A1, C5, E76, B1, B2, B3, B4, and B5

  • How Calculate more than one value and store it into to different rows and column for each input?

    thx guys.....i have a progress now in LV
    But now i have new trouble here. Ok i attached my LV file (LV 7.0.1/7.1) and excel form. I just could'nt calculate more than one input value. I want a different result for each value that i enter ... and store it into different rows and column. But it just store at one row.
    Attachments:
    My Project.vi ‏31 KB
    rumus motor bakar.xls ‏14 KB

    duplicate post

  • How to calculate sum in jtable

    Hi,i want to ask.Can you teach me how to calculate sum in jtable?For example i got rows of qty,price and total.The total is null unless the user enter value in qty,and when the user press enter key in the qty,the sum will be displayed in the total.Thanks a lot..

    Calculate the sum on the fly when the tableModel is updated (setValueAt() ) or let your row Object deal with it.

  • How to calculate sum of the fields in adobeforms

    Hello Experts
    can  i know how to calculate sum of fields in the adobe form.  I have few fields to be summed in total field.
    Regards

    Hello Surendra,
         Suppose you are having 4 fields and the 4th field is the TOTAL field.
         Write the below Javascript on the Initialize event of TOTAL field as shown below.
    Remember that if you use just "+" sign without Number() or ParseInt() function it acts like String Concatenation.
    this.rawvalue = Number( this.parent.field1.rawvalue ) +
                          Number( this.parent.field2.rawvalue ) +
                          Number( this.parent.field3.rawvalue ) ;
    You can also write is as shown below.
    this.rawvalue = parseInt( this.parent.field1.rawvalue ) +
                             parseInt( this.parent.field2.rawvalue ) +
                             parseInt( this.parent.field3.rawvalue ) ;

  • How to calculate sum of quantities of same item in po release using form personalization?

    I am doing one form personalization in which an item can be entered multiple times in with different released quantity and need by date.
    I want to calculate the sum of release quantity of items.
    How I can achieve this using form personalization?
    Thanks
    Sunny

    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

  • Calculate sum of long integer!

    Hi!
    Im new to java and just started to learn but have a little problem. What I want to know is how I can get a long integer from the user and then caculate the sum of the separate numbers? I thinking I would use som sort of array and then calculate from there. The thing is Im use to ada programminglanguage so I understand the problem but dont really know how to tackle the problem in java.
    So if someone could help I would be grateful!
    //Viktor

    Julingo wrote:
    "I guess you have a handle on how to get an integer from the user then? Can you write the code to get an integer from the user and display it? And "long" and "int" are two different things - which one are you talking about, a 32 bit number or a 64 bit number?"
    Yes, I do know how to get an integer from a user and display it. So far so good :) If I wasnt that clear it is a "long" 64 bit Im trying to get from user and then caculate the sum like this:
    enter integer: 1234567
    digits are 1 2 3 4 5 6 7 and the sum is 28
    /ViktorOk, so, you know how to get input from the user and display it - so - look at the API for the String class and think about your "I think I'll use an array" idea and see what you find there
    Edited by: tsith on Sep 9, 2008 7:49 PM

  • Javascript auto calculate sum in form

    Hello all,
    I have a question for you, probably pretty simple but I don't know JavaScript well enough. What I have is four TextFields in a form. I want the value of the first two (let's call them A and B) to multiply and autopopulate the total in the fourth TextField (D). In the third TextField (C) I want the number entered to be multiplied by 3.25 and be added to the total in the 4th TextField. In other words A*B+(C*3.25)=D
    In plain English, this is for a community garden registration. Number of plots times Fee per plot (which varies based on income level) plus optional bales of hay at $3.25 = _____________.
    Any JavaScript experts out there who can help me?
    Thanks much!
    Dave

    Thanks, Gramps, but not exactly what I was looking for. What I have is 4 TextFields, no radio buttons, etc. I want the first two to multipy, and the third I want to calculate the number typed in times 3.25 adding the sum of the three to the fourth box. I've come close to finding some JavaScript online, but can't quite figure out the exact JavaScript coding to do this. I have a feeling it is simple, just that I know next to nothing about JavaScript and was hoping to find a quick solution until I do have the chance to learn more. Anyone?

  • SSRS 2012 how to use sum from one dataset in calculations in another dataset

     Hi
    I have 2 datasets and I would like to calculate a sum from dataset1 and then use it in calculations in dataset2. I was thinking of a lookup but I can not use an aggregate in the lookup.
    My data looks like this
    dataset1 (warehouse)
    Site   InventoryID            Qty_On_Hand
     A              1                               5
     B              1                               1
     C              1                               7
    Dataset2 (shipping location)
    Site        InventoryID               QTY_Ord                Date_required
     A                1                                 3                        
       2-1-2015
     A                1                                 4                        
       2-9-2015
     C                1                                 6                        
       2-9-2015
    I have set up parameters to that I can choose which sites to include in the report. It is rare that all sites will be included. Normally I will set the parameters to just look at sites A and B from both datasets
    In the case when my parameters are for Sites A and B I would like to come up with a report like
       Inventory_ID         2-1-2015         2-9-2015              Total Qty_Ord             Total Qty_On_Hand
               1                         3                       4              
                      7                                           6
    I will then compare a running total of each Inventory_ID to the total Qty_On_Hand and highlight the cell where Qty_ord exceeds Qty_on_hand
    I just can seem to figure out how to get the Total Qty_on_hand from dataset1 and use it in Dataset2
    Does anyone have a suggestion or two?
    Thank you !

    You can do it simply in your query:
    DECLARE @dataSet1 TABLE (site CHAR(1), inventoryID INT, qtyOnHand INT)
    INSERT INTO @dataSet1 (site, inventoryID, qtyOnHand)
    VALUES ('A',1,5),('B',1,1),('C',1,7)
    DECLARE @dataSet2 TABLE (site CHAR(1), inventoryID INT, qtyOrdered INT, dateRequired DATE)
    INSERT INTO @dataSet2 (site, inventoryID, qtyOrdered, dateRequired)
    VALUES ('A',1,3,'2015-2-1'),('A',1,4,'2015-2-9'),('C',1,6,'2015-2-9')
    SELECT d2.site, d2.inventoryID, d2.qtyOrdered, d2.dateRequired, SUM(d1.qtyOnHand) as qtyOnHand
    FROM @dataSet2 d2
    LEFT OUTER JOIN @dataSet1 d1
    ON d2.inventoryID = d1.inventoryID
    AND d2.site = d1.site
    GROUP BY d2.site, d2.inventoryID, d2.qtyOrdered, d2.dateRequired

  • How to Calculate Sum of Difference between two dates

    Hi,
    I'm using BI Publisher in Siebel CRM.
    In RTF template I have the following expression to calculate the Difference between dates
    <?xdoxslt:date_diff( 'd' , psfn:totext(CIRGSubmittedDate,"yyyy-MM-dd","MM/dd/yyyy"), psfn:totext(Done,"yyyy-MM-dd","MM/dd/yyyy"), $_XDOLOCALE, $_XDOTIMEZONE)?>
    The above expression works for me to calculate the dates.
    I need to calculate the Sum of all these dates for a Group.
    Want to know the Syntax for Sum function using Date_diff.
    Tried the following and didn't work.
    <?Sum(xdoxslt:date_diff( 'd' , psfn:totext(CIRGSubmittedDate,"yyyy-MM-dd","MM/dd/yyyy"), psfn:totext(Done,"yyyy-aMM-dd","MM/dd/yyyy"), $_XDOLOCALE, $_XDOTIMEZONE))?>
    Not sure what I'm doing wrong here...
    Anyone please help...
    Thanks
    PV

    Hi
    To break the diff between 2 dates into days, hours, minutes, sec -- you can use the following:
    select to_char( created, 'dd-mon-yyyy hh24:mi:ss' ),
    trunc( sysdate-created ) "Dy",
    trunc( mod( (sysdate-created)*24, 24 ) ) "Hr",
    trunc( mod( (sysdate-created)*24*60, 60 ) ) "Mi",
    trunc( mod( (sysdate-created)*24*60*60, 60 ) ) "Sec",
    to_char( sysdate, 'dd-mon-yyyy hh24:mi:ss' ),
    sysdate-created "Tdy",
    (sysdate-created)*24 "Thr",
    (sysdate-created)*24*60 "Tmi",
    (sysdate-created)*24*60*60 "Tsec"
    from all_users
    where rownum < 50
    HTH
    RangaReddy

  • Calculate sum of under estimates

    I have a 2008 r2 cube with 2 measures EstmatedTime and ActualTime and a date dimension.  I need to calculate the sum of the under estimates.  So if my estimated hours on the 1st, 2nd and 3rd are 10, 10, 10  and my actual hours are 11, 12,
    7, I need to return 3 as the sum of the under estimates for the period.  Is there a way to do this using MDX, or do I need to do it in the ETL?
    John Schroeder

    Hi JS,
    Considering both the measures are at same granularity, try the below:
    Create a calculated member :
    with member [Measures].[Diff] as
    iif(isempty([Measures].[EstmatedTime])=TRUE and isempty([Measures].[ActualTime]=TRUE,null,
    iif([Measures].[ActualTime] > [Measures].[EstmatedTime],[Measures].[ActualTime] - [Measures].[EstmatedTime],0))
    Now the result would be fine at Date level, but at a higher level say Month the result would not as expected, as the calculated member [Measures].[Diff] would be calculated after aggregating EstmatedTime and ActualTime at month level. In order to fix this
    define a scope.
    Scope( [DimDate].[DateHierarchy].[Month],[Measures].[Diff]);
    This = Sum( Descendants( [DimDate].[DateHierarchy].CurrentMember,[DimDate].[DateHierarchy].[Date]),[Measures].[Diff]);
    End Scope;
    Similarly define scope for all higher datehierarchy levels.
    Saurabh Kamath

  • Require a function module to calculate sum of the quantity based on GRNDATE

    hi friends,
    I need to calculate the sum of the quantity based on GRN DATE and invoice date.
    the invoice date given in select-options should be captured by program and from the previous day it need to retrieve the GRN dates and corresponding quantities and i need to do the summation of all these quantities can anybody tell any function module.
    Thanks in advance.

    Try function MD_CONVERT_MATERIAL_UNIT
    the table of UOM's is MARM.
    Doug

  • I want a select statement to return two values, sum of one column and customer number

    I have two columns one called invoice_number and the other invoice_amount. I want a select statement to return two columns.... invoice_number and then the sum of the invoice_amount(s) for each unique invoice number.
    SELECT sum(invoice_amount) AS Totalinvoice_amount FROM InvoiceTB where invoice_number = 'INV102'
    This is where I've started, which returns:
    Totalinvoice_amount
    500.00
    Any help is appreciated.
    Please mark my post as helpful or the answer or better yet.... both! :) Thanks!

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Annoying Safari "problem"... a tricky one that has confounded others

    OK, so a confession...I prefer the world of Windows to the Mac environment. Simply because it's....simple. The Mac life is just too tricky/complicated (take for example, how hard it is to ever find a picture in iPhoto, compared the simplicity of storing pics in a folder!). I digress. I use a Mac because I love the hardware and some of the beauty. But I have one snare in Safari that drives me nuts.
    If I have used Google, searched on something, clicked on a link or two, and then go to edit my search....the search line automatically reverts to the previous search. You can imagine how annoying this is if the previous search was very different, and all I wanted to do was correct some spelling or something.
    Funky, no?

    Yup, I posted on this issue yesterday. No responses as yet. Googling it ( ! ) reveals a few other people experiencing the same thing. It can be a royal pain the backside, can't it? I'm here to sympathise only, I'm afraid.
    Any ideas gratefully received, readers.

  • Calculate SUM based in condition in iTAB

    Hi all,
    I have the ITAB as follows.
    wa_mseg-mblnr = '5000000130'.
    wa_mseg-mjahr = '2008'.
    wa_mseg-bwart = '901'.
    wa_mseg-dmbtr = '00000005000'.
    wa_mseg-bpmng = '00000000100'.
    wa_mseg-ebeln = '1059200855'.
    wa_mseg-ebelp = '00010'.
    APPEND wa_mseg to itab_mseg.
    wa_mseg-mblnr = '5000000131'.
    wa_mseg-mjahr = '2008'.
    wa_mseg-bwart = '902'.
    wa_mseg-dmbtr = '00000002500'.
    wa_mseg-bpmng = '00000000050'.
    wa_mseg-ebeln = '1059200855'.
    wa_mseg-ebelp = '00010'.
    APPEND wa_mseg to itab_mseg.
    wa_mseg-mblnr = '5000000132'.
    wa_mseg-mjahr = '2008'.
    wa_mseg-bwart = '901'.
    wa_mseg-dmbtr = '00000002500'.
    wa_mseg-bpmng = '00000000050'.
    wa_mseg-ebeln = '1059200855'.
    wa_mseg-ebelp = '00010'.
    APPEND wa_mseg to itab_mseg.
    now i want to add the BPMNG for the BWART = 901
                                   DMBTR   for the BWART = 901
    ans same thing  for the BWART = 902.
    how do i calculate the SUM based on condition.

    now i want to add the BPMNG for the BWART = 901
    DMBTR for the BWART = 901
    ans same thing for the BWART = 902.
    how do i calculate the SUM based on condition.
    Hi, you can loop de internal table and do a control cut by "bwart". For doing that the order of the fields of your internal table must change.
    If you have:
    1st.mblnr
    2nd.mjahr
    3rd.bwart
    you have to change to:
    1st.bwart
    2nd.mblnr
    3rd.mjahr
    So in the loop you will can do like this.
    loop at itab.
    aux_sum = itab-BPMNG + aux_sum.
    at end of bwart.
    * Here you will have de SUM for BWART.
    * Then you clear aux_sum for the next different BWART.
    endat.
    endloop.
    hope this help you.
    Andrew83

Maybe you are looking for

  • FCC Receiver Error :Column value '   ' too long

    Hi Experts I am getting data from SAP for which i should create a file which is fixed length on the target side My structure is : File----1.....Unbound ----->Header --- -1..1 >RecordType >Transcode >PO_Num >Vend_ID >Crea_date >WHS_ID >POM_Status >Can

  • IWeb 2.0.4 to 3.0.2

    I am running iWeb 08 at 2.0.4 I downloaded the 3.0.2 upgrade from Apple but when I try to complete the upgrade i get the message 'A qualifying copy of iWeb was not found in /Applications' don't understand what it is saying

  • Need tips to build a Logical data model

    Hey Gurus, 1) I need some tips in building a logical data model. I have reviewed a functional spec and listed all the fields required in a report. I now looked into datasources( extractor) in R/3 side  which can bring most of these fields but there a

  • Lightroom 4.0 Löschen von Bildern

    Hi, in my case, LR 4 do not delete files from HD when I choose this item in LR 4. LR turnes the files to the wastebasket of windows, but they still stay on HD. In Win Explorer I can see and open them. My system: Win 7 professionel, 64 Bit and LR 4.0.

  • Windows on macbook air

    Hi! I am going for the lates gen macbook air 13 with i7 and 8 gb of RAM as my first mac. But there is som software (note havy software) that i need windows for. How should i install windows? using bootcamp or parallels?? Is the macbook air powerful e