How to ChangePlantfor each item of Sales order using User Exit SAVE_DOCUMEN

Hi All,
I have to change plant for Each line item of sales order using (MV45AFZZ) (USEREXIT_SAVE_DOCUMENT) based on first Schedule line.
if Confirmed Quantity is Less than Ordered Quantity.
based on first Schedule line.
it has to select other Plant and need to populate it in line item of sales order.Please see the below code and let me knoe if any changes required... Thanks in Advance.
data : wa_vbep like xvbep,
       Lv_matnr type mara-matnr,
       lv_werks type marc-werks.
DATA: it_vbap TYPE STANDARD TABLE OF vbap,
      wa_vbap TYPE vbap.
field-symbols: <wa_vbap> type VBAPVB.
clear wa_vbap.
*loop at xvbap into wa_vbap.
loop at xvbap assigning <wa_vbap>.
read table xvbep into wa_vbep with key posnr = <wa_vbap>-posnr.
if wa_vbep-ETENR = '0001'.
if sy-subrc = 0.
IF wa_VBEP-BMENG LT wa_VBEP-WMENG.
    SELECT SINGLE DWERK
                 INTO lv_werks
                 FROM MVKE WHERE matnr = <wa_VBAP>-matnr
                            and  DWERK ne <wa_VBAP>-werks.
if not Lv_werks is initial.
if lv_werks EQ 1033.
move '1002' to <wa_vbap>-werks.
if sy-subrc eq 0.
  xvbap-werks =  <wa_vbap>-werks.
modify xvbap from <wa_vbap> .
endif.
elseif lv_werks EQ 1003.
move '1003' to <wa_vbap>-werks.
elseif lv_werks EQ 1010.
move '1010' to <wa_vbap>-werks.
endif.
endif.
endif.
endif.
endif.
endloop.
endif.
Regards,
Sudhakar Reddy.A

You have to use the form routine "USEREXIT_SAVE_DOCUMENT_PREPARE"
regards
Vinod

