SQL to fetch contract number for a sales order

Hello,
I am using API's to create service contracts, all is working well except one scenario - when install based item switches ownership.
I need some help crafting a query that will return the contract number, if one exists, for a particular sales order. I am trying to determine if a contract already exists so I can either create new contract header then add lines.... or add lines to existing.
I have this query so far, however it will return the prior/old service contract and not the most recent if an IB item is being resold after refurbish:
SELECT okh.id
FROM okc_k_headers_b okh
,okc_k_lines_b okl
,okc_k_items oki
,csi_item_instances cii
,oe_order_lines_all oolv
,oe_order_headers_all oohv
WHERE okh.id=okl.dnz_chr_id
AND oki.cle_id = okl.id
AND okh.sts_code <> 'TERMINATED'
AND to_char(cii.instance_id) = oki.object1_id1
AND oolv.line_id=cii.last_oe_order_line_id
AND oohv.header_id=oolv.header_id
AND okl.end_date >= trunc(sysdate)+vDuration
AND oohv.order_number=vOrderNumber
Thanks!
Any help would be great.

I found similar question here:
Relation between Order Number & Contract Number
But that query does not return contract number consistently for me. Meaning I know a contract exists related to a certain sales order yet query does not find it.
I am new to contracts I appologise for my ignorance
thanks
Edited by: user7513372 on Jul 6, 2010 11:23 AM

