Get quotation from Sales Order?

Hi,
I have the following code and its taking a lot of time on the database. Could you help me fine tune this?
  SELECT k~vbeln      "Sales Document
         p~posnr      "Sales Document Item
         k~vkorg      "Sales Organization
         k~vkbur      "sales office
         k~vtweg      "Distribution Channel
         p~werks      "plant
         p~lgort      "storage location
         k~spart      "Division
         p~matnr      "Material Number
         p~vrkme      "unit of measure
         p~netwr      "net value
         p~waerk      "currency
         p~arktx      "Short Text for Sales Order Item
         p~kwmeng     "Target quantity in sales units
         p~pstyv      "Sales document item category
         a~kunnr      "Sold-to-To Party
         k~auart      "sales type               
         k~audat      "sales order doc. date    
         k~bstdk      "cust. PO date
         k~bstnk      "cust. PO no. (text)      
    INTO CORRESPONDING FIELDS OF TABLE gt_item
*Sales Document: Header Data
    FROM vbak AS k
*Sales Document: Item Data
    INNER JOIN vbap AS p
    ON pvbeln = kvbeln
*Sales Document: Partner
    INNER JOIN vbpa AS a
    ON ( avbeln = kvbeln
     AND a~posnr = '000000'
     AND a~parvw = c_sold_to )
    WHERE k~vbeln IN s_vbeln
      AND k~auart IN s_auart
      AND k~erdat IN s_erdat
      AND k~vkorg IN s_vkorg
      AND k~vtweg IN s_vtweg
      AND k~spart IN s_spart
      AND k~vkbur IN s_vkbur
      AND p~lgort IN s_lgort
      AND a~kunnr IN s_kunnr.
After selecting the sales data I need to check whether there exists any Quotation for the above SO's. I wrote the following code but its taking a hell lot of time bcoz im trying to find out a preceding document from subsequent document.
SELECT VBELV
        POSNV
        VBELN
        POSNN
        VBTYP_N INTO TABLE GT_VBFA_B
                FROM VBFA
                FOR ALL ENTRIES IN GT_ITEM
                WHERE VBELN = GT_ITEM-VBELN
                  AND POSNN = GT_ITEM-POSNR
                  AND VBTYP_V = C_QUOTATION.
Any suggestions would be greatly appreciated.

Hi karthik,
I think why not have th first query as an inner join between vbak and vbap only usin all its primary keys and then use other query to select data from partner tablbe in other internal table and then read it into the final table with your required structure.
This will help in having all required data faster because the vbpa's data will be on application server while you are readeing the sam for the final table and hence it will make the execution.
I think this should work because with more inner joins the underlying database would have to run many queries to get the actual data from database , and everything else seems to be fine as you have used appropriate tables and appropriate keys in the select query , just try this option out.
Thank You!
Regards.
Sunmit.

