SQL Query to reduce Commission amount on a Sales Order

I hope that this is the right forum to post this and hope that someone may be able to help?
I have a customer who wants to manipulate the amount of commission given on a sales order for some specific items.
I have set up a UDF on the item master record called U_Commission_exempt. I have given this valid answer of 'Y' = Yes and 'N' = No
When I load a sales order, the commission amount is derived from the Sales Employee logged against the BP on the BP Master Data.
When you enter the Item No. onto the Sales order, I have set up a formatted search that goes and looks at the Item Master Record, and if the U_Commission_Exempt is set to 'Y' the commission amount on the sales order is supposed to be reduced to zero.
My problem is, I can not get the SQL to do exactly as I want - at the moment it is reducing the amount to zero every time.
Can anyone offer any thoughts on how the SQL should look?
Thanks

Thanks for all the Abhishek - I really do appreciate all the help on this as it's been really furstrating trying to get over this.
Would you be able to finalise the SQL for me as I still dont quite understand what you are saying - If you look at Gordon's attempts from earlier, the brackets etc all look different to your version.
If the OITM record returns 'N', the commission needs to come from OSLP 'Commission' which is stored on the sales order as RDR1 'Commission'

Similar Messages

  • SQL Query to pull RMA number and corresponding sales order number info

    Hi,
    I do not have good idea on the data model. I was asked to pull Sales order info & corresponding Return order (RMA) information. Appreciate if someone can provide me the query.
    thanks.

    I believe you have to use the link_to_line_id column in oe_order_lines_all.
    For a return line, that column points to the original (i.e shipment) sales order line id.
    Hope this helps,
    Sandeep Gandhi

  • Credit management how to block amount on particular sales order

    hi,
    Client want to block amount on sales order.
    If customer is having credit limit of 100000 n there are 3 sales order , sales order 1 amount is 50000,sales order 2 amount is 30000 and sales order 3 amount is 40000...
    Now customer is coming n saying I want 40000 amount material of sales order 1.here my client want to block 50000 for sales order 1 so customer can not use amount for other sales order , system will check credit limit is 100000 and out of 100000 system should block 50000 for order 1.
    Solution required...
    If this is not possible then suggest me possible solution.
    please suggest...

    please note what you require is not possible in SAP.
    Therefore there is no standard solution.

  • Condition value currency based on amount currency in sales order creation

    Hi all,
          I have a requirement where during creation of a sales order with line items in the conditions tab where if condition type is EDI2 the amount currency should be USDN and accordingly condition value currency should also be changed to USDN.
    I found the exit to acheive this and succeeded in changing the amount currency to USDN but condition value  currency is also changing but for all above condition types.
    I am using form userexit_field_modific_kzwi.
    loop at xkomv where kschl = 'EDI2'.
    XKOMV-WAERS  = 'USDN'.
    MODIFY XKOMV INDEX SY-TABIX TRANSPORTING WAERS .
    select single waers into komk-waerk from TCURC where waers = xkomv-waers.
    endloop.
    Thanks & Regards
    Jerry

    Hi Vindo,
    Thank you for your replay.
    There is no Net value column in pricing procedure. Am able to change the Net value in the condtion tab of  Item level but the problem is , the change is  not  reflected in condition tab of sales order header net value.This is creating a problem when we try to post the invoice document .
    Cheers,
    sravan.
    Edited by: Rob Burbank on May 7, 2010 4:30 PM

  • Problem in blocking that amount in the sales order through routein

    Dear Experts,
    We are facing a problem in Routine,
    We have developed a Z rebate module in that we are saving the accrual value for a perticular customer in "Z" Table.
    We are having a senerio of adjusting that perticular accrued amount in the next month sales order as a discount  at the item level. In table  itself we fix this much amount as to flow to sales order for a Perticular material (EX- for 100001 material 5 rs per TON).
    We have devaloped 901 routine that will go to "z" table and check any accrued amount is there then depending on the quantity ordered it will take accrual amount (simultanusly it will block the respective amount in the "z" table) and it will come and update in sales order pricing. Once we save sales order then it will reduse the perticular amount in from "z" table.
    Now we are facing a problem, when we create a sales order first time depending on quantity routine will pull the value from "z" table and it will block respective amount in the "z" table. but before saving the sales order if you change the quantity again (EX- from 100 qty to 200 qty) then the routine is not pulling any value because the amount is already blocked. 
    Can any one tell me how check in run time this was the earlier quantity and this is changes quantity Or is there any logic to block that perticular amount.
    Regards
    Nagesh

    HI Sree
    Could you please justify your post stating
    "Now we are facing a problem, when we create a sales order first time depending on quantity routine will pull the value from "z" table and it will block respective amount in the "z" table. but before saving the sales order if you change the quantity again (EX- from 100 qty to 200 qty) then the routine is not pulling any value because the amount is already blocked. "
    Your discount is based on qty, so when you are adding new item means order qty increased, so discount is applicable.
    Or please put your requirement clearly

  • Update  Customer's Credit Exposure amount when saving sales order

    Hi All,
    My requirement is to update the Credit Exposure amount(KNKK-SKFOR) of the Payer based on the open items for the payer when saving a sales order.
    I checked the UserExit USER_CREDIT_CHECK2 however this is not working when I am trying to update the KNKK-SKFOR value in this userexit.
    Please help.
    Thanks.

    Dear Debashish
    As per my understanding, this is because the credit limit check is always applicable at 2 levels only i.e. Sales Order and Delivery.
    u r talking about Open Billing Doc and Open Items, but this is also covered within Open Sales Orders and Deliveries, isn't it?
    Hope this will help u.

  • Query needed to find what time a sales order was closed

    Hi to All,
    Need to find when a sales order was closed. Meaning the exact time. I know the flags that needed to be considered. But what table/column holds the exact time that the sales order was closed.
    Thanks

    If your workflow process details are not purged below query end_date will be order closed date.
    select a.instance_id
    , to_char(b.begin_date, 'DD-MON-RR HH24:MI:SS') begin_date
    ,to_char(b.end_date, 'DD-MON-RR HH24:MI:SS') end_date
    , a.process_name process
    from  wf_process_activities a, wf_item_activity_statuses b
    where b.item_type        = 'OEOH'
    and   b.item_key     in (select to_char(header_id) from oe_order_headers_all where order_number = <Ordrer_num>)
    and a.process_name = 'CLOSE_HEADER_PROCESS'.
    and   b.process_activity = a.instance_idIn R12 if you do not have any customizations ,
    Current close process defines wake up time as last day of month, there is no time component.
    So order will be eligible from midnight of the last day of the month.
    First run of Workflow background process program for item type OEOH should be closing them.
    For example : If the Wait activity in 'Close - Order' process encountered first time on 09-May-2013(Any time in the month of May), then Wake up time will be last day of current month I.e. 31-May-2013 00:00.

  • SQL Query to Roll up amounts starting from a lower to higher level

    with data as (select 'C' Child, 'P' as parent, 11 amount from dual
      union all select 'C1', 'C', -2 from dual
      union all select 'C2', 'C', 3 from dual
      union all select 'C3', 'C', -8 from dual
      union all select 'C4', 'C', 10 from dual
      union all select 'C11', 'C1', 7 from dual
      union all select 'C12', 'C1', 12 from dual
      union all select 'C21', 'C2', 5 from dual
      union all select 'C22', 'C2', 9 from dual
      union all select 'C31', 'C3', 6 from dual
      union all select 'C32', 'C3', -4 from dual
      union all select 'C41', 'C4', -3 from dual
      union all select 'C42', 'C4', 13 from dual
      union all select 'C111', 'C11', 16 from dual
      union all select 'C121', 'C12', 8 from dual
    ) Select * from data order by 2
    Hi Experts,
    I have the following table with parent child relationship which I would like to roll up starting from a lower to a higher level. The catch here is as I move up the level i should replace the amount for a parent with the aggregate value of its children and grand total aggregated amount should be in C
    For example; In the given sample data c111 rolls up to c11 as 16 (please note: the amount for c11 is 7 should not be added to 16 rather replaced by 16) which should further roll up to c1.
    This means c1 = c11c12; c11 = c111 = 16 so, c1= 1612 instread of 16712.
    Since this is a interim table, i do not have any control on how many levels it might contain.
    So dynamically, i need a query which would rollup and aggregate the amount from a lower to a higher level moving up from the bottom.
    Is this possible? I look forward to all the help. Thanks in advance.

    SQL> with data as
      2  (
      3    select 'C' Child, 'P' as parent, 11 amount from dual
      4    union all select 'C1', 'C', -2 from dual
      5    union all select 'C2', 'C', 3 from dual
      6    union all select 'C3', 'C', -8 from dual
      7    union all select 'C4', 'C', 10 from dual
      8    union all select 'C11', 'C1', 7 from dual
      9    union all select 'C12', 'C1', 12 from dual
    10    union all select 'C21', 'C2', 5 from dual
    11    union all select 'C22', 'C2', 9 from dual
    12    union all select 'C31', 'C3', 6 from dual
    13    union all select 'C32', 'C3', -4 from dual
    14    union all select 'C41', 'C4', -3 from dual
    15    union all select 'C42', 'C4', 13 from dual
    16    union all select 'C111', 'C11', 16 from dual
    17    union all select 'C121', 'C12', 8 from dual
    18  )
    19  , data1
    20  as
    21  (
    22    select parent
    23         , child
    24         , lpad('-', (level-1)*3, '-') || parent tree_structure
    25         , amount
    26         , case when connect_by_isleaf = 1 then amount else 0 end amount_leaf
    27      from data
    28     start with parent = 'P'
    29   connect
    30        by parent = prior child
    31  )
    32  select parent as node
    33       , tree_structure
    34       , amount_sum
    35    from data1
    36   model
    37   dimension by
    38   (
    39      child
    40    , parent
    41   )
    42   measures
    43   (
    44      amount_leaf as amount
    45    , tree_structure
    46    , 0 amount_sum
    47   )
    48   rules automatic order
    49   (
    50      amount_sum[any,any]= amount[cv(),cv()] + nvl(sum(amount_sum)[any, cv(child)],0)
    51   );
    NOD TREE_STRUCTURE            AMOUNT_SUM
    P   P                                 50
    C   ---C                              24
    C1  ------C1                          16
    C11 ---------C11                      16
    C1  ------C1                           8
    C12 ---------C12                       8
    C   ---C                              14
    C2  ------C2                           5
    C2  ------C2                           9
    C   ---C                               2
    C3  ------C3                           6
    C3  ------C3                          -4
    C   ---C                              10
    C4  ------C4                          -3
    C4  ------C4                          13
    15 rows selected.

  • Freight Amount-KF00 in Sales Order/Invoice

    Hi All,
    requirement is regarding Capturing Freight costs involved in Transportation.
    Transportation charges are based on ,
    Incoterms_INCO1 ,
    Transporter_LIFNR ,
    Departure zone(Ship.Point)_LZONEA,
    Destination Zone(Customer-Ship to Party)_LZONEZ ,
    Shipping conditions - VSBED
    I have created cond table with the above mentioned fileds & assign it to the KF00 access sequence. Condition record has been maintianed.
    But its not picking while creating sales order-
    In Pricing analysis -
    Transporter/Vendor
    Dep.Zone
    Dest.Zone
    is not picking.
    fyi: - Transporter, am using Partner Function_CR
    anythoughts would be highly appreciated

    Hi!
    You can try with traffic points insted of zones (KNOTA and KNOTZ). If you need departure and destination zones, verify those appears on the cost document you may see those doesnt appears. Maybe an exit could help you.
    For the transporter, maybe TDLNR field (forwarding agent) could be an option insted LIFNR.
    Regards,
    RP

  • Amount Difference in sales order and billing for one line item

    Hi experts,
    User created one sales order with three line items say line item10, line item20
    Line item 30.Line item 10 value is 5024.26 EUR in sales order. He did delivery for three line item and invoiced. But the problem is that the line item 10 value is changed i.e. 5024.28 EUR in Billing and the remaining line item values are correct. All the line items having same item category.
    I asked the user to cancel the invoice and PGI. He did that. And again he created the PGI and Invoice. But the value of line item 10 become 5024.27 EUR and again he cancels the invoice and the PGI. and again he created the PGI and Invoice. Now the value of line item 10 is correct i.e. 5024.26EUR in invoice.
    Note: No changes are carried out from sales order to billing and even in material also.
              I checked copy control settings also all are correct.

    Hi
    I think this is standard SAP issue of rounding the condition records at item level. Can you please share the netvalue for all the three items and the header net value at sales order and invoice level.
    kind regards
    sandeep

  • Query - Delivered quantity at schedule line of Sales Order

    Hi,
    I've realized a sales order report and i need extract for each schedule line the delivered quantity (VBEPD-VSMNG). How can i find the correct values?
    Thanks and best regards.
    Antonio

    Hi.
    You can use the function module RV_SCHEDULE_CHECK_DELIVERIES to get the delivered quantity corresponding to schedule line item  in sales order.
    Please refer below code:
    Internal table it_vbep has got field VSMNG which is the delivered quantity for each line item
      SELECT * FROM vbfa
        INTO  TABLE  it_xvbfa
        WHERE vbelv = <sales order numer>
        AND posnv = <sales order line item>
        AND vbtyp_v = 'C'.
        SELECT  * FROM vbup
        INTO TABLE it_xvbup
        WHERE vbeln = <sales order numer>
        AND posnr = <sales order line item>.
        SELECT * FROM vbep
        INTO TABLE it_vbep
        WHERE vbeln = <sales order numer>
        AND  posnr = <sales order line item>.
        SELECT  * FROM vbap
        INTO  TABLE it_xvbap
        WHERE vbeln = <sales order numer>
        AND  posnr = <sales order line item>.
        CALL FUNCTION 'RV_SCHEDULE_CHECK_DELIVERIES'
          EXPORTING
            fbeleg                  = <sales order numer>
            fposnr                  = <sales order line item>
          TABLES
            fvbfa                   = it_xvbfa
            fvbup                   = it_xvbup
            fxvbep                  = it_vbep
            fvbap                   = it_xvbap
          EXCEPTIONS
            fehler_bei_lesen_fvbup  = 1
            fehler_bei_lesen_fxvbep = 2
            OTHERS                  = 3.
    Regards,
    Sameer

  • Is it possible in PLD to add sql query ?

    Hi
    In Order report in PLD , i need to add the total amount of down payment . it doesn't exists in Order , so i need to do a sql query to display this amount .
    is it possible to add sql query in pld formula ?
    thanks ,
    regards
    laurent

    Hi,
    You cannot add sql query in PLD.If you need SQL query use Crystal report or on the document add UDF and try by adding FMS and then selecting UDF in pld
    Thanks,
    Neetu

  • Help with JSTL sql query

    i have a query that i want to pass a paramater to the query goes like this
    <sql:query var = "user" >
    SELECT AMOUNT,flag FROM SAVINGS_ACTIVITY_DETAILS WHERE ACCOUNT_ID =? AND AMOUNT >200000 AND Flag =1 AND ACCOUNT_ACTION_ID =6 AND Treated =0 ORDER BY created_date DESC
    <sql:param value="${test.accountId}"/>
    </sql:query>
    this will give an error on TLD attribute.................and i tested the value with the following code and it worked
    <c:set value="${test.accountId}" var="u"/>
    <c:out value="${u}"/>
    this will print out the value nicely now i need a way to be able to pass this value to the sql query
    Thanks

    Which version of jstl are you using? == JSTL1.1
    However the other two questions remain unanswered.
    What server are you using? Version?
    How are you importing the tag library?
    You can find out the server info with this snippet of a JSP:
    Working with server: <%= application.getServerInfo() %><br>
    Servlet Specification: <%= application.getMajorVersion() %>.<%= application.getMinorVersion() %> <br>
    JSP version: <%= JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion() %><br>
    Java Version: <%= System.getProperty("java.version") %><br>

  • Retrieve a range of records from SQL query Oracle

    I want to retrieve range of rows in Oracle database. This is the table structure:
    CREATE TABLE ACTIVESESSIONSLOG(
      ASESSIONID VARCHAR2(30 ) NOT NULL,
      USERID VARCHAR2(30 ),
      ACTIVITYSTART TIMESTAMP(6),
      ACTIVITYEND TIMESTAMP(6),
      ACTIVITY CLOB
    /This is the SQL command that I use to get rows from the table:
    SELECT * FROM ACTIVESESSIONSLOG WHERE ROWNUM >= 5 AND ROWNUM <= 10 ORDER BY USERID ASC;When I rum it no data is displayed. What is the proper way to get only 5 rows from the database?
    Best wishes
    Peter

    Is this SQL query valid?I tend to say no: ORDER BY is applied last, so your rownum is not in correct anymore:
    SQL> select rownum, ename, empno from emp order by empno
        ROWNUM ENAME           EMPNO
             3 SMITH            7369
             4 ALLEN            7499
             5 WARD             7521
             6 JONES            7566
             7 MARTIN           7654
             8 BLAKE            7698
             9 CLARK            7782
             2 SCOTT            7788
            10 KING             7839
            11 TURNER           7844
            12 ADAMS            7876
             1 JAMES            7900
            13 FORD             7902
            14 MILLER           7934
    14 rows selected.You either use analytic ROW_NUMBER() as in my previous post - or you need to nest once again:
    SQL> select rn, empno, ename
      from (select rownum rn, ename, empno
              from (  select ename, empno
                        from emp
                    order by empno))
    where rn between 4 and 5
            RN      EMPNO ENAME    
             4       7566 JONES    
             5       7654 MARTIN   
    2 rows selected.

  • How to create a Folder using a SQL Query?

    Hi
    How can I create a Folder (eg. C:\MyNewFolder) using SQL Query?

    Hi,
    I added some code in order to get the result from the xp_cmdshell command
    This returns null if successfull, if an error occurs returns the error message. May be useful instead of getting an sql error
    Code Snippet
    declare @cmdpath nvarchar(60), @Location nvarchar(100), @message nvarchar(max)
    set @Location = N'C:\Temp\Temp5'
    set @cmdpath = 'MD '+ @Location
    Create table #result
    result nvarchar(255)
    insert into #result (result) exec master.dbo.xp_cmdshell @cmdpath
    select @message = ISNULL(@message + ' - ','') + result from #result where result is not null
    select @message
    drop table #result
    Eralper
    http://www.kodyaz.com

Maybe you are looking for