Sum of a field

I am having issues trying to do sum of a field.
This is how the source data looks like:
COLA COLB COLC COLD
123 456 4 X
123 456 4 A
123 456 4 B
123 789 5 Y
123 789 5 Z
123 789 5 E
Output I want is:
COLA COLB COLC COLD COLE COLF COLG COLH COLI
123 789 9 X A B Y Z E
max(COLB) (5+4)
The sumof COLC based on ColB
Any suggestions, please let me know...
Thanks..

COLC is 9 because there are just unique values for COLB. ColA is my primary key but I am joining to 2 tables where there is one to many relationships and thats why the data looks like above.
As far as COLD goes, there is a unique code for every value in COLD and I am doing a decode along with MAX and trying to normalize the data, but my problem is I dont know how to just get just the 2 values from COLC to do the sum.

Similar Messages

  • Sum of a field in ALV List

    Hello Guys,
    I'm using 'REUSE_ALV_GRID_DISPLAY' in my prog.
    There is a field in output table which is of type P(8) Decimals 3.
    When I'm trying to get the sum of this field in ALV Display it gives the message " Desired operation cannot be performed for column 'Converted Quantity' ".
    I have also tried do_sum = 'X'.
    But it is not working. Please help guys.
    Regards,
    Abhinav

    Thanks a lot guys for your inputs.
    The program is working now.
    Now I'm using :
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname = 'QUAN'.
    *  wa_fieldcat-ref_tabname = 'I_OUT2'.
    *  wa_fieldcat-tabname = 'I_OUT2'.
      wa_fieldcat-qfieldname = 'MEAS'.
      wa_fieldcat-qtabname = 'I_OUT2'.
      wa_fieldcat-outputlen = '15'.
      wa_fieldcat-seltext_l = text-052.
      APPEND wa_fieldcat TO i_fieldcat.
    The program is working fine now.
    I have commented tabname and -ref_tabname , and the program is working fine now.
    Thanks a lot.

  • Dump when summing up CURR field in ALV GRID display

    Hi All,
    I am getting dump when I try to sum the CURR field in my ALV Grid Display. The field is of CURR 23.  I am using classes and methods to display alv grid.
    I tried passing <fs_fieldcat>-do_sum = 'X'. When I did this, it is dumping without even displaying the alv grid.
    Here is the part it is throwing dump:
            ls_lvc_data-value = space.
            clear ls_lvc_data-style.
            loop at it_fcat_local assigning <ls_fcat>
                    where tech ne 'X' and no_out ne 'X'.
              if l_invisible eq 'X'.
                clear l_invisible.
                if <ls_fcat>-do_sum is initial.
                  continue.
                else.
                  clear ls_lvc_data-col_pos.
                endif.
              endif.
              add 1 to ls_lvc_data-col_pos.
              assign component <ls_fcat>-fieldname
                               of structure <ls_data> to <l_field_value>.
              _if sy-subrc ne 0.
                message x000(0k).
              endif._
    Regards,
    Guru

    Thomas,
    Here is the dump:
    Runtime Errors         MESSAGE_TYPE_X
    Date and Time          10/22/2010 23:30:53
    Short text
    The current application triggered a termination with a short dump.
    What happened?
    The current application program detected a situation which really
    should not occur. Therefore, a termination with a short dump was
    triggered on purpose by the key word MESSAGE (type X).
    Error analysis
    Short text of error message:
    Long text of error message:
    Technical information about the message:
    Message class....... "0K"
    Number.............. 000
    Variable 1.......... " "
    Variable 2.......... " "
    Variable 3.......... " "
    Variable 4.......... " "
    How to correct the error
    Probably the only way to eliminate the error is to correct the program.
    If the error occures in a non-modified SAP program, you may be able to
    find an interim solution in an SAP Note.
    If you have access to SAP Notes, carry out a search with the following
    keywords:
    "MESSAGE_TYPE_X" " "
    "SAPLSLVC" or "LSLVCF36"
    "FILL_DATA_TABLE"
    If you cannot solve the problem yourself and want to send an error
    notification to SAP, include the following information:
    1. The description of the current problem (short dump)
    To save the description, choose "System->List->Save->Local File
    (Unconverted)".
    2. Corresponding system log
    Display the system log by calling transaction SM21.
    Restrict the time interval to 10 minutes before and five minutes
    after the short dump. Then choose "System->List->Save->Local File
    (Unconverted)".
    3. If the problem occurs in a problem of your own or a modified SAP
    program: The source code of the program
    In the editor, choose "Utilities->More
    Utilities->Upload/Download->Download".
    4. Details about the conditions under which the error occurred or which
    actions and input led to the error.
    Source Code Extract
    Line
    SourceCde
    2708
    is_subtottxt_info = ls_subtot_info
    2709
    ip_subtot_line    = lr_data
    2710
    changing
    2711
    c_subtottxt       = l_subtottxt.
    2712
    ls_lvc_data-value = l_subtottxt.
    2713
    2714
    append ls_lvc_data to ct_lvc_data.
    2715
    endif.
    2716
    2717
    2718
    Column per Fieldcat Entry
    2719
    2720
    ls_lvc_data-value = space.
    2721
    clear ls_lvc_data-style.
    2722
    loop at it_fcat_local assigning <ls_fcat>
    2723
    where tech ne 'X' and no_out ne 'X'.
    2724
    if l_invisible eq 'X'.
    2725
    clear l_invisible.
    2726
    if <ls_fcat>-do_sum is initial.
    2727
    continue.
    2728
    else.
    2729
    clear ls_lvc_data-col_pos.
    2730
    endif.
    2731
    endif.
    2732
    2733
    add 1 to ls_lvc_data-col_pos.
    2734
    2735
    assign component <ls_fcat>-fieldname
    2736
    of structure <ls_data> to <l_field_value>.
    2737
    if sy-subrc ne 0.
    >>>>>
    message x000(0k).
    2739
    endif.
    2740
    2741
    *... work on average
    2742
    if <ls_fcat>-do_sum eq 'C'.
    2743
              Initialize average result and entries
    2744
    <l_field_value> = 0.
    2745
    clear l_entries.
    2746
    2747
              retrive unit from fieldcatalog
    2748
    assign space to <l_unit>.
    2749
    if not <ls_fcat>-cfieldname is initial.
    2750
    assign component <ls_fcat>-cfieldname
    2751
    of structure <ls_data> to <l_unit>.
    2752
    endif.
    2753
    if not <ls_fcat>-qfieldname is initial.
    2754
    assign component <ls_fcat>-qfieldname
    2755
    of structure <ls_data> to <l_unit>.
    2756
    endif.
    2757

  • SUM for a field in ALV

    Hello Guys,
    CAn any one tell me how to do the SUM for a particular column in ALV.It should display at the End of the records.The column field is TYPE N(4).
    My CODE is like this:
    CLEAR fc_tmp.
      fc_tmp-col_pos         =  5.
      fc_tmp-reptext_ddic    = 'POINTS'.
      fc_tmp-fieldname       = 'POINTS'.
      fc_tmp-tabname         = 'ITAB'.
      fc_tmp-outputlen       = 15.
      fc_tmp-key             = 'X'.
      fc_tmp-do_sum          = 'X'.
      APPEND fc_tmp TO fieldcat.
    This is not working.
    Thanks in Advance,
    Take care

    Hi,
    populate the IT_SORT internal table of REUSE_ALV_GRID_DISPLAY provided in the importing parameters.
    fieldname = Company Code
    append fieldname to it_sort.
    fieldname = division.
    append fieldname to it_sort.
    If you explicitly need subtotals then add the following line
    subtot = 'X'
    For obtaining sum you have an attribute "do_sum" in fieldcatalog , set it to 'X' and you should be able to do sum on that field.
    <b>Ensure that these should be numeric / currency or quantity datatypes only.</b>
    wa_fieldcat-datatype = 'CURR'.   or
    wa_fieldcat-datatype = 'QUAN'.
    Hope this solves your problem
    Cheers,
    Simha.
    PS : Please reward points if solution is helpful

  • Material description filled automatically as the sum of two fields

    Hello to all
    We can automate the process of the creation a new material doing that the field material description(MAKT-MAKTX) can be filled by the system before saving(not by the user) as the sum of two fields in the MARA table that the users will be filled manually.
    Is it possible using a user exit, field exit,....?
    Thanks in advance.
    Regards

    Hello to all
    We can automate the process of the creation a new material doing that the field material description(MAKT-MAKTX) can be filled by the system before saving(not by the user) as the sum of two fields in the MARA table that the users will be filled manually.
    Is it possible using a user exit, field exit,....?
    Thanks in advance.
    Regards

  • [CR integrated in VS 2005] - sum of string fields

    Hello,
    i am discovering CR,
    and i am trying to do the sum of a field (number) but declared as string. the declaration of the field cannot be changed (string in the database).
    so i want to do the sum of this field.
    i wonder if it is possible, and if yes, how.
    maybe something like a formula.
    I saw the functions: ToNumber () and Cdbl() for conversion, and Sum().
    If someone has an idea, i will be very interested.
    PS: sorry if my question is not understandable, i'm french. If you don't understand it, i would rewrite it.
    thank you!

    thank you.
    I could convert, but the problem is to make the sum of the conversion.
    i would like to do something like:
    Sum(ToNumber ()) but CR does not accept it.
    Maybe by using a variable in a formula (but i don't know where):
    shared numbervar total;
    total = total+ToNumber({MyField});
    and when printing a formula field at the bottom of the report to show the total:
    shared numbervar total;
    ToText (total);

  • 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 ) ;

  • Sum a DATETIME field

    Just noticed it isn't straight forward to SUM a DATETIME fields.
    I’ve used the following code to get the time, how do I convert the output back to a DATETIME field?
    declare @T table
    total_hours_worked datetime
    insert into @T values ('01:00:00')
    insert into @T values ('01:30:00')
    insert into @T values ('03:35:00')
    select *
    from @T
    select SUM((DATEPART(hh,total_hours_worked)*60)+DATEPART(mi,total_hours_worked)+(DATEPART(ss,total_hours_worked)/(60.0)))/60.0 as TotalHours from @T
    Thanks,

    I should have added the disclaimer that my solution would require total_hours_worked to be stored as either a float or a varchar to be used with the function I described above.   The completed functions would be similar to 
    CREATE FUNCTION dbo.TimeSpan_CreateFromString
    @pFormattedTimeSpan varchar(128) = null
    RETURNS float(53)
    with returns null on null input AS
    BEGIN
    declare @DayPortion int
    ,@HourPortion int
    ,@MinutePortion int
    ,@SecondPortion decimal(6,4)
    declare @l int
    declare @s2 varchar(128)
    DECLARE @Result float(53)
    select @s2=LTRIM(rtrim(@pFormattedTimeSpan))
    set @l = LEN(@s2)
    declare @i int
    if CHARINDEX('.',@s2,1) < CHARINDEX(':',@s2,1)
    begin
    set @i = CHARINDEX('.',@s2,1)
    select @DayPortion =
    case CHARINDEX('.',@s2)
    when 0 then 0
    else
    case ISNUMERIC(SUBSTRING(@s2,1,CHARINDEX('.',@s2)-1))
    when 1 then CAST(SUBSTRING(@s2,1,CHARINDEX('.',@s2)-1) as int)
    else 0
    end
    end;
    set @s2=ltrim(rtrim(SUBSTRING(@s2,@i+1,@l-(@i))))
    end
    else
    begin
    set @DayPortion=0
    end
    -- ** debug: select @i, @l, @s2
    --select CHARINDEX(':',@s2,1) [c1], CHARINDEX(':',@s2,CHARINDEX(':',@s2,1)+1) [c2], CHARINDEX(':',@s2,(CHARINDEX(':',@s2,CHARINDEX(':',@s2,1)+1))+1) [c3]
    set @i = CHARINDEX(':',@s2,1)
    select @HourPortion =
    case CHARINDEX(':',@s2,1)
    when 0 then 0
    else
    case ISNUMERIC(SUBSTRING(@s2,1,CHARINDEX(':',@s2,1)-1))
    when 1 then CAST(SUBSTRING(@s2,1,CHARINDEX(':',@s2,1)-1) AS int)
    else null
    end
    end
    set @s2=ltrim(rtrim(SUBSTRING(@s2,@i+1,@l-(@i))))
    -- ** debug: select @i, @l, @s2
    set @i = CHARINDEX(':',@s2,1)
    select @MinutePortion =
    case CHARINDEX(':',@s2,1)
    when 0 then 0
    else
    case ISNUMERIC(SUBSTRING(@s2,1,CHARINDEX(':',@s2,1)-1))
    when 1 then CAST(SUBSTRING(@s2,1,CHARINDEX(':',@s2,1)-1) AS int)
    else null
    end
    end
    set @s2=ltrim(rtrim(SUBSTRING(@s2,@i+1,@l-(@i))))
    -- ** debug: select @i, @l, @s2
    set @i = CHARINDEX(':',@s2,1)
    select @SecondPortion =
    case ISNUMERIC(@s2)
    when 0 then null
    else CAST(@s2 as decimal(6,4))
    end
    SELECT @Result = dbo.TimeSpan_CreateFromParts(@DayPortion,@HourPortion,@MinutePortion,@SecondPortion);
    RETURN @Result
    END
    GO
    I changed the function names to make them more consistent.

  • Finding sum for time field in alv

    hi gurus.,
              i need to find total hours.. i am using field of data type 'TIMS' ... i converted the value to decimal in ALV and founfd total hours .. i need the total hours in Time format .. how can i achieve this in alv .. its very urgent ...
    thanks&regards.,
    S.Sivakumar

    Hi Shivakumar,
    I suggest you not to convert TIMS to Decimal
    because it won't give you correct result..
    Eg...
    Time1 = '11:56:32'
    Time2 = '11:50:10'        
    now add these two times...
    u will get the sum of these as 23:06:42
    but in real life... you want the result as 23:46:42
    So the better way for getting accurate result is to convert this
    HH:MM:SS to Seconds
    and then sum these seconds
    then again convert it to HH:MM:SS
    1 hr = 3600 sec
    1 min = 60 sec
    Hope it will solve your problem...
    Reward points if useful...
    Thanks & Regards
    ilesh 24x7

  • Sum for Dynamic Fields in a Dynamic Table with Field Symbol

    Hi All,
    I currently have an report which I am looking to update with some totals.  The information is currently output in an ALV which is fed data from a dynamic table defined with a field symbol.  The modification that needs to be applied is a summation per currency code where each of the fields to be summed is a dynamically named field at runtime.  I am now just looking to see if anyone has any recommendations on how to obtain these totals it would be appreciated.  I have no problem doing the leg work in piecing the solution together but am just stuck on which approach I should be investigating here.  I have looked into several options but do to the fact that the totals are for dynamic fields in a dynamic table and it is a field symbol I am having some difficulties thinking of the easiest approach to obtain these totals.
    Below is a simple sample of what the report currently looks like and what we are looking to add.
    ====================================================================================
    As-Is Report:
    DETAILED DATA ALV
    Company Code  |  Plant  |  2006 Total  |  2007 Total  |  2008 Total |  CURRENCY
    0001          |   ABCD  |    1,500     |    1,200     |    1,700    |    USD
    0001          |   BCDE   |    2,300     |    4,100     |    3,600    |    GBP
    0003          |   DBCA  |    3,200     |    1,600     |    6,200    |    USD
    Addition 1:
    TOTALS PER CURRENCY
    Currency                |  2006 Total  |  2007 Total  |  2008 Total |
    USD              |    4,700     |    2,800     |    7,900    |
    GBP                       |    2,300     |    4,100     |    3,600    |
    Addition 2:
    CONVERSIONS TO USD
                                          |  2006 Curr   |  2006 USD    |  2008 Curr   |  2006 USD   |
    USD                       |  4,700 USD   |  4,700 USD   |  7,900 USD  |  7,900 USD  |
    GBP   (1.5GBP/1 USD)    |  2,300 GBP   |  1,150 USD   |  2,300 GBP  |  1,800 USD  |
    ====================================================================================
    Any recommendations will be appreciated.

    Hi,
    We cannot use the key word SUM in the loop at assigning statement.
    The way i see is
    When  you are creating the first dynamic internal table , create one more with  the structure below:
    Currency | 2006 Total | 2007 Total | 2008 Total |
    Then while populating the data into first itab,also move the contents to the second itab using collect statement.

  • Correspondence open items sum by sort field

    Hello
    I have set a variant for correspondence open items with sort items by field vbeln (this is SD invoice number, which is written in vbeln, when invoice is booked and also when (partially) payment against this invoice is booked).
    Is it possible to have a sum of all items with the same vbeln number and output it in sapscript ?
    I am using RFKORD11 program.

    Hi
    U can use Customised query Report to show ur report as per ur format and requirement. But in Normal Report u cant do this...always u have to sort there was no option in standard to save...
    Giri

  • Sum of Calculated Field

    Hi,
    I am using 9.0.2.39.1 and am having trouble summing up a calculated field. I have a crosstab layout like so:
                           MTD               YTD              CURRENT YR
    2005                   $                 $                (decode function based on period)
    2004                   $                 $                (decode function based on period)
    2003                   $                 $                (decode function based on period)I put a grand total for MTD, YTD and Current YR, but it does not pick up the total sum for the Current Year calculated field. I then also tried a total just for the Current Year field, but it is just blank although that column has values for each row. Strangely the count/max..etc functions give me a value, just not sum. The calculation works perfectly just not the sum of it.
    Any idea what I am doing wrong???

    Hi,
    You need to check note 208366.1 which explains why totals can be blank. Without knowing the detail of you decode function it is hard to say what needs to be changed. Try putting a sum in front of the decode e.g.
    sum(decode(period, 'Jan period', value, 0))
    Hope that helps,
    Rod West

  • Dividing sum of varchar fields?

    I'm using SQL Server 2014 and I have the following table containing two varchar fields I need to sum and divide:
    CREATE TABLE.[VMs](
    [VMID] [int] IDENTITY(1,1) NOT NULL,
    [vCenter] [varchar](100) NULL,
    [VMName] [varchar](100) NULL,
    [Template] [varchar](100) NULL,
    [PowerState] [varchar](100) NULL,
    [ClusterName] [varchar](100) NULL,
    [Disk] [int] NULL,
    [DiskPartition] [varchar](70) NULL,
    [DiskSizeGB] [decimal](10, 3) NULL,
    [Hostname] [varchar](100) NULL,
    CONSTRAINT [PK_VMs] PRIMARY KEY CLUSTERED
    [VMID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    I'm trying to get the distinct sum of 'VMName' and 'Hostname' to get the count of each, and then divide the 'VMName' count by 'Hostname' count on a per 'vCenter' basis.
    I'm not sure how to perform calculations against the varchar fields and any help would be appreciated.
    Thanks in advance
    Adam

    This is the main query, the top portion was sample data I just put based on your provided data
    ;With CTE
    AS
    SELECT
    vCenter
    ,COUNT(DISTINCT VMName) As CountVMName
    ,COUNT(DISTINCT HostName) As CountHostName
    FROM
    @myTable
    GROUP BY
    vCenter
    SELECT *, (CASE WHEN CountHostName <> 0 THEN CountVMName / CountHostName ELSE 0 END) As CountPerVCenter
    FROM
    CTE
    Best Wishes, Arbi; Please vote if you find this posting was helpful or Mark it as answered.

  • How to calculate sum of the fields that will be reflected for every row entry??

    Probably, the title might not give you the correct view on the question that I want to ask but, I can describe my question. Well, I have an
    Excel sheet for attendance where in I have different columns
    for 3 subjects (subject1, subject2, subject3) and a
    total column. I also have another column named as Student ID.
    I would like to write a formula for the total column where, when I enter the number of classes attended in every subject column for each student present in every row, then the total column is reflected with the sum of no.of classes attended in every subject
    for each student automatically.
    How can I achieve this? I am looking forward for any help. I am a beginner.
    Ex: Excel sheet
    Student ID | Subject1 | Subject2 | Subject3 | Total
    1               
    |     2        
    |       3      
    |       4       |   
    9
    2                |     3        
    |       5      
    |      2       
    |   1
    The total column should be reflected with the sum of values under subject1, subject2, subject3 fields automatically for every row. How to do it?
    Thank you,
    Kaushik.

    In the first empty cell of the row of Student 1, enter a formula like
    =SUM(B2:D2)
    where column B is headed Subject 1 and column D is headed Subject 3, then copy down to match your student list.
    Then below the last row of column B, enter the formula
    =SUM(B2:BXXX)
    where 2 is the row of Student 1, and XXX is the row number of the row above the formula, then copy across to match.

  • Sum of Average Field

    Post Author: jehanzeb
    CA Forum: Crystal Reports
    Hello all,
    I am wondering how can you get a grand total of "Average". I have a field in the report with Average per day per lense. Now at the end of the report I would like to show the grand total of all those averages.
    Example:
    Average Per day
    2.00
    3.00
    1.50
    At the end of the page (footer) it should show grand total of 6.50.
    How can I achive this?
    Help pleaseeee
    I have tried sum, count, distrnt count etc but none seems to be working (tried the summary function key as well).
    Regards
    Jehanzeb

    Post Author: jehanzeb
    CA Forum: Crystal Reports
    Morning Khalil,
    Firstly thanks for the kind reply. I have tried your explained method but unfortunately it didn't work, infact it has changed the values to 1.00 all the way.
    Example -
    Whileprintingrecords;Global Numbervar FAvg:=0; ( This stayed at it is and has been inserted onto the header - upon initialisation it is shown as 0 which is fine).
    Whileprintingrecords;Numbervar FAvg;FAvg := FAvg+ {lab_rework.rework_qty}; ( The rework qty is the field which needs to be averaged - example  from 01/05/2008 to 02/05/2008 there were 3 lenses which were reworked, so the average should be 1.5 per lense per day. However, using your formula it shows 1.00)
    Whileprintingrecords;Numbervar FAvg; (This is the grand total of whatever the average field shows however this is showing 1.00 as well even though the records are showing 1.00, in theory this should add up all those 1.00s and should show 10.00 which it isnt.)
    I have tried using the built in average running total but it doesnt seem to work as it calculates the average of the first day and not all days. For example when I entered the date range from 01/05/2008 to 02/05/2008, it shows the average of the 01/05/08 day and not the total average of both days hence showing only 1.00 as it calculating only one day. This however should calculate the average of the days I enterd into the parameters i.e. according to the date range
    how can I achive the expected results (where it shows the average of all the lenses reworked according to the date range)?
    Many thanks
    Regards
    Jehanzeb

Maybe you are looking for

  • Itunes dowlowader problem

    ok so i downloaded the new software for itunes and and it still wont let me download my music onto my phone

  • 9iAS Release 2 Forms/Reports Servers

    With 9iAS Rel1, there was a forms and a reports startup script for the servers. I'm not seeing this with Release 2. Also, we have had problems with Reports with regards to the DISPLAY environment setting. Where do I alter the DISPLAY for the reports

  • Installing oracle 8i

    hi, i have a peculiar problem in installing oracle 8i. i use the following config> PC BRAND: ACER 7500 PROCESSOR: INTEL PENTIUM 4 SPEED: 1.7GHZ CACHE: 256KB RAM: 1GB MOTHER BOARD: ACER WITH INTEL 850 CHIPSET ======================================== i

  • More than one map number per topic?

    I have been asked to create context sensitive help with RoboHelp6. Is it possible to create bookmarks in a topic and have different map numbers open to these different bookmarks in the same topic OR does each map number have to have one unique topic?

  • IPhoto 11 keeps crashing while I am updating faces.

    I have a new MacBook Pro, with OS 10.7.3. I am updating iPhoto faces with names and iPhoto keeps crashing. Has anyone else experienced this, and do you have any suggestions?