BRFplus: Sum Amount in Table

Experts,
We are having trouble summing amount columns of tables in BRFplus.  We have tried 2 different ideas and each has a different error:
Table Operation - sum the column containing the amount.  This returns a currency error.  It is not possible to pass a currency at runtime because it does not exist in the table structure.
TABLE_SUM_AMOUNT - create a formula and use this function to calculate the amount.  This always returns the error "Column 0050569BA4BE1EE487810606D083E1 does not exist in table Table Type."  Regardless of the column or the table type, this same error appears for all TABLE_SUM* functions.
Any ideas?  Your help would be greatly appreciated.

My specific requirement is to sum the BETRW amount field on an internal table of structure DFKKOP.  In ABAP, the structure contains a currency field called WAERS.  If you attempt to create a table Data Object in BRFplus based on the DFKKOP structure, for some reason the WAERS field disappears:
This is really a very simple and common use case.  My function module that calls BRFplus is posted below.  What I need to know from the experts is:
****HOW DO I SUM THE FIELD BETRW IN TABLE DFKKOP?****
The examples posted so far are not helping at all.
FUNCTION ZFICA_BRFPLUS_SUM_TEST.
*"*"Local Interface:
*"  EXPORTING
*"     VALUE(EV_AMOUNT) TYPE  BETRW_KK
*"  TABLES
*"      IT_DFKKOP STRUCTURE  DFKKOP
*"  EXCEPTIONS
*"      NO_INKGP_FOUND
   CONSTANTS:  lv_function_id TYPE if_fdt_types=>id VALUE '0050569BA4BE1EE48FE94B283920E9F1'. "THE BRFPLUS FUNCTION
   DATA: lt_name_value  TYPE           abap_parmbind_tab,
         ls_name_value  TYPE           abap_parmbind,
         lv_timestamp   TYPE           timestamp,
         exc            TYPE REF TO    cx_fdt,
         lr_data        TYPE REF TO    data.
   FIELD-SYMBOLS: <logmsg> TYPE if_fdt_actn_message_log=>s_log_msg,
                  <wa>     TYPE any.
   GET TIME STAMP FIELD lv_timestamp.
   "SEND THE OPEN ITEMS TO BRFPLUS
   CLEAR ls_name_value.
   MOVE: 'IT_DFKKOP' TO ls_name_value-name.
   GET REFERENCE OF IT_DFKKOP INTO lr_data.
   TRY.
       CALL METHOD cl_fdt_function_process=>move_data_to_data_object
         EXPORTING
           ir_data        = lr_data
           iv_function_id = lv_function_id
           iv_data_object = 'IT_DFKKOP'
           iv_timestamp   = lv_timestamp
         IMPORTING
           er_data        = ls_name_value-value.
     CATCH cx_fdt_input.
   ENDTRY.
   INSERT ls_name_value INTO TABLE lt_name_value.
   "THEN CALL THE BRFPLUS FUNCTION
   TRY.
       CALL METHOD cl_fdt_function_process=>process
         EXPORTING
           iv_function_id = lv_function_id
           iv_timestamp   = lv_timestamp
         CHANGING
           ct_name_value  = lt_name_value.
     CATCH cx_fdt_input cx_fdt INTO exc.
       MESSAGE exc TYPE 'E'.
   ENDTRY.
   "NOW GET THE RESULT FROM THE CALL TO THE BRFPLUS FUNCTION
   cl_fdt_function_process=>get_context_value( EXPORTING iv_function_id      = lv_function_id
                                                         iv_data_object      = 'EV_AMOUNT'
                                                         iv_timestamp        = lv_timestamp
                                               IMPORTING ev_data             = EV_AMOUNT ).
ENDFUNCTION.