Similar Messages

  • How to Find Out The Production Order Number For The Sales Order Line Items

    Hi All,
    I want to know the number of production orders for each sales order line item. I know the sales order number .Can anyone tell me how the tables can be linked to get all the production order numbers for each sales order line item.

    I think it depends on your configuration. But check fields KDAUF and KDPOS in table AUFK.  or in table AFPO.
    Regards,
    Rich HEilman

  • Return a number for every sales order

    Hai All,
                 I have a sales order coming into a cube. Our model is in such a way that if we look at the records in the cube, there are more than one record for a sales order. I have to report on number of sales orders based on  period.
    I want to create a key figure to return "1" for every sales order and "0" for the repeated sales order numbers. so that in the report if I am asked how many sales orders are created in a period, I can just sumup the 1s.
    I would appreciate if any one could suggest a way for me. Can non-cumulative key figures help me?
    Thanks.

    Hi,
      to my knowledge, it's not possible with Bex reporting.
    1.  we have DS 2LIS_11_VAHDR DS, if you are extracting this data you can extract to some ODS. which will give Sales Order Header details.
    2. as i said through VBA coading, you can achive this.
    3. by implementing one more key figure(to calculate the number of Sales Orders) in the cube, we can achive this.
    all the best.
    Regards,
    Nagesh Ganisetti.

  • How to get the delivery number for the sales order

    hi
    how to get the delivery number for the sales order

    Hi,
    1. IN VA03, enter the sales order and click on the document flow button. From there you can check the delivery document.
    2. In SE11, enter VBFA(Document flow) table and enter the sales order in VBELV field and in VBTYP_N field enter 'J' to specify that you want to check if there is already a delivery document for that sales order.
    Hope it helps...
    P.S. Please award points if it helps...

  • PO number for B2B Sales Orders.

    Hello,
    B2B orders lines are in the status "PO Created".
    But while checking the PO number in the Supply TAB, PO number is blank and greyed out.
    Intrestingly we can see the PO line number.
    Any pointers?
    Thanks
    Radha.

    Hi Luko,
    Thanks for the notes.
    Note 746241.1 says the following
    When performing a back to back order for a lot controlled item and then an over-receipt of the original booked item within the tolerances, the status of the Sales Order is not changing from 'PO-Created' to 'Awaiting Shipping'. Reservations are not being transferred from PO to Sales order.
    It works fine if the quantity received is equal to the quantity ordered.
    we have receiving equal quantity as ordered.
    Please suggest.
    Thanks
    Radha.

  • Single idoc generation for multiple sales orders

    Hi,
    Pls let me know how do we generate single idoc for multiple sales orders.
    Its not collecting idoc. As we know we can generate an idoc for one sales order correspondingly
    my requirement is to generate single idoc number for multiple sales orders.
    Do we need to write a program.

    Amar,
    To understand take HRMD_A04 as example. Root segment has Maximum 9999999999 defined.
    Segm.type       E1PLOGI
    Minimum number  1
    Maximum number  9999999999
    Parent segment
    Hier.level      2
    This means that this IDOC types has capability to hold multiple HR Master data objects. PFAL program creates this IDOC and it has facility to mention the Objects per process, check selection screen.
    I checked for INVOICE01/02 its not possible there. Hope this clarifies.

  • How I can get the Billing Type for the sales order and its items

    How I can get the Billing Type for the sales order and its items. I mean from which SAP tables and how?

    Hi,
    You need to use two tables.
    First use VBFA. Enter the sales order number in the field Predecessar and the value M in SubCt field. This will give all the billing document number for the sales order items.
    Then use the billing document numbers in table VBRK, where in you can get the billing document type.
    Regards,

  • Equipement details history for the sales order.

    Hi,
    I want to find out the details of the equipment for a particular sales order.
    I have creatde a sales order, delivery and the billing. I used the serial number for my material.
    Now i have cancelled the billing and then reversed the PGI and then changed the serial number and then proceded with billing.
    Now in which table(s) can i find the details of the changed serial / equipment number for my sales order.
    Thanks and Regards,
    Raya.

    Hi Raya
    Your subject line and your question seem to differ so I am not sure I am understanading correctly...but if you are wanting to be able to see the change for the serial number and what the serial number used to be then...when you are in IQ09 go to enter your new serial number and execute from the detail screen go to extra and look at changes.
    Now if you are wanting to view the table of the sales order for the changes made...you can check the change log tables  cdpos and cdhdr
    You can also use transaction AUT10; put in transaction code VA02 and enter a date range to limit your search results
    Edited by: Kim Blair on Sep 7, 2011 9:24 PM
    Edited by: Kim Blair on Sep 7, 2011 9:35 PM

  • PL/SQL API for Creating Sales Order

    Hi,
    I am new to Oracle SOA 11g.
    I have done the Deleting Sales Order using PL/SQL API ( Oracle Apps Adapter ) [ API Name: OE_ORDER_PUB.DELETE_ORDER ] in SOA BPEL. While executing the BPEL, it is correctly deleting Sales Order in E Business Suite which is created in EBS User Interface. I don't face any problem while deleting the sales order.
    Now, in same way, I have to create a new Sales Order using PL/SQL API in SOA-BPEL. I don't find any API's related to creating Sales Order in Order Management Suite (OM_PF) -->Order Management (ONT) --> Sales Order (ONT_SALES_ORDER) --> PL/SQL --> Process Order API (OE_ORDER_PUB) in Module Browser.
    Please tell me which PL/SQL API to use to create new Sales Order in BPEL.
    Thanks,
    -- Gowtham
    Edited by: user8223943 on Feb 16, 2012 7:38 AM

    You may be on a different patch level. Can you ensure that you have applied all latest patches for your version?
    See sample code at http://jyotioraapps.blogspot.com/2009/08/use-of-oeorderpubprocessorder-to-create.html
    Hope this helps,
    Sandeep Gandhi

  • PL/SQL API for Creating Sales Order in E Business Suite from BPEL

    Hi,
    I am new to Oracle SOA 11g.
    I have done the Deleting Sales Order using PL/SQL API ( Oracle Apps Adapter ) [ API Name: OE_ORDER_PUB.DELETE_ORDER ]. While executing the BPEL, it is correctly deleting Sales Order in E Business Suite which is created EBS User Interface. I don't face any problem while deleting the sales order.
    Now, in same way, I have to create a new Sales Order using PL/SQL API. I don't find any API's related to creating Sales Order in Order Management Suite (OM_PF) -->Order Management (ONT) --> Sales Order (ONT_SALES_ORDER) --> PL/SQL --> Process Order API (OE_ORDER_PUB) in Module Browser.
    Please tell me which PL/SQL API to use to create new Sales Order in BPEL.
    Thanks,
    -- Gowtham

    You may be on a different patch level. Can you ensure that you have applied all latest patches for your version?
    See sample code at http://jyotioraapps.blogspot.com/2009/08/use-of-oeorderpubprocessorder-to-create.html
    Hope this helps,
    Sandeep Gandhi

  • In which table  we will find phone number for particular sales offic

    HI,
    My requrement is ,they are maintening two phone numbers per particular sales office.
    but in the table ADRC it is showeing only one phone number for particular sales office. where we can find second phone number.
    i want to print both phone number in the form.
    Regards
    suneela

    Hi,
    U can get 1st telephone no from ADRC ,
    Check table KNA1 or LFA1
    field id TELF2.
    If it is usefull pls reward pts.
    Regards
    Srimanta

  • How to find Ship to party number for a Sale doc.

    Hi,
    Currently, I have a sale doc number with type ZDR (Debit memo request). Could you please let me know how can I get the ship to party number for that document number.
    In General, Could you please show me how to get ship-to party number for a sale doc with all sale doc type ?
    Thanks,

    Hi Krishna,
    Your answer is correct, I just go to table VBPA pass the sale doc number & choose the partner function as ship to party, then I can get the ship-to-party ID.
    Hi Sandipsinh,
    The KUWEV is the customer master data view that is used in standard T-code. However It is not a table, therefore I can't get data from it.
    Hi  senya_1111,
    You know, with a sale order we have only one sold-to-party. However, we can have several corresponding ship-to-partys.
    Moreover, In table VBAK(Sale order header)  we just have sold-to-party not ship-to-party. That means we can get wrong value in case ship-to-party is not the same as sold-to-party.
    Overall, Thank all of you for your opinion.

  • Maximum number of Invoices for a Sales order

    Dear All,
    How many invoices we can make for a Sales order?
    Is there any maximum limit for that?
    How many documents can be shown in Document flow?
    Please let me know.
    Regards,
    Mullairaja

    hi mullairaja
    if in the case for partial deliveries you could process any number of invoices but only till the number of partial deliveries in the customer master data > sales area > shipping > partial deliery per item .....
    if the case of the sales order  is processed and delivery and COMPLETE  picking ...and PGI with respect to that delivery document you could only process one invoice ......
    IF you complete the whole sales cycle ...you can see the whole document flow in va02 by clicking document flow in the left top corner.
    the document flow will be more if their are many partial deliveries.
    <removed_by_moderator>
    Please read the "Rules of Engagement"
    Regards,
    JAGAN N M 
    SAP SD
    Edited by: Juan Reyes on Mar 14, 2011 9:35 AM

  • Reg: function module to fetch the overall taxs for  a sales order

    Hi Experts,
    I need a fuction module which fetches all the taxes for a sales order with the tax values.
    (i.e) i need a function module with displays the overall tax values and not line itemwise..
    Regards,
    Vikram.S

    Hi,
    Check if it works
    POS_SALES_DOCUMENT_HEAD_TAXES

  • Discount calculation for a sales order in CRM

    Hi All,
    I need to change the pricing data for a sales order item using a BAPI. For this I want to make use of the BAPI_BUSPROCESSND_CHANGEMULTI. But I am not sure as to which of the fileds to be used for the discount rate calculation. The scenario is, from a Custom UI we will change the discount given for an item and the same has to be reflected in CRM and the calculation for that also will be carried out in CRM.
    Can somebody throw some light on this?
    Regards,
    - Prasenjit

    Hi Richard,
    There is no pricing procedure in the UI. For every calculation the UI is calling a BAPI and changing the UI accordingly. Everything needs to be done in CRM.
    The requirement is basically to fetch the pricing details for a contract that is under creation. The main funda is to obtain the pricing document guid, which will intern fetch the pricing condtion rates corresponding to a condition type. Can you tell me how to do that?
    Regards