Similar Messages

  • Price in invoice is not getting copied from Sales order

    Hi,
    In my case when i create a sales order...my VPRS condition is taking price 4.020,24 (@335.02/PC). When i create a Invoice it is coming with 4.020,22 value and .02 is coming in different condition type ZDIF ( Rounding diff) automatically. When i check my PGI accounting document there also price 4.020,22  hits the G/L account.
    Now able to understand why .02 value is going in the ZDIF condition ?
    Need help
    Regards
    Nitin

    Hi Nitin,
    Rounding condition is coming in picture because there will some difference in PR00 and VPRS.
    Generally VPRS is a statistical condition type and it is just used for viewing purpose not a part of calculation.
    So you can go to V/08, select your pricing procedure and then control data.
    In that find out VPRS condition type and click on statistical, then it wont come in calculation.
    If you want that this should be copied then you have to made changes in copy control.
    Go to VTFA if you are making billing document with reference to order document.
    Go to VTFL if you are making billing document with reference to delivery document.
    Select your combination of billing document and delivery document/order document.
    Then go to item level and select you item category and then click on detail
    In that you will find pricing type just change that pricing type to D.
    Now it will copy pricing as it is from sales order.
    Hope so it will solve your problem
    Regards
    Raj.

  • How to get PO from sales order item in CRM

    Hi,
    I am building a BI extractor which needs PO for a given complaint. I am able to get the sales order/item for a complaint using crm_order_read FM. Is there anyway to get the PO based on this SO-item. Are their tables that link these two.
    Thanks!

    Table CRMD_ORDERADM_I -> Give Item GUID in filed GUID and get the document header guid in field HEADER. Then use function module CRM_ORDER_READ and table ET_SALES to get the Sales Data for the right item. The PO you are interested in can be any of the fields related to PO in this set. Usually it is PO_NUMBER_UC.
    Alternately, if you want to use only the table reads use this.
    1. Table CRMD_LINK --> get the record with GUID = Item GUID and OBJTYPE_SET = 11 (for Sales Set)
    2. Table CRMD_SALES --> get the record with GUID = CRMD_LINK-GUID_SET
    Get your PO information from this Sales set record for your item. But since, PO is usually associated with the header, you can do the same as above but with the GUID = Header GUID in the CRMD_LINK table.

  • PR getting duplicated from Sale order

    Dear Experts,
    We have a schedule line category defined for drop shipment Z1 which is having provision of automatic PR creation when sale order is created and saved. I created a sale order with 2 line items and saved and PR too is created automatically upon saving. The problem is that the PR is having 3 lines items where as the sale order is having 2 line items. One line is getting duplicated. Pls tell me what could be possible reason for duplication.
    regards,
    Gopal

    Hi Gopal ,
    It cant be the case ,as the 100% the PR checks the Line items in the sales order.
    so check the quantity in the sales order and the Qunatity in PR.
    and check the item details-- Account assignment details of the PR.
    Whether they belong to the same Sales order and the most important thing ..the same line item..
    check the above you will have some clue..
    Hope so it helps
    Regards
    Anjanna

  • How material transfers from sales order to service order

    Hi All,
    In case of sales order (Debit memo request or quotation) created from service order, material in service order is transferred to sales order via DIP profile.
    but in case of,
    service order created from sales order how the material flows from sales order to service order.
    In customer service module.

    If Service Order gets created from Sales order, operations & components are transferred to Service order through Service Product assignment in Sales Order.
    Service Product will be created in MM01 & this will be linked to Task list in OISD. By assigning this Service Product in Sales Order, Service order will be created automatically with the assigned Task list.

  • Automatic PR Creation from Sales order

    Hi All,
              This is with respect to PR creation from Sales order for 3rd party items.
    I am able to create PR from standard sales order and i dont have any issues with that.  I have used schedule line categories which is configured with Order type Z2, Item rel for dlvy checked and Acct assigment group as E.
    Now my question is , I want to copy partners from sales order to Purchas req. Currently some partners are getting transferred from Sales order to P.Req, But not all there in sales order. Where do we control the data that can be copied from Sales order to P. Req
    Thank you
    Kris

    Hi,
    Genrating PR, Mostely depends on shedule line,see which shedule line u r determining for HIGH LEVEL ITEM ,for that shedule line maintain setting is VOV6.
    kapil

  • PO Text copy from Sales Order to Purchase Order

    Dear friends,
    Hope everyone is doing fine.
    I have the following business requirement for two situations
    Scenario 1) Purchase Order text from the Sales order has to be copied to the purchase order. Here sales order is converted to purchase requisition, and later the requisition is converted to the purchase Order.
    The standard SAP config is working absolutely fine for this.
    Scenario 2) Purchase Order text from the Sales Order has to be copied ot the purchase order. Here sales order is converted into a planned order, planned order is converted into purchase requisition, and later the requisition is converted to the purchase Order. For this situation, the text is not getting copied from Sales order to the requisition/purchase order.
    This is not working as of now with the configuration for the above scenario 1.
    Please throw some light to solve the scenario 2.
    Please let me know if there is a config or do we need to use any user exit or BADI to achieve this.
    Thanks in advance.
    Regards

    Hi Sam Matt ;
    You can benefit from MM:Define copy rules for PR texts .
    I checked , you can copy from sales order , like a belowed screens.
      Regards.
      M.Ozgur Unal

  • To get PO reference number from Quotation to Sales Order

    Hi ,
    As per the Client requirement, I configured the Quotation process with respective to few Distribution Channels in SD.  While creating Sales Order, PO ref.no is not copying from Quotation to Sales Order.
    What necessary changes required to be done in Copy Control - VTAA. Can it possible through standard routines (or) Do i need to Develop a new Routine with BSTKD ?. Pl provide me solution with earliest. Thanks in advance !
    Best Regards,
    SRI

    Hi Senthil Kumar B,
    If the Sales Order is already stored in the DB you should be able to get the internal Row number from the DBDataSource.
    ...when the user is just entering the SO this won't work if I remember correctly. Do you need that too - or what is the functional goal that you want to reach?
    Regards,
    Frank

  • Copy data customer PO and PO date field from quotation to sales order

    Hi Friends,
    Can you please let me know what copy control settings I need to maintain in order to copy customer PO# and PO date field data in quotation to sales order.
    All the data is getting copied from quotation to sales order when I create sales order with reference to quotation but the customer PO no. and PO date is not getting copied.
    Can anyone please help.
    Regards,
    Wasim.

    HI
    Not sure if this is possible via Customization or not but you can try the user-exits or Routines for the Sales Order program for this
    You need to change the include FV45C102 (assuming you have copied standard order and the copy controls). ABAP team should be able to make changes to this routine and achieve your requirement.
    In VTAA, after choosing the Source and Target order type and choosing the right Quatation item, check the routine for 'Bus.data/item compl.' and it will be what has been mentioned above.
    Please check &Revert
    Thanks&Regards
    Raghu.k

  • How to Copy Cost Estimate from Quotation to Sales Order in MTO Scenario

    Hi,
    We are working on a MTO scenario- Sales order Costing with Valuated Stock.
    And our case we are creating the Cost Estimate at the time of Quotation using PP qty structure. Now we wan to transfer the cost estimate to Sales Order as we don't want to recost the sales order.
    Currenty it's transferring only the EK01 condition as total planned costs in Sales order but we want to see the itemization also.
    Please suggest is there any way to transfer this cost estimate with itemization from Quotation to Sales Order.
    Regards
    venkat

    Hi
    As far as I know the CO esimate does not get copied from Quotation to Sales Order
    You need to recost the SO again.. If your Qty Structure has not changed between Quotation to SO and your valuation variant is also the same - it would give the same result
    br, Ajay M

  • GATP run ffecting manual Pricing from Quotation to Sales Order

    Hi SAP Gurus
    We have a bit of problem, when we place a Quotation for a material and APO gATP is run it creates a sub-item for the material and thatu2019s where we add our manual prices(e.g Freight Charges).What than happens is the Quotation is later converted to a Sales Order and gATP is run again( I would think to still see if stock is still available) but all those manual Conditions are lost and our Users have to re-create those manual conditions. I checked in Copy Control(VTAA) to make Pricing type C(Copy manual Elements). Does anyone have an Idea what else can I do to make sure Manual Price is copied even though gATP is run again.
    Thanks
    Phenyo

    Hi Friend,
    To copy the pricing from Quotation to Sales order without change you have to maintain copy control settings from  QT to OR
    Goto the Transaction code VTAA then click on position and choose the Source document as QT and the Target document as OR
    Then click on the item in the control tab and choose ur item category and click on Display
    Now in the Pricing field change the value To D
    Hope it is clear and work.
    regards,
    santosh

  • Copying pricing condition from quotation to sales order

    Hi,
    I would like to know how the following can be achieved.
    In quotation, i have two conditions type.
    For e.g. a item value
    1000 -> PR00
    3%  -> ZMarkup
    Gross Value -> 1003
    In the sales order, we are only having PR00 as the condition type. Thus only 1000 is being copied to sales order.
    How can i achieve such that the gross value in the quotation can be copied into PR00 of sales order?
    Regards

    Hi Friend,
    To copy the pricing from Quotation to Sales order without change you have to maintain copy control settings from  QT to OR
    Goto the Transaction code VTAA then click on position and choose the Source document as QT and the Target document as OR
    Then click on the item in the control tab and choose ur item category and click on Display
    Now in the Pricing field change the value To D
    Hope it is clear and work.
    regards,
    santosh

  • Flow of Information from Quotation to Sales Order

    Hi Group,
    Just want to understand is there any possibility to put a check while information is flowing from Quotation to Sales Order.
    Once information flows to Sales Order no one should be able to change the flown information in Sales Order. Any changes to be done in Sales Order, user should go to Quotation & Change provided Authorization is given.
    How to put this check. Need help & explanation.
    Regards
    Deepak

    Hello Deepak,
    There are normally authorization BADIs for this. But once a sales order is created from a quotation the sales order is not updated if the quotation is updated any more, according to my knowledge. That would also be a strange business process as the quotation would have been already approved by the customer.
    Best regards,
    Thomas Wagner

  • Copy BILLING PLANS from Quotation to Sales Order.

    Hi Guys,
    I am trying to copy the billing plans from quotation to sales order(SO), when CREATED BY REFERENCE from quotation.
    Quotation HEADER LEVEL Billing plans -> SO Header Level Billing plans
    Quotation ITEM LEVEL Billing plans -> SO ITEM LEVEL Billing plans
    I have already tried to use copy control routine 402 by adding a statments to copy internal table CPFLT to XFPLT. It did not work.
    I will appreciate if somebody can tell how to accomplish this task. It is for ECC 6.00
    Thanks,

    Hi Manoj,
    I know its very late to provide the solution. Thought of sharing since I had a similar requirement as yours and got the solution.
    Here is the Solution::::
    1) Let 402 routine stay in the config and do not add any custom code in it.
    2) In TCode: VTAA , in FPLA tab, copy the routine 251 (Conditions) and copy the below mentioned code..thats it...
    FORM DATEN_KOPIEREN_251.
    *{   INSERT         ECDK900223                                        1
    LOOP AT CFPLT.
    MOVE-CORRESPONDING cfplt TO FPLT.
    CLEAR FPLT-FPLNR.
    FPLT-FPLNR = FPLA-FPLNR.
    MOVE-CORRESPONDING FPLT TO XFPLT.
    XFPLT-UPDKZ = 'I'.
    APPEND XFPLT.
    CLEAR XFPLT.
    ENDLOOP.
    UPD_FPLT = 'I'.
    *}   INSERT
    ENDFORM.
    Now you should be able to copy the Billing plan from Quotation into Sales Order.
    Reward if helpful
    Thanks,
    Maqsood.

  • Billing Plan from Quotation to Sales Order

    Hello Friends,
    When Iam creating a Sales Order with reference to a Quotation, I want to copy the Billing Plan automatically from Quotation to Sales Order.
    How can I achieve this??
    Thx,
    Smitha.

    Hi Smitha,
    During sales order processing, the system determines from the item category whether a
    billing plan is required and, if so, which type of plan
    The type of billing plan that is determined at this point is set up in Customizing and
    cannot be changed in the sales document
    REWARD IF U FINDS THIS AS USEFUL...
    Regds
    MM

