Problem in lock Sales order create with BAPI BAPI_SALESORDER_CREATEFROMDAT2

Hi All,
i have the z program to create the sales order with reff  quotation in SD With BAPI BAPI_SALESORDER_CREATEFROMDAT2.
this program will  excute every 30 mins .
Problem: Some times if i excute the program in background it is taking morethan 30mins so second batch excution also gets starting to create the sales order for same quotation then it is creating 2 sales orders at atime with 1 quotation.
here i am getting duplicate sales orders so i want to lock the creation of duplicate sales order.

Some solutions
- Just lock (ENQUEUE) any object at the start of the job(*), if not locked, you can exit or wait in a loop, will be released at end of job (use a _SCOPE '3' so commit work wont release the lock)
-> This will insure the job runs only once at a time
- Lock the quotation before calling the BAPI, will be released by the COMMIT_WORK (from where do you fetch the quotation, if it is a customer Z_table, you can use the lock object that you have surely created ?) (use a _scope '2')
-> This will insure that at most one job will convert a quotation (i suppose you set a "done" flag or status  in the quotation record)
Read [SAP Locks |http://help.sap.com/abapdocu_70/en/ABENSAP_LOCK.htm] if you are not familiar with the concept of lock in SAP.
Regards,
Raymond
(*) E_TABLEE for table, E_TRDIR for program, anything not required by another process

Similar Messages

  • Change of Sold to Party in Sales order created with Reference to Contract

    Dear Gurus
    I want to change the sold to party in Sales Order created with reference to contract.
    When I create a Sales order with reference to contract the system copies all the partner functions- Sold to, Ship to, Bill to and Payer alongwith other data.
    However Sold to is marked as "Grey" and not changable, rest of the partners can be changed.
    There is no subsiquent document created with reference to this Sales Order.
    Please advice.
    Thanks a lot.
    Regards
    Raghu

    Hi ,
    Please follow the below mentioned step.
    1) Create a partner function letts say Authorized SP .
    2) Assign all the possible authorised  SP (customer) in the contract.
    3) When you create sales order with reff to Contract. Put the customer for whom you wish to create a sales order in release partner tab.
    Hop this will resolve our problem
    Regards,
    Krishna O

  • Sales Order Created with reference to Contract - Exchange rate Issue

    When Sales Order created with reference to contract VBKD fields KURSK and KURSK_DAT gets copied from contract and not redetrmined based on pricing date and Exchange rate type. I expected it to be determined based on pricing date is standard. What I am missing, should it be controlled by data transfers
    If Document currency and condition currency are different it cause problems with incorrect condition values are calculated, as KOMP-KURSK are copied from VBKD-KURSK
    Any help or directions would be greatly appreciated . We are on 4.7 ISOIL
    Sincerely Julietta

    Well,
    and if we have the same issue, but we don't have OIL Version, but simple 4.6C, which solution has to be applied then?
    Thank you
    Standa

  • Error  : Sales order 'create with Reference' to the contract

    We have made a value contract. Now we are trying to make a Sales order 'create with Reference' to the contract.
    when we do that, we am getting error 'copying material in any value contract item is not permitted'
    Any help or directions would be greatly appreciated . We are on Ecc 6.0
    Rohit

    As of now my value contract has just one material. so i dont need assortment module settings. right?
    in VTAA settings are as follows
    Target type: OR  
    Source type: ZK1
    there is only on item category
    Target item category: TAN   
    Source item category: WKN
    Copying requirement : 301
    update doc flow : 2
    pricing type : C
    cont item copy mode : A
    DataT am using 151,102,002
    There are no schedule line.
    Rohit
    Edited by: rohit kumar on May 15, 2008 7:36 PM

  • Throw Information message for sale order created with value less that 5$

    Hi all,
            I am basically an abaper, I have got a requirement in SD. The requirement is any sales order created with value less that 5$, should be prompted with an error message saying the minimum order value should be more than 5$. Could any one help me on this.
    Thanks in advance,
    shiv

    userexit_save_document_prepare,main program - sapmv45a, issue an error message if your document value is less than 5$ (VBAK-NETWR) but check if your order has any non-rejected item, I would not issue this message if all items are rejected:
    loop at xvbap where updkz ne 'D' and abgru = ' '.
      exit.
    endloop.
    if sy-subrc = 0.  "-you have at least one non-rejected, non-deleted item.
    NOTE: sapmv45a works NOT only for orders, so please check document types in your logic which are relevant to your messge only (VBAK-VBTYP and/or VBAK-AUART).

  • BAPI Sales order create with reference

    Hi
    I need to use BAPI to create sales order with reference to Quantity Contract. The line item material quantity would be less than or equal to quantity contract quantity.
    Sales order needs to be created with new quantity.
    Quantity contract quantity change needs to be maintained.
    Document flow needs to be maintained.
    Is any one aware if this is possible using BAPI_SALESORDER_CREATEFROMDAT2. If yes, how?
    Any insights would be highly appreciated.

    Hi Maninder,
    The BAPI does not allow the Pricing Conditions to be sourced from the Contract. I debugged the BAPI and it uses a piece of code (don't recall which subroutine though) from SAPMV45A which is relevant for dialog processing where it reads from the VBAP and *VBAP structures. Well this structure is only populated when you are using the Front End transaction (VA41, VA42, etc). Because this structure is empty, pricing conditions do not flow across.
    Here is a little prototype program I whipped up to test my method of creating a Sales order and then changing the Sales Order:
    REPORT  ypat_salesorder_create LINE-SIZE 256.
    * This program will create a ZOC Sales Order with Reference to Contract
    * 20000720 / 10. This will be done via BAPI. There are 2 BAPi calls,
    * BAPI_SALESORDER_CREATEFROMDAT2 and BAPI_SALESORDER_CHANGE. We need to
    * perform 2 BAPI calls as the BAPI to create the Sales Order does not
    * bring across the Pricing Conditions properly. To get around this we
    * create the Order with reference to the Contract, then we get the
    * related Pricing Conditions from the COntract and then update the newly
    * created Order.
    * Constants
    CONSTANTS: c_contract  LIKE vbak-vbeln VALUE '0020000720',
               c_item      LIKE vbap-posnr VALUE '000010'.
    * Structures
    * Structure to hold BAPI Header
    DATA: st_bapisdhd1   LIKE bapisdhd1.
    * Internal Tables
    * Sales Order Create BAPI Return Messages
    DATA: tbl_return     TYPE STANDARD TABLE OF bapiret2
                         WITH HEADER LINE.
    * Sales Order BAPI Line Item
    DATA: tbl_bapisditm  TYPE STANDARD TABLE OF bapisditm
                         WITH HEADER LINE.
    * Sales Order BAPI Line Item
    DATA: tbl_bapisditmx  TYPE STANDARD TABLE OF bapisditmx
                         WITH HEADER LINE.
    * Sales Order BAPI Pricing Conditions
    DATA: tbl_bapicond   TYPE STANDARD TABLE OF bapicond
                         WITH HEADER LINE.
    * Sales Order BAPI Partner Functions
    DATA: tbl_bapiparnr  TYPE STANDARD TABLE OF bapiparnr
                         WITH HEADER LINE.
    * Sales Order BAPI Schedule Lines
    DATA: tbl_bapischdl  TYPE STANDARD TABLE OF bapischdl
                         WITH HEADER LINE.
    * Sales Order BAPI Schedule Lines
    DATA: tbl_bapischdlx TYPE STANDARD TABLE OF bapischdlx
                         WITH HEADER LINE.
    * Sales Order BAPI Pricing Conditions
    DATA: tbl_bapicondx    TYPE STANDARD TABLE OF bapicondx
                           WITH HEADER LINE.
    * Customer Enhancement for VBAK, VBAP, VBEP
    DATA: tbl_bapiparex    TYPE STANDARD TABLE OF bapiparex
                           WITH HEADER LINE.
    * Table to hold BAPI Detail Conditions
    DATA: tbl_bapisdcond   TYPE STANDARD TABLE OF bapisdcond
                           WITH HEADER LINE.
    * Table to hold Return Messages from Sales Order Change BAPI
    DATA: tbl_return_chg  TYPE STANDARD TABLE OF bapiret2
                          WITH HEADER LINE.
    * Variables
    DATA: g_vbeln_created   LIKE vbak-vbeln,
          g_valid_contract  TYPE c,
          g_cont_price_date TYPE d.
    * Start of Selection
    START-OF-SELECTION.
      PERFORM validate_contract.
      PERFORM create_sales_ord.
      PERFORM update_sales_ord.
    * End of Selection
    END-OF-SELECTION.
      PERFORM write_output_report.
    * Subroutines
    *&      Form  create_sales_ord
    *       Create the Sales Order
    FORM create_sales_ord .
      PERFORM populate_bapi_tables.
      PERFORM call_create_sales_ord_bapi.
    ENDFORM.                    " create_sales_ord
    *&      Form  populate_bapi_tables
    *       Fill up the BAPI Tables
    FORM populate_bapi_tables .
      PERFORM populate_bapi_header.
      PERFORM build_bapi_partners.
      PERFORM build_bapi_items.
      PERFORM build_bapi_sched_lines.
    ENDFORM.                    " populate_bapi_tables
    *&      Form  populate_bapi_header
    *       Build BAPI Header Details
    FORM populate_bapi_header .
      CLEAR st_bapisdhd1.
      st_bapisdhd1-doc_type     = 'ZOC'.         "Order type
      st_bapisdhd1-sales_org    = '026'.         "Sales Org
      st_bapisdhd1-distr_chan   = '00'.          "Dist Channel
      st_bapisdhd1-division     = '00'.          "Division
      st_bapisdhd1-purch_no_c   = 'Cust Po No'.  "Cust PO No
      st_bapisdhd1-name         = 'Orderer'.     "Name of Orderer
      st_bapisdhd1-ord_reason   = ''.            "Order Reason
      st_bapisdhd1-sales_off    = '3001'.        "Sales Office
      st_bapisdhd1-sales_grp    = '301'.         "Market Area
      IF g_valid_contract = 'X'.
        st_bapisdhd1-price_date = g_cont_price_date.
      ENDIF.
    ENDFORM.                    " populate_bapi_header
    *&      Form  build_bapi_partners
    *       Build BAPI Partner Functions
    FORM build_bapi_partners .
      CLEAR tbl_bapiparnr.
      tbl_bapiparnr-partn_role   = 'AG'.
      tbl_bapiparnr-partn_numb   = '0000100750'.
      APPEND tbl_bapiparnr.
      CLEAR tbl_bapiparnr.
      tbl_bapiparnr-partn_role   = 'WE'.
      tbl_bapiparnr-partn_numb   = '0000504472'.
      APPEND tbl_bapiparnr.
    ENDFORM.                    " build_bapi_partners
    *&      Form  build_bapi_items
    *       Build The BAPI Line Items
    FORM build_bapi_items .
      DATA: l_matnr LIKE mara-matnr.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = '10000072'
        IMPORTING
          output = l_matnr.
      CLEAR tbl_bapisditm.
      tbl_bapisditm-itm_number  = c_item.
      IF g_valid_contract = 'X'.
        tbl_bapisditm-ref_doc     = c_contract.
        tbl_bapisditm-ref_doc_it  = c_item.
        tbl_bapisditm-ref_doc_ca  = 'G'.       "Contract
      ENDIF.
      tbl_bapisditm-material    = l_matnr.
      tbl_bapisditm-plant       = '3012'.
      tbl_bapisditm-target_qty  = '5.000'.
      tbl_bapisditm-target_qu   = 'M3'.
      tbl_bapisditm-item_categ  = 'ZZOC'.
      tbl_bapisditm-sales_dist  = '301'.
      tbl_bapisditm-dlv_prio    = '02'.
      tbl_bapisditm-prc_group5  = '080'.
      tbl_bapisditm-cust_mat35  = 'kdmat'.
      tbl_bapisditm-route       = 'TESYS'.
      tbl_bapisditm-usage_ind   = 'CIV'.
      APPEND tbl_bapisditm.
      CLEAR tbl_bapisditmx.
      tbl_bapisditmx-itm_number = c_item.
      tbl_bapisditmx-ref_doc    = 'X'.
      tbl_bapisditmx-ref_doc_it = 'X'.
      tbl_bapisditmx-ref_doc_ca = 'X'.
      tbl_bapisditmx-material   = 'X'.
      tbl_bapisditmx-updateflag = 'I'.
      tbl_bapisditmx-plant      = 'X'.
      tbl_bapisditmx-target_qty = 'X'.
      tbl_bapisditmx-target_qu  = 'X'.
      tbl_bapisditmx-item_categ = 'X'.
      tbl_bapisditmx-sales_dist = 'X'.
      tbl_bapisditmx-dlv_prio   = 'X'.
      tbl_bapisditmx-prc_group5 = 'X'.
      tbl_bapisditmx-cust_mat35 = 'X'.
      tbl_bapisditmx-usage_ind  = 'X'.
      tbl_bapisditmx-route      = 'X'.
      APPEND tbl_bapisditmx.
    ENDFORM.                    " build_bapi_items
    *&      Form  build_bapi_sched_lines
    *       Build the BAPI Schedule Lines
    FORM build_bapi_sched_lines .
      CLEAR tbl_bapischdl.
      tbl_bapischdl-itm_number  = c_item.
      tbl_bapischdl-req_qty     = '1'.
      tbl_bapischdl-req_date    = sy-datum.
      APPEND tbl_bapischdl.
    ENDFORM.                    " build_bapi_sched_lines
    *&      Form  build_bapi_conditions
    *       Pull the BAPI Pricing Conditions from the Contract
    FORM build_bapi_conditions .
      LOOP AT tbl_bapisdcond.
        CLEAR tbl_bapicond.
        MOVE-CORRESPONDING tbl_bapisdcond TO tbl_bapicond.
        APPEND tbl_bapicond.
        CLEAR tbl_bapicondx.
        tbl_bapicondx-itm_number = tbl_bapicond-itm_number.
        tbl_bapicondx-cond_st_no = tbl_bapicond-cond_st_no.
        tbl_bapicondx-cond_count = tbl_bapicond-cond_count.
        tbl_bapicondx-cond_type  = tbl_bapicond-cond_type.
        tbl_bapicondx-updateflag = 'I'.
        tbl_bapicondx-cond_value = 'X'.
        tbl_bapicondx-currency   = 'X'.
        tbl_bapicondx-cond_unit  = 'X'.
        tbl_bapicondx-cond_p_unt = 'X'.
        tbl_bapicondx-varcond    = tbl_bapicond-varcond.
        APPEND tbl_bapicondx.
      ENDLOOP.
    ENDFORM.                    " build_bapi_conditions
    *&      Form  call_create_sales_ord_bapi
    *       Call the Sales Order Create BAPI
    FORM call_create_sales_ord_bapi .
      CLEAR g_vbeln_created.
      CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
        EXPORTING
          order_header_in    = st_bapisdhd1
        IMPORTING
          salesdocument      = g_vbeln_created
        TABLES
          return             = tbl_return
          order_items_in     = tbl_bapisditm
          order_items_inx    = tbl_bapisditmx
          order_partners     = tbl_bapiparnr
          order_schedules_in = tbl_bapischdl.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ENDFORM.                    " call_create_sales_ord_bapi
    *&      Form  update_sales_ord
    *       Update the newly created Sales Order with the Pricing Conditions
    *       from the Contract
    FORM update_sales_ord .
      CHECK g_valid_contract EQ 'X'.
      PERFORM get_contract_details.
      PERFORM build_bapi_conditions.
      PERFORM call_change_sales_ord_bapi.
    ENDFORM.                    " update_sales_ord
    *&      Form  get_contract_details
    *       Get Contract Details
    FORM get_contract_details .
    * Need to manually get the relevant Pricing Conditions as the BAPI
    * BAPISDORDER_GETDETAILEDLIST causes problems when we call the BAPI
    * BAPI_SALESORDER_CREATEFROMDAT2 and BAPI_SALESORDER_CHANGE (I think
    * this is due to the fact that these BAPIs belong to the same Function
    * Group and there must be some common structures that are not cleared
    * causing us all sorts of grief when we try and call the next BAPI)
      DATA: tbl_konv TYPE STANDARD TABLE OF konv WITH HEADER LINE.
      DATA: tbl_komv TYPE STANDARD TABLE OF komv WITH HEADER LINE.
      DATA: tbl_vbak TYPE STANDARD TABLE OF vbak WITH HEADER LINE.
    * Pricing Condition Master
      DATA: BEGIN OF tbl_t685a OCCURS 0,
              kschl     LIKE t685a-kschl,
              kaend_wrt LIKE t685a-kaend_wrt,
            END OF tbl_t685a.
      SELECT *
             INTO TABLE tbl_vbak
             FROM vbak
             WHERE vbeln = c_contract.
      READ TABLE tbl_vbak INDEX 1.
      SELECT *
             INTO TABLE tbl_konv
             FROM konv
             WHERE knumv = tbl_vbak-knumv AND
                   kposn = c_item.
      CHECK sy-subrc EQ 0.
    * We now need to make sure we only bring across the Condition Types that
    * are EDITABLE. If we bring across non editable conditions (such as
    * 'ZPR1') the Change Sales Order BAPI will fail
      SELECT kschl kaend_wrt
             INTO TABLE tbl_t685a
             FROM t685a
             FOR ALL ENTRIES IN tbl_konv
             WHERE kappl     EQ 'V'             AND  "Sales
                   kschl     EQ tbl_konv-kschl  AND
                   kaend_wrt EQ 'X'             AND  "Value is Editable
                   kmanu     NE 'D'.                 "Process manually
    * Prepare for Binary Search
      SORT tbl_t685a BY kschl.
      LOOP AT tbl_konv.
        READ TABLE tbl_t685a WITH KEY kschl = tbl_konv-kschl BINARY SEARCH.
        IF sy-subrc EQ 0.
          MOVE-CORRESPONDING tbl_konv TO tbl_komv.
          APPEND tbl_komv.
        ENDIF.
      ENDLOOP.
      CHECK NOT tbl_komv[] IS INITIAL.
    * Map KOMV into the more BAPI friendly BAPISDCOND structure
      CALL FUNCTION 'MAP_INT_TO_EXT_STRUCTURE'
        TABLES
          fxvbak        = tbl_vbak
          fxkomv        = tbl_komv
          fxbapikomv    = tbl_bapisdcond
        EXCEPTIONS
          entry_missing = 1
          OTHERS        = 2.
    ENDFORM.                    " get_contract_details
    *&      Form  call_change_sales_ord_bapi
    *       Call the Change Sales Order BAPI
    FORM call_change_sales_ord_bapi .
      DATA: st_head_chg      LIKE bapisdh1x,
            st_logic_switch  TYPE bapisdls.
      CHECK NOT g_vbeln_created IS INITIAL.
      CHECK g_valid_contract EQ 'X'.
      st_head_chg-updateflag     = 'U'.
      st_logic_switch-cond_handl = 'X'.
      CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
        EXPORTING
          salesdocument    = g_vbeln_created
          order_header_inx = st_head_chg
          logic_switch     = st_logic_switch
        TABLES
          return           = tbl_return_chg
          conditions_in    = tbl_bapicond
          conditions_inx   = tbl_bapicondx.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ENDFORM.                    " call_change_sales_ord_bapi
    *&      Form  write_output_report
    *       Produce Output Report
    FORM write_output_report .
      IF NOT g_vbeln_created IS INITIAL.
        WRITE:/ 'Success! Sales Order', g_vbeln_created, 'was created!'.
      ELSE.
        WRITE:/ 'Failure! Sales Order was not created!'.
      ENDIF.
      SKIP.
      WRITE:/ 'Sales Order Create Log'.
      LOOP AT tbl_return.
        WRITE:/ tbl_return-type, tbl_return-id, tbl_return-number,
                tbl_return-message.
      ENDLOOP.
      SKIP.
      WRITE:/ 'Sales Order Change Log'.
      LOOP AT tbl_return_chg.
        WRITE:/ tbl_return_chg-type, tbl_return_chg-id,
                tbl_return_chg-number, tbl_return_chg-message.
      ENDLOOP.
    ENDFORM.                    " write_output_report
    *&      Form  validate_contract
    *       Make sure that the Contract is Valid
    FORM validate_contract .
      DATA: l_gueen  LIKE vbak-gueen,
            l_prsdt  LIKE vbkd-prsdt.
      SELECT SINGLE  vbak~gueen vbkd~prsdt
             INTO (l_gueen, l_prsdt)
             FROM vbak
             INNER JOIN vbkd
             ON vbak~vbeln = vbkd~vbeln
             WHERE vbak~vbeln = c_contract AND
                   vbkd~posnr = '000000'.
      IF sy-datum LE l_gueen.
    * Contract is valid! Set Order Price Date
        g_valid_contract  = 'X'.
        g_cont_price_date = l_prsdt.
      ENDIF.
    ENDFORM.                    " validate_contract
    Hope this helps.
    Cheers,
    Pat.

  • Sales Order CReated with Reference

    Hi,
    I created a sales order with reference to an existing order. I created delivery based on the new order that was created with reference. HOwever, if i try to get the sales order number of my delivery, the sales order that i am getting is the sales order number that was referenced. How will I retreived the new sales order number from VBFA?
    Thanks,
    Louisse

    Hello,
             We can follow the below Procedure to get the Sales Order Number from VBFA Table.
    1. Input the Delivery in VBELN field to get VBELV (Sales Order)
        Number with VBTYP_V = 'C' (Order). 
    2. Now, if the Sales Order which is fetched is the one which is
        referenced, then Input the Sales Order Number again in the
        VBFA Table into the Field VBELV and fetch the Sales Order
        Number (New) in the VBELN Field with VBTYP_N = 'C'.
    3. You should be able to satisfy your requirement.
    Hope it was clear.
    Thanks and Regards,
    Venkat Phani Prasad Konduri

  • Problem in Sales order create using BAPI with reference to quotation

    Hi,
    I am creating a sales order from Quotation using BAPI /AFS/BAPI_SALESORD_CREATEFDATA.
    The Sale order is getting created and the document flow is updated. When i check the status of quotation it is "OPEN".
    Ideally when a sale order is created in VA01 with reference to a quotation and if all items are added in the order from quotation, then the status of the quotation must be "Complete".
    When i use the BAPI, the status of the quotation is sill "Open". Has anyone faced this issue?
    Even if anyone has faced this issue with BAPI_SALESORDER_CREATEFROMDAT2, please let me know...
    Regards

    Hi RV,
    I am using BAPI  to create order reference to contracts. I am facing same issue. Its not updating document flow (vbfa-plmin field). After creating orders I am forcing to update plmin field in vbfa. This worked fine. But now status in reference document not updating properly. I saw your thread. It looks like similar issue. I saw your comments "Customization was not maintained properly for the Order types ". Please can you explain little bit more about your solution. It will helps us lot.
    Thanks,
    srini

  • Create Sales Order / Delivery with BAPI

    Hi,
    I want to create a sales order and the its delivery using BAPI. Is there such BAPI or should i use two different BAPI functions.
    I also need to post goods issue after the completition of the delivery. Which BAPI is the most appropriate for my pupose?
    thanks for your help,
    - ferudun

    Hi,
    Check this example of creating a sales order and for creating delivery...and PGI
    ************SALES ORDER INPUT CREATION.
    PARAMETERS: p_auart TYPE auart OBLIGATORY.
    PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.
    PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.
    PARAMETERS: p_spart TYPE vtweg OBLIGATORY.
    PARAMETERS: p_sold TYPE kunnr OBLIGATORY.
    PARAMETERS: p_ship TYPE kunnr OBLIGATORY.
    *ITEM
    PARAMETERS: p_matnr TYPE matnr OBLIGATORY.
    PARAMETERS: p_menge TYPE kwmeng OBLIGATORY.
    PARAMETERS: p_plant TYPE werks_d OBLIGATORY.
    PARAMETERS: p_itcat TYPE pstyv   OBLIGATORY.
    DATA DECLARATIONS.
    DATA: v_vbeln LIKE vbak-vbeln.
    DATA: header LIKE bapisdhead1.
    DATA: headerx LIKE bapisdhead1x.
    DATA: item    LIKE bapisditem OCCURS 0 WITH HEADER LINE.
    DATA: itemx   LIKE bapisditemx OCCURS 0 WITH HEADER LINE.
    DATA: partner LIKE bapipartnr  OCCURS 0 WITH HEADER LINE.
    DATA: return  LIKE bapiret2    OCCURS 0 WITH HEADER LINE.
    DATA: lt_schedules_inx   TYPE STANDARD TABLE OF bapischdlx
                             WITH HEADER LINE.
    DATA: lt_schedules_in    TYPE STANDARD TABLE OF bapischdl
                             WITH HEADER LINE.
    HEADER DATA
    header-doc_type = p_auart.
    headerx-doc_type = 'X'.
    header-sales_org = p_vkorg.
    headerx-sales_org = 'X'.
    header-distr_chan  = p_vtweg.
    headerx-distr_chan = 'X'.
    header-division = p_spart.
    headerx-division = 'X'.
    headerx-updateflag = 'I'.
    PARTNER DATA
    partner-partn_role = 'AG'.
    partner-partn_numb = p_sold.
    APPEND partner.
    partner-partn_role = 'WE'.
    partner-partn_numb = p_ship.
    APPEND partner.
    ITEM DATA
    itemx-updateflag = 'I'.
    item-itm_number = '000010'.
    itemx-itm_number = 'X'.
    item-material = p_matnr.
    itemx-material = 'X'.
    item-plant    = p_plant.
    itemx-plant   = 'X'.
    item-target_qty = p_menge.
    itemx-target_qty = 'X'.
    item-target_qu = 'EA'.
    itemx-target_qu = 'X'.
    item-item_categ = p_itcat.
    itemx-item_categ = 'X'.
    APPEND item.
    APPEND itemx.
      Fill schedule lines
    lt_schedules_in-itm_number = '000010'.
    lt_schedules_in-sched_line = '0001'.
    lt_schedules_in-req_qty    = p_menge.
    APPEND lt_schedules_in.
      Fill schedule line flags
    lt_schedules_inx-itm_number  = '000010'.
    lt_schedules_inx-sched_line  = '0001'.
    lt_schedules_inx-updateflag  = 'X'.
    lt_schedules_inx-req_qty     = 'X'.
    APPEND lt_schedules_inx.
    Call the BAPI
    CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
         EXPORTING
              sales_header_in     = header
              sales_header_inx    = headerx
         IMPORTING
              salesdocument_ex    = v_vbeln
         TABLES
              return              = return
              sales_items_in      = item
              sales_items_inx     = itemx
              sales_schedules_in  = lt_schedules_in
              sales_schedules_inx = lt_schedules_inx
              sales_partners      = partner.
    Check the return table.
    LOOP AT return WHERE type = 'E' OR type = 'A'.
      EXIT.
    ENDLOOP.
    IF sy-subrc = 0.
      WRITE: / 'Error in creating document'.
    ELSE.
      COMMIT WORK AND WAIT.
      WRITE: / 'Document ', v_vbeln, ' created'.
    ENDIF.
    ************DELIVERY CREATION.
    DATA: BEGIN OF t_vbap OCCURS 0,
            vbeln LIKE vbap-vbeln,
            posnr LIKE vbap-posnr,
            zmeng  LIKE vbap-kwmeng,
            matnr  LIKE vbap-matnr,
            werks  LIKE vbap-werks,
          END OF t_vbap.
    DATA: t_request TYPE STANDARD TABLE OF bapideliciousrequest
          WITH HEADER LINE.
    DATA: t_created TYPE STANDARD TABLE OF bapideliciouscreateditems
          WITH HEADER LINE.
    DATA: t_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE.
    SELECT vbeln posnr zmeng matnr werks
           INTO TABLE t_vbap
           FROM vbap
           WHERE vbeln = v_vbeln.
    LOOP AT t_vbap.
      t_request-document_numb = t_vbap-vbeln.
      t_request-document_item = t_vbap-posnr.
      t_request-quantity_sales_uom = t_vbap-zmeng.
      t_request-quantity_base__uom  = t_vbap-zmeng.
      t_request-id = 1.
      t_request-document_type = 'A'.
      t_request-delivery_date      = sy-datum.
      t_request-material = t_vbap-matnr.
      t_request-plant = t_vbap-werks.
      t_request-date = sy-datum.
      t_request-goods_issue_date = sy-datum.
      t_request-goods_issue_time = sy-uzeit.
      APPEND t_request.
    ENDLOOP.
    CALL FUNCTION 'BAPI_DELIVERYPROCESSING_EXEC'
         TABLES
              request      = t_request
              createditems = t_created
              return       = t_return.
    READ TABLE t_return WITH KEY type = 'E'.
    IF sy-subrc = 0.
      MESSAGE e208(00) WITH 'Delivery creation error'.
    ENDIF.
    COMMIT WORK.
    ************Post goods issue.
    READ TABLE t_created INDEX 1.
    DATA: vbkok_wa TYPE vbkok.
    vbkok_wa-vbeln_vl = t_created-document_numb.
    vbkok_wa-wabuc = 'X'.
    DATA: v_error.
    CALL FUNCTION 'WS_DELIVERY_UPDATE'
         EXPORTING
              vbkok_wa                  = vbkok_wa
              delivery                  = t_created-document_numb
         IMPORTING
              ef_error_in_goods_issue_0 = v_error.
    COMMIT WORK.
    Thanks,
    Naren

  • BAPI Sales Order create with reference Invoice document

    Hi
      I am using BAPI ''SD_SALESDOCUMENT_CREATE''  to create debit memo request with reference Invoice document.
      First time its successfully created with reference Invoice.When i am going to create 2nd time debit memo request with  same reference Invoice and item
      no its giving following error.
          Reference quantity:             
    10 EA (total referenced:             
    40 EA)
           Error in SALES_ITEM_IN 000010
           Condition ZSLS is not allowed as header condition
           Sales document  was not changed
        Please help any one to resolved this issue.
       Regards
       Shyam

    SD_SALESDOCUMENT_CREATE is not a BAPI. Is there any specific reason you're using this FM when the actual BAPI exists?
    ZSLS is a custom condition. There might as well be some user exit that attempts to add it [possibly incorrectly], how would we know this on SCN? There is enough information in the error message to troubleshoot on your own, it seems. What kind of analysis have you done before posting on SCN?

  • How to maintain serial no for sales order created by BAPI

    Hi all,
    We are using BAPI for creating sales order "BAP_SALESORDERDAT2" but we are not able to assign Serial number while using this BAPI. Is there any function modul, BAPI, or workarround available to solve this problem. Or how to maintain Serial number.
    Regards
    Shambhu Sarkar

    Hi
    It is not possible to to maintain serial numbers with the normal SD
    BAPIS. This functionality is not scope of the BAPIS.
    regards,
    Ramana

  • Creating the Sales Order using the bapi BAPI_SALESORDER_CREATEFROMDAT2

    Hi,
    My problem is , i have created one module pool program for accelerating the Sales Order creation.
    I am using the bapi BAPI_SALESORDER_CREATEFROMDAT2 for sales order creation. After executing the program
    bapi is given an errot that, incomplete sales order document is saved.
    Can any body tell me plz what are the necessary fields i need to take in the header and item level , so that the complete
    document will be saved through BAPI.
    <removed_by_moderator>
    Thanks
    Edited by: Julius Bussche on Jan 11, 2010 12:09 PM

    TABLES: VBAK,                             "Sales Document: Header Data
            VBAP.                             "Sales Document: Item Data
    *************************************WORK AREA DECELERATION************************
    DATA: BEGIN OF WA_HEADER,
            LI    TYPE I,                      "LINE TYPE
            AUART TYPE VBAK-AUART,             "Sales Document Type
            VKORG TYPE VBAK-VKORG,             "Sales Organization
            VTWEG TYPE VBAK-VTWEG,             "Distribution Channel
            SPART TYPE VBAK-SPART,             "Division
            KUNNR TYPE BAPIPARNR-PARTN_NUMB,   "Customer number
          END OF WA_HEADER.
    DATA: BEGIN OF WA_ITEM,
            LI     TYPE I,
            MATNR  TYPE VBAP-MATNR,            "MATERIAL NUMBER
            ZMENG  TYPE VBAP-ZMENG,           "QUANTITY
          END OF WA_ITEM.
    ***********************************INTERNAL TABLE DECELERATION***************************************
    DATA: IT_HEADER      LIKE TABLE OF WA_HEADER WITH HEADER LINE.                   "IT FOR HEADER
    DATA: IT_ITEM        LIKE TABLE OF WA_ITEM WITH HEADER LINE.                     "IT FOR ITEM
    DATA: IT             LIKE VBAK OCCURS 0 WITH HEADER LINE.
    ***************************SALES ORDER INTERNAL TABLE DECELERATION********************************
    DATA:
          HEADER  TYPE TABLE OF BAPISDHEAD WITH HEADER LINE,        "SALES HEADER DATA
          ITEMS   TYPE TABLE OF BAPIITEMIN WITH HEADER LINE,         "SALES ITEM DATA
          PARTNERS TYPE TABLE OF BAPIPARTNR WITH HEADER LINE.      "SALLES PARTNERS
    ***********************************DYNAMIC FIEL PATH GETTING DECELERATION************************
    DATA : HL_FIELD_NAME TYPE DYNPREAD-FIELDNAME VALUE 'G_P_SPATH',              "SCREEN FIELD NAME
           HL_FILE_NAME  TYPE IBIPPARMS-PATH VALUE 'G_P_SPATH',                  "Local file for upload/download
           IL_FIELD_NAME TYPE DYNPREAD-FIELDNAME VALUE 'G_P_EPATH',              "SCREEN FIELD NAME
           IL_FILE_NAME  TYPE IBIPPARMS-PATH VALUE 'G_P_EPATH',                  "Local file for upload/download
           FL_FIELD_NAME TYPE DYNPREAD-FIELDNAME VALUE 'G_P_EPATH',              "SCREEN FIELD NAME
           FL_FILE_NAME  TYPE IBIPPARMS-PATH VALUE 'G_P_EPATH'.                  "Local file for upload/download
    DATA : CTR TYPE I .
    DATA : CTR2 TYPE STRING.
    DATA : CTR1 TYPE STRING.
    Sales document number
    DATA : L_VBELN LIKE BAPIVBELN-VBELN.
    SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE T1.
    SELECTION-SCREEN : SKIP.
    PARAMETER        : P_HPATH TYPE STRING.
    PARAMETER        : P_IPATH TYPE STRING.
    SELECTION-SCREEN : SKIP.
    SELECTION-SCREEN : END OF BLOCK B1.
    SELECTION-SCREEN : BEGIN OF BLOCK B2 WITH FRAME TITLE T2.
    SELECTION-SCREEN : SKIP.
    SELECTION-SCREEN : BEGIN OF LINE.
    SELECTION-SCREEN : PUSHBUTTON 10(14) UPLOAD USER-COMMAND CLICK1.
    SELECTION-SCREEN : END OF LINE.
    SELECTION-SCREEN   END OF BLOCK B2.
    ******************************************INITIALIZATION.***************************************************
    INITIALIZATION.
      T1       = 'Putchase Order Source File Path'.
      T2       = 'Push Button'.
      UPLOAD   = 'Upload'.
    *******************************************AT SELECTION SCREE EVENT********************************************
    AT SELECTION-SCREEN.
      CASE SY-UCOMM.
        WHEN 'CLICK1'.
          IF P_HPATH IS INITIAL AND P_IPATH IS INITIAL.      "CHECKING BTHE THE TEXT BOX
            MESSAGE I009.
          ELSE.
            PERFORM SELECT.                                  "CALLING THE SELECT SUBROUTINE
          ENDIF.
        WHEN OTHERS.
          MESSAGE 'PRESS FORM BUTTON' TYPE 'I'.      "WHEN EXECUTE BUTTON IS PRESSED
      ENDCASE.
    ***********************************GETTING HEADER FIEL PATH*******************************************
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_HPATH.
      CALL FUNCTION 'F4_FILENAME'
        EXPORTING
          PROGRAM_NAME  = SYST-CPROG
          DYNPRO_NUMBER = SYST-DYNNR
          FIELD_NAME    = HL_FIELD_NAME
        IMPORTING
          FILE_NAME     = HL_FILE_NAME.
      P_HPATH = HL_FILE_NAME.
    ***********************************GETTING ITEM FIEL PATH*******************************************
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_IPATH.
      CALL FUNCTION 'F4_FILENAME'
        EXPORTING
          PROGRAM_NAME  = SYST-CPROG
          DYNPRO_NUMBER = SYST-DYNNR
          FIELD_NAME    = IL_FIELD_NAME
        IMPORTING
          FILE_NAME     = IL_FILE_NAME.
      P_IPATH = IL_FILE_NAME.
    START-OF-SELECTION.
    *&      Form  SELECT
          text
    -->  p1        text
    <--  p2        text
    FORM SELECT .
      CALL FUNCTION 'GUI_UPLOAD'             " function resposible to get the local flat
          EXPORTING                          " and upload it in a internal table
            FILENAME            = P_HPATH
            FILETYPE            = 'ASC'
            HAS_FIELD_SEPARATOR = '#'
          TABLES
            DATA_TAB            = IT_HEADER.
      CALL FUNCTION 'GUI_UPLOAD'             " function resposible to get the local flat
          EXPORTING                          " and upload it in a internal table
            FILENAME            = P_IPATH
            FILETYPE            = 'ASC'
            HAS_FIELD_SEPARATOR = '#'
          TABLES
            DATA_TAB            = IT_ITEM.
      LOOP AT IT_HEADER.
        Initialize Header values
        HEADER-DOC_TYPE     =  IT_HEADER-AUART.
        HEADER-SALES_ORG    =  IT_HEADER-VKORG.
        HEADER-DISTR_CHAN   =  IT_HEADER-VTWEG.
        HEADER-DIVISION     =  IT_HEADER-SPART.
        APPEND HEADER.
        PARTNERS-PARTN_ROLE = 'WE'.
        PARTNERS-PARTN_NUMB = IT_HEADER-KUNNR.
        APPEND PARTNERS.
        CTR = 10.
        LOOP AT IT_ITEM WHERE LI = IT_HEADER-LI.
          CTR2 = CTR.
          CONCATENATE '0000' CTR2 INTO CTR1.
    ***Initialize Item values
         ITEMS-ITM_NUMBER   = IT_ITEM-ITEM.
          ITEMS-ITM_NUMBER   = CTR1.
          ITEMS-MATERIAL     = IT_ITEM-MATNR.
          ITEMS-REQ_QTY   = IT_ITEM-ZMENG.
          APPEND ITEMS.
          CTR = CTR + 10.
        ENDLOOP.
        CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
          EXPORTING
            ORDER_HEADER_IN = HEADER                      "SALES HEADER DATA
          IMPORTING
            SALESDOCUMENT   = L_VBELN                        "RETRIEVED SALES DOCUMENT NUMBER
          TABLES
            ORDER_ITEMS_IN  = ITEMS                       "SALES ITEM LEVEL DATA
            ORDER_PARTNERS  = PARTNERS.                    "SAKES PARTNERS
        APPEND L_VBELN TO IT.
        COMMIT WORK AND WAIT.
        CLEAR : HEADER , ITEMS[] ,PARTNERS,CTR,CTR1,CTR2.
        REFRESH : ITEMS.
      ENDLOOP.
      IF IT[] IS NOT INITIAL.
        LOOP AT IT.
          WRITE: / 'SALES ORDER', IT-VBELN , 'CREATED'.
        ENDLOOP.
        LEAVE TO LIST-PROCESSING.
        SET PF-STATUS SPACE.
      ELSE.
        MESSAGE I044.
      ENDIF .
    ENDFORM.                    " SELECT

  • Changing Rejected Sales Order Items with BAPI?

    Hi Forum,
    I have the following challenge, would be great if someone of you could help me out. Will help me solve some of my performance problems.
    I have sales orders which are temporary and have 'rejected order items'. Now the requirement is that I have to change the 'rejected order items' (quantity and Delivery dates) based on some XYZ criteria. Now using the BAPI_SALESORDER_CHANGE bapi I have to
    1. first get rid of the 'REJECTION REASON'
    2. Change the order item and then reset the above.
    I tried doing it by populating the order_items internal table with two entries but to my surprise it works once and fails twice!!! I get some errors that are totally irrelated and wierd.
    As for now, I've just adjusted the program(dirtily??) and will be calling the BAPI twice for a change !!!(Huh!)
    Now if anybody knows how to deal with the above problem just drop a few lines, will be of good help to me.
    Thanks and regards,
    ZAM

    Hi Srinivas,
    Thanks for the reply. The rejection reason is set manually, when creating the sales order. I do set the update flag to 'U' and also activating all the X structures. But still it did not work.
    Let me put it very simple. Is it possible to change the rejected order items, through BAPI's? If yes, how?
    Regarding the error messages I will have to change the code again to recreate the messages will let you know as soon as I am finished with some things. But however here are some errors
    Field 'WMENG' cannot be changed, VBEPKOM 000100 0001 ready for input
    Field 'WMENG' cannot be changed, VBEPKOM 000100 0001 ready for input
    Sales document 0030000031 was not changed                           
    there are few others which appear now and then indicating a system error !!
    thanks,
    ZAM

  • Re. Sales order Created with reference to Contract

    Hi Guru's,
    I have create a Contract with Sold to party, Ship to party and material combination. So when i am creating a Sales order for the same combination system is not proposing the availability of contract. I manually need to assign the contract to the sales order.
    Am i missing any configuration. Can any one suggest the solution for the same.
    It would be of great help.
    Thanks in advance.
    With Best Regards,
    M. Rajendran.

    Hi Rajendran M, 
    Maintain the copy control in VTAA
    select your Sales document type & contract document type
    In Header
    Data T- 051
    Data T- 101
    Data T- 001
    copying req- 001
    check mark copy item number
    in Item - select yourcontract item category
    Data T- 151
    Data T- 102
    Data T- 002
    FPLA- 251
    copying req- 301
    check mark copy schedules
    x update document flow
    pos/neg qty - +
    pricing type- G
    Let me know if your problem is solved
    Regards
    Pradeep

  • Remove Header text from a sales order, created with reference to quotation

    Hi all,
    I have a sales order(in VA01) which is created with reference to quotation (in VA21).
    If header text (Notes for logistics, Note for responsible person, Header text Doc & Declaration) in texts tab is maintained in the quotation they are getting copied in Sales Order which is NOT the requirement.
    I need suggestions on how to disable the text that is getting copied.
    Any pointers would be of great help.
    Regards,
    Vamsee Priya.

    Hi Nilesh,
    I created a routine in vofm and this solved my problem.
    Now, I'm having a similar problem where I'm creating an Invoice(through transaction VF01) giving the delivery document number and document type (Invoice F2).
    we are maintaining Header text in Order through which the above mentioned delivery document number is created and this header text should get copied in the Invoice.
    For this, I went into Transaction VOTXN, from there selected billing header, from here kept a break point for the routine BEDINGUNG_PRUEFEN_001 through which the text will get copied.
    Now, when I'm creating the Invoice this routine is getting executed, but still the text is not getting copied.
    Any pointers on this would be of great help.
    Also at the end of your previous mail, you are telling about SPRO - text assignment. Can you please let me know how to I should navigate to this text-assignment??
    Thanks and Regards,
    Vamsee Priya.

Maybe you are looking for

  • I did IOS update and cannot locate my personal music. Downloaded music from Itunes is ok.

    I did current OS update for my macbook pro. My personal music is missing. Downloaded music from Itunes is ok. How do i find my missing music?

  • Apps removed from my iPhone b/c I don't have the most current OS version?

    Several apps including Yelp, London Tube, and other purchased apps were removed from my phone the last time I did a sync with iTunes with the message that a newer iPhone version was required. I currently have 3.0 and not 3.1.2 but why wouldn't it hav

  • Terminal login message missing

    (previously posted to wrong forum) Starting Terminal.app results in Macintosh:~[myusername]$ only. Also, it seems to take longer than it once did for the message, such as it is, to appear. I have trashed the Terminal preferences in my local library f

  • Interpretation Statspack

    Hi Friends, Top 5 Timed Events Avg %Total ~~~~~~~~~~~~~~~~~~ wait Call Event Waits Time (s) (ms) Time db file sequential read 324,488 1,169 4 48.4 db file scattered read 283,960 722 3 29.9 CPU time 285 11.8 SQL*Net break/reset to client 2,480 150 61

  • Sample code for Org Management

    Hi,          I am new to Org Management coding in HR ABAP.    Can anybody post some simple sample code for Org. Management so that I can understand the flow of coding.. Thanks and Regards, Ram