Similar Messages

  • How to get sum amount (wrbtr) from table BSIS group by gjahr hkont monat

    Hello! I am new to this forum, and to ABAP. Hope my question is not obvious.
    I want to get sum amount from table BSIS, group by year, period an account. Normally I will try a SQL select like this:
    SELECT gjahr monat hkont sum( wrbtr ) as wrbtr INTO CORRESPONDING FIELDS OF TABLE itab FROM BSIS WHERE (itabcond) GROUP BY gjahr monat hkont .
    The problem is that the amount in field wrbtr is all positive. The result gets wrong. The debet/credit indicator shkzg determines what is positive/negative. How to solve this in the most efficient way? Should I read all accounting documents into an internal table, and loop through them, changing the sign, and then make some new select, or is there a better way?
    Regards Dag-Egil
    Message was edited by:
            Dag-Egil Bull Sletholt

    Here are the objects in the trace list:
    SKB1
    USR05
    TRDIR
    SKA1
    SKAT
    SKB1
    BSIS
    PRPS
    BSAS
    V_LTDX
    USR02
    RFBLG
    V_LTDX
    LTDX
    RTXTH
    RTXTF
    RTXTT
    TRDIR
    The most of this call to this tables returns 1-2 records, apart from BSIS, where it returns 10 records. This is the same as accounting documents in the transaction FBL3N. When i try this again with more records returned I still have no call to table GLT0.

  • Sum(amount) from 4 tables in sql

    Hi, Everyone,
    I have 4 tables which has pr_code,amount in each table.
    I need the sum(amount) for each pr_code from all the four tables?
    How could i write a sql to achieve this?
    Please help!
    Regards
    Su

    one option would be:
    select sum(cnt) sum_cnt
      from (select count(*) cnt from user_tables
             union all
            select count(*) cnt from user_objects
             union all
            select count(*) cnt from user_indexes
       SUM_CNT
           151

  • SUM - amount of product in all WAREHOUSEs

    Hi
    I am sql beginner and have a problem with collecting data from Oracle DB.
    I have a table ODT with all the products (nr of product and nr of warehouse are the PK) (NTWR and NODD).
    for every warehouse the product has its row.
    for example product nr 658:
    NAME NTWR NODD AMOUNT
    EXAMPLEPRODUCT658 658 1 30
    EXAMPLEPRODUCT658 658 2 207
    EXAMPLEPRODUCT658 658 3 1602
    I'd like to learn how to sum the amount for NODD.
    Example output
    NAME NTWR AMOUNT
    EXAMPLEPRODUCT658 658 237 //the amount for NODD 1&2
    EXAMPLEPRODUCT768 768 568 //the amount for NODD 1&2
    I made a query like this to sum amount for a product by entered number:
    SELECT SUM(SUMAMO) FROM (SELECT ODT.AMOUNT SUMAMO, ODT.NTWR, ODT.NAME FROM ODT WHERE ODT.NTWR = '657' AND ODT.NODD IN (1,2))
    and it works for one product
    great! :) but i entered this query into larger one with product number and name:
    SELECT * FROM
    SELECT DISTINCT a.NTWR,
    (SELECT SUM(SUMAMO) FROM (SELECT ODT.AMOUNT SUMAMO, ODT.NTWR, ODT.NAME FROM ODT WHERE ODT.NTWR = a.NTWR AND ODT.NODD IN (1,2))),
    a.NAME
    FROM ODT a)
    and i have an error for a.NTWR in SUM -> bad identifier
    What can i do to count sum for every product?
    1. Sorry for my English
    2. I would appreciate any help

    Can you send me the exact query that you are using?
    But make sure that in group by clause, you are using the same arguments, as there are present in your select statement
    for eg
    incorrect one
    select a,b from tem
    where a=1
    and b=2
    group by b;
    Correctone
    select a,b from tem
    where a=1
    and b=2
    group by a,b;

  • Sum amount within a date range

    I have 2 tables where I Need to sum up sales amount within a booking date range.
    Below an example to help illustrate this task.
    Table1:
    CustomerID BookingDate (YYYY-MM-DD)
    1 2014-04-29
    1 2014-07-30
    2 2014-03-31
    2 2014-06-30
    Table2:
    CustomerID SalesDate (YYYY-MM-DD) Amount
    1 2014-01-30 20
    1 2014-02-25 30
    1 2014-05-20 100
    1 2014-07-30 200
    1 2014-09-30 80
    2 2014-03-20 50
    Result:
    CustomerID BookingDate (YYYY-MM-DD) Sum(Amount From Table2)
    1 2014-04-29 50 -- SalesDate between 2014-01-01 and 2014-04-29
    1 2014-07-30 300 -- SalesDate between 2014-04-30 and 2014-07-30
    2 2014-03-31 50 -- SalesDate between 2014-01-01 and 2014-03-31
    2 2014-06-30 0 -- SalesDate between 2014-04-01 and 2014-06-30

    Please try this code:
    declare @Table1 table
    (CustomerID int,BookingDate date );
    insert @Table1
    values
    ( 1, '2014-04-29' ),
    (1, '2014-07-30' ),
    (2, '2014-03-31' ),
    (2, '2014-06-30') ;
    declare @Table2 table
    (CustomerID int, SalesDate date, Amount int);
    insert @Table2
    values
    (1,'2014-01-30',20) ,
    (1,'2014-02-25',30) ,
    (1,'2014-05-20',100) ,
    (1,'2014-07-30',200) ,
    (1,'2014-09-30',80) ,
    (2,'2014-03-20',50) ;
    with cte as
    select
    CustomerID,
    BookingDate ,
    row_number() over (partition by CustomerID order by BookingDate ) as rn
    from @Table1 )
    , cte2 as
    select
    T2.CustomerID ,
    isnull(T1.BookingDate, '2014-01-01') as FromDate,
    T2.BookingDate as ToDate
    from cte as T1
    right join cte as T2
    on T1.rn = T2.rn - 1
    and T1.CustomerID = T2.CustomerID
    select
    b.CustomerID ,
    b.ToDate as BookingDate,
    isnull(sum(a.Amount), 0) as [Sum(Amount From Table2)]
    from @Table2 as a
    right join cte2 as b
    on a.CustomerID = b.CustomerID
    and a.SalesDate > b.FromDate
    and a.SalesDate <= b.ToDate
    group by
    b.CustomerID ,
    b.ToDate;
    T-SQL Articles
    T-SQL e-book by TechNet Wiki Community
    T-SQL blog

  • How to do "for each month in 2008 sum amount where category is cash"

    The table format is:
    Date(MM/DD/YYYY) Amount Description Category Account
    01.02.2008 -21000 benzina (C) Calatorii Cash
    01.04.2008 -2000 Mancare (C) Calatorii Cash
    01.05.2008 -2000 Mancare (C) Comisioane Cash
    05.12.2008 4706 diverse (C) Comisioane BT - Mondo
    08/25/2008 8807 diverse (C) Calatorii BRD - PFA
    08/25/2008 104000 diverse (C) Comisioane BRD - Multiplan
    10.10.2008 6385849 diverse (C) Comisioane BRD - Atucont
    10/26/2008 943699 diverse (C) Calatorii BRD - ISIC
    10/27/2008 95313 diverse (C) Comisioane Cash
    10/28/2008 -300 Comisioane (C) Comisioane BRD - ISIC
    I am trying to do the following:
    for each month in 2008
    sum (Amount) where Category is (C) Calatorii
    =>
    January -23000
    February 0
    for each month in 2009 up until now
    sum (Amount) where Category is Cash
    =>
    January 35000
    With these 2 samples I can manage the other functions I need.
    Thanks in advance.

    Question asked and responded several times.
    In column H of the first table I inserted the formula:
    =YEAR(B)*100+MONTH(B)
    In column B of the second table, the formula is:
    =SUMIFS(Tableau 1 :: C,Tableau 1 :: G,"=Cash",Tableau 1 :: H,"="&A)
    CAUTION
    I don't know your system settings.
    If your system uses the decimal comma, you will have to use:
    =SUMIFS(Tableau 1 :: C;Tableau 1 :: G;"=Cash";Tableau 1 :: H;"="&A)
    Yvan KOENIG (from FRANCE jeudi 23 avril 2009 15:04:49)

  • USING SUM IN INTERNAL TABLE

    plz give me a simple example for using SUM in internal table and do some calculations in the same internal table.

    HI
    CHECK WITH THIS
    Syntax
    SUM.
    Effect
    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.
    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.
    Example
    Control level processing for creating a list. At the end of line groups, the total of reserved places is calculated and issued.
    DATA: sflight_tab TYPE SORTED TABLE OF sflight
                      WITH UNIQUE KEY carrid connid fldate,
          sflight_wa  LIKE LINE OF sflight_tab.
    SELECT *
           FROM sflight
           INTO TABLE sflight_tab.
    LOOP AT sflight_tab INTO sflight_wa.
      AT NEW connid.
        WRITE: / sflight_wa-carrid,
                 sflight_wa-connid.
        ULINE.
      ENDAT.
      WRITE: / sflight_wa-fldate,
               sflight_wa-seatsocc.
      AT END OF connid.
        SUM.
        ULINE.
        WRITE: / 'Sum',
                  sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
        SKIP.
      ENDAT.
      AT END OF carrid.
        SUM.
        ULINE.
        WRITE: / 'Carrier Sum',
                  sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
        NEW-PAGE.
      ENDAT.
      AT LAST.
        SUM.
        WRITE: / 'Overall Sum',
                  sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
      ENDAT.
    ENDLOOP.
    Hope this solves ur problem....
    <b>do reward if useful....</b>
    regards
    dinesh

  • Sum amount - Positive and negative

    How do I have a select statement that sum up all the negative and positive values into 2 serperate column? sth like this:
    SELECT sum(amount) as negative, sum(amount) as positive FROM account_table WHERE customer_id = 111;Here is how the output look like when I retrieve the amount of customer_id = 111:
    Amount
    1.4
    300
    -1.22
    -100The expected output that I want should be like this:
    Positive          Negative
    301.4                -101.22

    DECODE and SIGN functions can help
    SQL> select * from t
      2  /
           VAL
             1
            -2
             3
            -4
             5
            -6
             7
            -8
             9
           -10
    10 rows selected.
    SQL> select sum(decode(sign(val),1,val)) pos, sum(decode(sign(val),-1,val)) neg
      2    from t
      3  /
           POS        NEG
            25        -30

  • Different value in the sum in a table of Desktop Intelligence

    Greetings, I created a report in Desktop Intelligence and I created a variable that contains the sum of the table. The table gives a value but when I put the variable in other part of the report give a total different value. When I checked the table contains some duplicate values. I used Avoid Duplicate Row Aggregation but the problem is worst. How can I remove the duplicate values in a row of table ?

    Hi  Miguel Rodriguez,
    what is the meaning of sum of table???
    i didnot  understud.
    aggregation performence is good when you make A object as measure Object in Universe level.
    if you want to like this:
    customer      product_1       product_2      product_3
        A             10                  50               60
        B             20                  60               40
        C             30                  70               20
        D             40                  80               80
    create a variable    PRODUCT
    =Sum( [product_1]  + [product_1] + [product_1])
    customer      product_1       product_2      product_3                    PRODUCT
        A             10                  50               60                   120
        B             20                  60               40                   120
        C             30                  70               20                   120
        D             40                  80               80                   200
    Next Click on Product column     File menu   -
    > Insert -
    > calculations -
    >Sum
    customer      product_1       product_2      product_3                    PRODUCT
        A             10                  50               60                   120
        B             20                  60               40                   120
        C             30                  70               20                   120
        D             40                  80               80                   200
                                                                            Sum= 560
    All the best,
    Praveen

  • Sum in 2 tables?

    How to get sum of 2 tables on the third table on one sheet?

    Regarding adding a screen shot to your post:
    Command-Shift-4, Click and Drag over the area you want to image.
    The graphic file will appear on your Desktop.
    Upload the file to a photo-sharing internet site. You will need to create an account on one if you haven't already done that.
    Select the doc on the sharing site and copy the link info.
    Paste the link into your post.
    Regards,
    Jerry

  • How can I subtract in formcalc  sum(amount[0],amount[1],amount[2])

    How can I subtract amount[3] from this sum?  sum(amount[0],amount[1],amount[2])

    sum(amount[0], amount[1], amount[2]) - amount[3]
    Kyle

  • Sum from cluster table

    I want to make a SUM for a field from KONV table. Making the sum directly doesn't works because konv is a cluster table. What is the code for making the sum from this table?
    Thank you.

    Hi,
    You can proceed with normal selection process ie : fetch the data into and internal table and then later
    you can loop that particular internal table and collect it into another internal table  to sum up the values.
    for example :
             select * from ( your required field which you want )
                       from konv
                        into table it_konv.
    if it_konv[] is not initial.
         loop at it_konv into wa_konv.
            wa_konv to wa_collect.
    collect wa_collect to it_collect.
    endloop.
    collect statement will full fill your requirment
    Let me know if you need further information
    Regards
    Satish Boguda

  • Query in fetching invoice amount from table EKBE

    Hi all,
    In my custom report  the invoice amount is taken from the field  ekbe-dmbtr and is displayed wrongly.
    For a particular Purchase order the account  assignment table EKKN has only one entry and for the same Purchase order the Purchase order history table EKBE has two entries.
    For eg :
    Table EKKN
    Purchase order       Item               Seq Access number
    20900753               000001            01
    Table EKBE
    Purchase order       Item               Seq Access number   Material Doc Number        Amount(DMBTR)
    20900753               000001            01                              5105606685                      500
    20900753               000001            99                              5105606685                      500
    There is a loop at EKBE within the loop there is a IF condition which checks if
    IF EKBE-PO number EQ EKKN-PO number and
    EKBE-Item = EKKO-Item and
    EKBE-Seq Access Number = EKKN-Seq Access number.
    When the above condition is satisfied then the EKBE-DMBTR is added to the o/p field.
    ENdloop.
    In this case(several account exists for one mat doc,accounting dept use occasionally such cases) since EKKN does not hv seq access number 99 it does not take the second line into consideration so the amount displayed in the output has the value 500 instead of expected value 1000(sum of both the lines 01 and 99)
    Can you please offer suggestion on how to solve this issue.I want to know if i can ommit the Seq access number check in the IF condition.In that case i would get the expected result 1000,but will it affect some other functionality.Or is there any other way to solve this.

    Hi,
         We cannot say that Seq Access number is unimportant as it depends on the requirements of the client.....
    Seq Access  is a number defining the account assignment i. e which account should be posted in a transaction ( see documentation of the data element of seq Access ).
    We can omit checking of sequential number . Use read table EKKN instead of IF condition as we can check for multiple values of table EKKN.
    Thanks,
    Viquar Iqbal

  • Sum in Internal Tables

    Dear Friends,
    I AM WRITING A REPORT TO SHOW THE ALL THE POs WHOSE GRs HAS BEEN DONE BUT NOT THE IRs.
    LIKE :-
    Serial_no    Vendor_no    vendor_name     Po_no         ItemNo       GR_no          Ref_Doc_num          Amount
    I GOT THE REPORT BUT NOW MY USER SAYS ....
    HE WANTS one recod (Serial_no) if po_no and GR_no and ref_doc_num are same with Amount summed up.
    so that serial number will be less and and he will get the total amount of the pending GR.
    I am not getting the logic how shall I sum up the amounts comapring po, gr and Ref doc no.
    Regards,
    jeevan.

    Thanks for your replies. but i am not getting that......
    i have an internal table with POs ..item nos...grs..ref no..... anmount..
    now i have to get it in another internal table where there will be only Serialno .. po.no.gr..and ref and amount summed up all the similar ref numbers.
    here is code.. its not optimized...but see... i have included
    *& Report  ZMMR_TEST2
    REPORT  ZMMR_TEST2.
    TABLES : EKKO, EKBE, LFA1.
    TYPE-POOLS : SLIS.
    DATA : begin of IT_ekbe4 OCCURS 1  ,
            i_index type i,
            lifnr TYPE ekko-lifnr,
            name1 TYPE lfa1-name1,
            no_name type string,
            ebeln TYPE ekbe-ebeln,
            ebelp TYPE ekbe-ebelp,
            belnr TYPE ekbe-belnr,
            xblnr TYPE ekbe-xblnr,
            dmbtr TYPE ekbe-dmbtr,
            bewtp TYPE ekbe-bewtp,
            bwart TYPE ekbe-bwart,
            menge type ekbe-menge,
           end of IT_ekbe4.
    DATA : it_ekbe like ekbe occurs 1 with header line,
          it_ekbe2 like ekbe occurs 1 with header line,
          it_ekbe3 like it_ekbe4 occurs 1 with header line.
    DATA : V_TABIX LIKE SY-TABIX.
    *DATA : it_ekbe4 type standard table of s_ekbe4 initial size 0,
           wa_ekbe4 type s_ekbe4.
    data: fieldcatalog type slis_t_fieldcat_alv with header line,
          gd_tab_group type slis_t_sp_group_alv,
          gd_layout    type slis_layout_alv,
          gd_repid     like sy-repid.
    *selection screen.
    select-options : s_date for ekbe-budat.
    PARAMETERS DOC_TYP LIKE EKKO-BSART.
    *Start-of-selection.
      select a~ebeln a~ebelp a~bewtp a~bwart a~xblnr a~dmbtr a~belnr
                b~lifnr
                c~name1
                into  (it_ekbe4-EBELN, it_ekbe4-ebelp, it_ekbe4-bewtp,
    it_ekbe4-bwart, it_ekbe4-xblnr, it_ekbe4-dmbtr, it_ekbe4-belnr,
    it_ekbe4-lifnr, it_ekbe4-name1)
                from ekbe as a
                inner join ekko as b
                on a~ebeln = b~ebeln
                inner join lfa1 as c
                on b~lifnr = c~lifnr
                where a~budat in s_date
                and a~bewtp = 'E'
                and a~bwart in ('101','102', '122')
                and b~bstyp = 'F'
                and b~bsart  = DOC_TYP
                and b~ekorg = '1000'
         select ebeln ebelp bewtp bwart
                  from ekbe
                  into (it_ekbe2-EBELN , it_ekbe2-ebelp , it_ekbe2-bewtp ,
    it_ekbe2-bwart)
                  where ebeln = IT_EKBE4-EBELN
                  and ebelp = it_ekbe4-ebelp
                  and bewtp = 'Q'.
          APPEND IT_EKBE2.
        ENDSELECT.
         APPEND IT_EKBE4.
      ENDSELECT.
      LOOP AT IT_EKBE4.
        V_TABIX = SY-TABIX.
        READ TABLE IT_EKBE2 WITH KEY EBELN = IT_EKBE4-EBELN ebelp =
    it_ekbe4-ebelp.
        IF SY-SUBRC = 0.
          DELETE IT_EKBE4 INDEX V_TABIX.
        ENDIF.
        ENDLOOP.
        clear v_tabix.
      LOOP AT IT_EKBE4.
        if ( it_ekbe4-bwart = '102' or it_ekbe4-bwart = '122' ).
          it_ekbe4-dmbtr = it_ekbe4-dmbtr * -1.
        endif.
           it_ekbe3-i_index = sy-tabix.
           it_ekbe3-ebeln = it_ekbe4-ebeln.
           it_ekbe3-ebelp = it_ekbe4-ebelp.
           it_ekbe3-belnr = it_ekbe4-belnr.
           it_ekbe3-xblnr = it_ekbe4-xblnr.
           it_ekbe3-dmbtr = it_ekbe4-dmbtr.
           it_ekbe3-lifnr = it_ekbe4-lifnr.
           it_ekbe3-name1 = it_ekbe4-name1.
           concatenate it_ekbe4-name1 '/' it_ekbe4-lifnr into  it_ekbe3-no_name.
    *separated by space.
           append it_ekbe3. "YOU TOLD THIS TO BE COLLECT."
          Collect it_ekbe3 into it_ekbe3.
      ENDLOOp.
    sub totals.
    *loop at it_ekbe3.
    *collect
    *endloop.
    loop at it_ekbe3.
    write:/ it_ekbe3-ebeln , 'gr', it_ekbe3-belnr , 'ref', it_ekbe3-xblnr, 'amount', it_ekbe3-dmbtr.
    endloop.

  • Comparing sum from two tables and correct by difference of sum in second t,

    Hello Guys,
    I have a very tricky task that I cant get my head around.
    The sample data looks like that:
    Master Table
    Claim------Booking--------Debit--------Credit------------MasterAmout          
    1------------1----------------D---------------------------------15.3          
    1------------2----------------D---------------------------------480.6          
    1------------3------------------------------C-------------------496.8          
    ------------------------------------------- 0.9          
    Slave Table
    Claim-----Booking-----Debit------------Credit----------SlaveAmout------- SlaveCorrection
    1------------1------------D------------------------------------15.3---------------14.5
    1------------2------------D------------------------------------480.6-------------480.6
    1------------3-----------------------------C-------------------496---------------496
    -------------------------------------------0.1--------------------------------------0.9
    The booking have a total amout of 0.1 but has to be corrected to 0.9 because the master table has 0.9.
    Booking 1 requires a correction so the slave table also has a total of 0.9 (business rule is, corrections only on first booking). so we have
    to change the amount from 15.3 to 14.5. I plan my SQL like that:
    1. Sum bookings from both tables for each Claim. Compare the two for each individual claim.
    2. If the Master sum of the amount shows a difference between the master and slave table
         2.1 select top 1 booking from slave table for the specific claim and increase/decrease by the difference of those two amounts.
    Does that make sense?

    Hello
    It would be really helpful if you could a) format your posting properly using the {noformat}{noformat} tags around your data and b) provide create table/ insert statements.
    Anyway, from what you described -
    Booking 1 requires a correction so the slave table also has a total of 0.9 (business rule is, corrections only on first booking). so we haveto change the amount from 15.3 to 14.5
    You could achieve this with an analytic function and an outer join...WITH Master_Table AS
    SELECT 1 Claim, 1 booking, 'D' debit,NULL credit,15.3 masteramount from dual union all
    SELECT 1,2,'D',NUll,480.6 from dual union all
    SELECT 1,3,NULL,'C',496.8 from dual
    Slave_Table AS
    ( SELECT 1 claim, 1 booking, 'D' debit, null credit, 15.3 slaveamount,14.5 slavecorrection from dual union all
    SELECT 1,2,'D',NULL,480.6,480.6 from dual union all
    SELECT 1,3,null,'C',496,496 from dual
    SELECT
    m.claim,
    m.booking,
    m.debit,
    m.credit,
    NVL(s.slavecorrection,m.masteramount) amount
    FROM
    master_table m
    LEFT OUTER JOIN
    ( SELECT
    claim,
    booking,
    slaveamount,
    slavecorrection,
    ROW_NUMBER() OVER(PARTITION BY claim ORDER BY booking) rn
    FROM
    slave_table s
    ) s
    ON
    ( s.claim = m.claim
    AND
    m.booking = s.booking
    AND
    s.rn = 1
    CLAIM BOOKING D C AMOUNT
    1 1 D 14.5
    1 2 D 480.6
    1 3 C 496.8
    HTH
    David                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for