Maybe you are looking for

  • Custom Markup Extensions

    Hello Community, I'm looking into porting my SL5 code over to Windows Store Application development, and I'm having trouble finding where the IMarkupExtension interface is with the new libraries.  Can someone point this out for me?  A search online h

  • Using list values

    I would like to know if there is a way to do pass a parameter p_Parameter having a value of say A1, A2,A3,....An for a query in PL/SQL stored procedure for a query such as : Select * From Employee where EmpId in (p_Parameter) I was able to resolve th

  • ACH File addenda record for IAT transactions

    Hello Experts, While generatin the DME file for IAT payment method my addenda records are coming as 0000 while they should be either of 7,8 or 9. Not sure the cause of this. In this regard I seek your suggestion whether there are certain configuratio

  • Smartform dump when creating a PO for an output type...

    Hi. When changing a PO and giving the output message type for the smartform, and giving option to print on LOCAL when saving the application , its taking long time to save the PO and producing a dump with a message saying " TYPELOAD_NEW_VERSION" ( DA

  • Help for Seconds to Duration (hh:mm:ss) conversion

    I have this SubVI that is to convert Seconds to Duration (hh:mm:ss). This SubVI works fine for converting Seconds below 54000 (15:00:00) but the subsequent Seconds, for instance (57600 seconds), it returns Duration -8:00:00 instead of 16:00:00. My Su