Maybe you are looking for

  • How do I change the preview file location?

    I have a SSD "C:" drive which is filling up, and I have other drives with lots of space and performance, so I'd like to move where SB stores the preview files (currently in  "Adobe Soundbooth Preview Files") to a different drive. I haven't seen anyth

  • Error when emailing XML document

    Hi there I am trying to email an XML document to an external vendor by using the CL_DOCUMENT_BCS class.  The email is sent successfully and I receive it in the relevant mailbox.  To make it an XML document, I move 'XML' to the I_TYPE parameter of the

  • How to set the Valid-to-date (datub) of a BOM item

    Is there a way I can set the "Valid-to-date" of a BOM item? According to SAP documentation... Quote <i>"If you change a BOM using a change number, the system determines the valid-to date dynamically."</i> Unquote I want to "expire" a BOM item. Meanin

  • DB_ACCESS_ERROR in the pipeline Message Branch

    Hi, all. In the IDoc -> XI -> File Scenario, sometimes(twice in this week) DB_ACCESS_ERROR occurs and the corresponding message shows System Error - Manual Restart Possible. The error message in SXMB_MONI shows like the following and the trace shows

  • Contrast adjustment creates color cast - why and how to fix?

    I used a local curves adjustment (with a layer mask) set to "Strong contrast" to make the space shuttle "pop" in a particular shot. I looked it so much I copied that adjustment layer to the rest of the launch sequence. I then realized that as I went