Similar Messages

  • To add line items to sales order using User exit.

    Hi ,
    I have to add line items to sales order .
    I have tried adding the code in usr exit move field _VBAP // Check VBAP and in savedocument _prepare . But in all the places I dont see it in VA01 . I can see it in the VA02 and VA03 . But I am not able to save the order as they have made the flooring term as mandatory field, and I am supposed to populate the XVBKD structure for this.
    Pls tell me whts the procedure like say , should I popluate the XVBKD / XVBAP / and should i use the bapi_SALES_ITEM_CHECK to populate the structures at the save_document prepare.

    Hi,
    1. It is not possible to delete records using DTW, only importing new records or updating existing ones are supported. These are the only valid operations via DTW.
    2. It is possible to delete the contents of an edit text field by using the character / or -1. However it is not possible to clear an entire row/line using this notation.
    Thanks & Regards,
    Nagarajan

  • How to change price in Sales order using user exit ?

    The scenario is -  when the user creates a sales order,  there has to be an RFC called to another system to get the price of the materials in that system. Then it has to overwrite that price in this S.O.
    Which exit in S.O can be used for this and then what processing needs to be done after the RFC call to get price. Like how the price can be overwritten on this S.O ? (Lets say to get price we use some BAPI to the other system).  Any help ?

    Dear Theodorous,
    1)Please check the Material has been extended to the second plant.
    2) Assign the second Plant to Sales Org and Dist Channel
    If you have any concern revert back the same
    Regards
    Amjath

  • How to trigger Availability check in Sales Order 'save' user exit.

    I have requirements which dictate that I change item categories of most of the line items in a user exit. If I do that the line items no longer confirm. I know that the availability check happens in 'move_Field_to_vbap' user exit. Is there any way I can re-trigger it on save. These orders will be coming through a bapi. Thanks in advance.

    Hi!
    Search the way (via menu) in VA01 to trigger the availability check manually. Then have a look, with routines are called.
    Then call this (these) routines in the exit. If you see something like 'perform okcode_...', then this should work. Be careful not to trigger recursive loops by this way. Maybe  the prepare_save-exit is a better place to do this.
    Regards,
    Christian

  • How to create Billing Plan in sales order using Function module /BAPI

    hi,
    How to create Billing Plan in sales order using Function module /BAPI
    i hv check few FM such
    BILLING_SCHEDULE_READ
    BILLING_SCHEDULE_GET_NUMBER
    BILLING_SCHEDULE_SAVE
    But unable to create billing plan for a sales order.....any other method to create???

    Hi,
    Use this link.
    Create sales order with billing plan via LSMW and BAPI BUS2032
    BAPI or Function to update Billing Plan in Sales Order Items
    Hope this will help you.
    Regards,
    Vijay

  • Sales Order Pricing User Exit Problem

    Hi,
    I am facing a problem related to coding in Sales Order pricing user exits. Scenario is as mentioned below:
    Based on Material Entered and Sold To in Sales Order, auto determination of a manual pricing condition happens. For doing this, coding has been done in USEREXIT_PRICING_PREPARE_TKOMP by changing XKOMV table. Auto determination of the manual price is happening properly.
    From Sales Overview Screen when user goes to the Conditions tab, Net Value is not getting calculated. When we navigate away to Schedule line tab and then come back to COnditions tab, Net Value is automatically getting calculated.
    AM i missing something in the coding part? As the data is getting populated automatically I guess some piece of code needs to be triggered. Can anyone shed some light into this.
    Thanks in advance,
    thunderans.

    Prabhu: After filling in XKOMV structure, I am calling FM PRICING. On doing this, the Sales Pricing is getting calculated but even then net value of order at header i.e VBAK-NETWR is not getting populated when we are in Sales Overview screen. When, I am getting into Conditions tab and coming back to Sales Overview screen, Net value is getting populated correctly. This portion of everything not getting populated at the same time is bothering me. The pricing conditon that I am  filling is a manual pricing condition.
    I put a breakpoint after FM PRICING which correctly populates XKOMV structure. How do I properly update Order Net Value in Sales Overview screen wihtout having to navigate to any other tab?
    Nicklas: I am looping at Order line within the user exit USEREXIT_PRICING_PREPARE_TKOMP and determining price. Once all line items are processed, I am using the FM PRICING for calculating Sales Prices.
    J@Y: Request to send me a bit more details into your approach.

  • How to create service items and sales order for service contracts.

    Hi,
    I have created item using Purchased Item template and one more item(service item) using service /warranty program template. Then I have used these items to create sales order with service item in it and closed that order , but Iam not getting this order in service contracts. Is this right way to create sales order for service items. I
    item name:- personal_computer
    copied from purchased order template. service is enabled and install base is checked and enable service coverage is enabled.
    item name:- service_item
    copied from service /warranty program template
    service is selected to inactive,
    service type: service
    duration: 1 year
    template: Gold
    and saved the item.
    Then I have used these two items in sales order for service contracts. But that sales order is not hitting in service contracts. Is there any error with item creation.
    Thanks,
    Bharat G.

    Following SAP Notes to be referred for Service Tax:
    1.     778976 u2013 Service Tax and Ecess on Service Tax
    2.     1032265 - SEcess on Service Tax
    Regards
    AK

  • How to add line item to sales order item table?

    Kindly help me the with the below requirement .
    Add line item to sales order(va01) dynamically on click of button. The button is also custom created push button.
    In the above requirement I have added the pushbutton to va01 tcode. But when I click on that button I need to add line item to sales order item table.
    I tried a lot but I am not successful. If possible can u please help on this.
    Regards,
    Rachel

    Hi!
    It's quite easy even in the standard SAP to add a line item for a customer order, I don't think it worth to develop a new button for this.
    However if you wanted to add a line automatically, the you can do the following in the program MV45AFZZ, FORM USEREXIT_SAVE_DOCUMENT.
    You can use similar code, but with some modifications.
    DATA: lv_posnr.
    LOOP AT xvbap.
    MOVE xvbap-posnr TO lv_posnr.   "get the last posnr
    ENDLOOP.
    ADD 10 TO lv_posnr.
    MOVE 'XYZ' TO xvbap-matnr.   "enter your material number here
    MOVE lv_posnr TO xvbap-posnr.
    * fill additinal field data in XVBAP if necessary
    MOVE 'I' TO xvbap-updkz.                  "Insert line
    APPEND xvbap.
    Regards
    Tamá

  • Creating line item for a sales order in user exit

    Hi
    I have to create a line item through user exit "userexit_save_document_prepare" when saving the sales order.I am doing this by appending a row to the internal table XVBAP in the user exit.
    The row is getting appended to the internal table but the line item is not getting created in the sales order .I dont getting any error also.
    Can anyone tell me what could be the reason for this and is there any other means by which i can create a line item through the user exit.

    You have to set the creation flag UPDKZ to 'I'.
    to correctly use the user exit refer to OSS note 0381348 Using user exit, customer exit, VOFM in SD.
    pls reward if helpful
    Roberto

  • How to Create RMA Based on Sales order using OE_ORDER_PUB api

    Hi,
    Can any one pls help me how to create a RMA based on the sales order using oe_order_pub.process_order APi.
    Thanks.

    Creating RMA is very similar to creating an Order. You need to make sure you're passing the correct order_type, line_type which'll be setup as 'RETURN' (or 'MIXED') category in transaction type definition.
    For the API to automatically create a reference on your RMA lines to the original Order lines, you need to pass the following
    l_line_tbl (l_line_tbl.COUNT).return_reason_code := 'RETURN'; -- Mandatory for RMA
    l_line_tbl (l_line_tbl.COUNT).reference_line_id := v_ref_line_id; -- Original order line_id
    l_line_tbl (l_line_tbl.COUNT).reference_header_id := v_ref_header_id; -- Original order header_id
    l_line_tbl (l_line_tbl.COUNT).return_context := 'ORDER';
    l_line_tbl (l_line_tbl.COUNT).return_attribute1 := v_ref_header_id; -- Original order header_id
    l_line_tbl (l_line_tbl.COUNT).return_attribute2 := v_ref_line_id; -- Original order line_id
    Once the RMA gets created, query the order and navigate to Lines>Returns tab. You can see the original order number and line number.
    Thanks
    Gopal

  • Sales order number user exit in Purchase order

    hi,
        There is a sales order number in Purchase order(item level/account assignment/sales order no)
      Now, i have to populate the SO no in  orders 05.
       Can any one say the user exit for populating the sales order number in PO.

    Hi
    Check the below exits related to purchasing in which the table EKKN is referenced
    EKKN will have VBELN (sales order No) and POSNR (item of sales order)
    M06B0001
    Role determination for release of requisitions
    M06B0001
    Changes to communication structure for release of requisitions
    M06B0003
    Number range and document number
    M06B0004
    Number range and document number
    M06B0005
    Changes to communication structure for overall release of purchase requisitions
    M06E0004
    Changes to communication structure for release of purchasing document
    M06E0005
    Role determination for release of purchasing documents
    ME590001
    Grouping of requisitions for PO split in transaction ME59
    MEETA001
    Determination of schedule line type (backlog, immediate requirement, forecast)
    MEFLD004
    Determination of earliest delivery date for checking at time of goods receipt (PO only)
    MELAB001
    Generation of forecast delivery schedule: realization via creation profile
    MEQUERY1
    Enhancement for document overview ME21N / ME51N
    MEVME001
    Calculation of default GR quantity and over/underdelivery tolerances
    MM06E001
    User exits for inbound EDI messages and outbound purchasing documents
    MM06E003
    Number range and document number
    MM06E004
    Control of import data screens in purchase orders
    MM06E005
    Customer fields in purchasing documents
    MEREQ001
    Customer's own data in purchase requisitions
    MM06E007
    Change document for requisitions when converting into POs
    MM06E008
    Monitoring of contract target value in case of release orders
    MM06E009
    Relevant texts for "Texts exist" indicator
    MM06E010
    Field selection for vendor address
    MM06E011
    Activation of requisition block
    MM06L001
    Exits for determination of ratings in vendor evaluation
    MMAL0001
    ALE source list distribution: outbound processing
    MMAL0002
    ALE source list distribution: inbound processing
    MMAL0003
    ALE purchasing info record distribution: outbound processing
    MMAL0004
    ALE purchasing info record distribution: inbound processing
    MMDA0001
    Default values for delivery addresses
    MMFAB001
    User exit for generation of releases
    MRFLB001
    Control items during release creation
    LWBON001
    Enhancement of LIS update through extension of the communication structure MCKONA (business volumes and rebate income)
    LWBON003
    Change settlement data for end-of-period rebate settlement before creation of settlement documents
    LWSUS001
    Customer-specific source determination in Retail
    LMEXF001
    Conditions in purchasing documents without invoice receipt
    LMEKO002
    Enhance communication structure KOMP for price determination
    <b>Reward points for useful Answers</b>
    Regards
    Anji

  • How to disable line items of sales order ie not editable

    Hi All,
      I want to diable line items of BOM when using it in sales order, Can any one tell me how to do it and which USER EXIT or BADI i have to use it for.
    Regards,
    Sudhakar.A

    Hi,
    You have to write your code in this Include : MV45AFZZ
    Here i have diabled the components of BOM...change the code accordingly.
    IF ( sy-tcode EQ 'VA01'
             OR sy-tcode EQ 'VA02' ).
        loop at xvbap where pstyv eq 'ZABC'.
          if not vbap-uepos is initial.
            if sy-subrc = 0.
              screen-input = 0.
            endif.
         endif.
        endloop.
      endif.
    Here Xvbap is like Internal table
    VBAP is strucure.
    Regards,
    Sudhakar Reddy.A

  • How to upload multiple items of sales order?

    I have extracted open sales order and transferred it to an excel file.
    Some SO doument has multiple items on one SO.
    If I will upload that SO document (with multiple items) into a new server, how am I suppose to itemize that this document has multiple items?
    I hope my explanation is clear.

    Hi,
    Suppose you are uploading through LSMW
    Then when you recording in t-code VA01 that time you have to enter MULTIPLE ITEMS, so record will capture multiple items then same you maintain in excel and upload.
    Kapil

  • How to find open item from sales order

    Hi all,
      my requirement is one sales order is there partial delivery is happened for some materials,take exampla matarial X has 100 quantity in sales order pratial delivery 50 is done, iwant to know the open order qunatity for a  material X from sales order.
    regards,
    kishore.

    hi kishore,
    in the partial delivery scenario, the sales order items always be a open.
    you can see the document flow of that document by using Tcode : VA03 then click on'update document flow' icon. then system will show the status.
    i.e  sales order is 'being processed'
      outbound delivery is completed
    billing document is completed
    and accounting document in not cleared.
    if it is helpful, then give me the points.
    Regards,
    somu.

  • Deletion of line items from Sales Order using DTW

    Hi Experts
    I have 160 sales which all require a particular item needs to be
    deleted before they can be processed further.  It is ths same item on every order but
    doesn't appear at the same row number.  In some cases it may appear more than once
    on an order.
    The line item needs to be deleted based on the row numbers which could be different on every order (LineNum)
    Rather than have admin go through them 1 by 1 and delete the
    row is it possible I can use DTW to perform an update on each row to delete it?
    I'm not sure how to do this since I have only ever used DTW
    to add or edit.
    Thanks
    Geoff

    Hi,
    1. It is not possible to delete records using DTW, only importing new records or updating existing ones are supported. These are the only valid operations via DTW.
    2. It is possible to delete the contents of an edit text field by using the character / or -1. However it is not possible to clear an entire row/line using this notation.
    Thanks & Regards,
    Nagarajan

Maybe you are looking for