Bapi Sales Order Create

Hello,
I am using BAPI_SALESORDER_CREATEFROMDAT2 to create sales order. The system is configured to automatically generate the item numbers. I can create an order alright for simple materials.
For this I am populating both Line items and Schedule Line item structures - ORDER_ITEMS_IN and ORDER_SCHEDULES_IN respectively, without passing the line item number(ITM_NUMBER field).
The problem is when I create an order which has a KIT as a line item.
So SAP explodes the Kit correctly, but the quantity information goes all wrong for the subsequent lines after the kit. Hence order does not get correctly created.
Any hints on how to solev this? I want to create the order with Kit and simple materials and without provising the line item numbers.

hello,
Please check the following code in case its a bill of material
FORM CHECK_SALES_BOM  TABLES ORDER_ITEMS_IN STRUCTURE BAPIITEMIN
                             ORDER_PARTNERS STRUCTURE ZBAPISHIP1.
  CLEAR FLAG_CANCEL_CREATE.
  CLEAR V_LINES1.
  LOOP AT ORDER_ITEMS_IN.
    V_ITM_NUMBER = ORDER_ITEMS_IN-ITM_NUMBER.
  ORDER_ITEMS_IN-PO_ITM_NO = ORDER_ITEMS_IN-ITM_NUMBER.   " DEVK942749
    ORDER_ITEMS_IN-ITM_NUMBER = 10 * SY-TABIX + 10 * V_LINES1.
    MODIFY ORDER_ITEMS_IN.
    LOOP AT ORDER_PARTNERS WHERE ITEM_NUMB = V_ITM_NUMBER.
      ORDER_PARTNERS-ITEM_NUMB = ORDER_ITEMS_IN-ITM_NUMBER.
      MODIFY ORDER_PARTNERS.
    ENDLOOP.
    SELECT SINGLE KNUMH FROM KOTD001 INTO KOTD001-KNUMH
                 WHERE KAPPL = 'V'
                 AND KSCHL = 'A001'
                 AND  MATWA = ORDER_ITEMS_IN-MATERIAL
                 AND DATBI GE SY-DATUM
                 AND DATAB LE SY-DATUM.
    IF SY-SUBRC = 0.
      SELECT SINGLE SMATN FROM KONDD INTO KONDD-SMATN
                   WHERE KNUMH = KOTD001-KNUMH.
      ORDER_ITEMS_IN-MATERIAL = KONDD-SMATN.
    ELSE.
      ORDER_ITEMS_IN-MATERIAL = ORDER_ITEMS_IN-MATERIAL.
    ENDIF.
    CLEAR V_WERKS.
    SELECT SINGLE DWERK MTPOS INTO (V_WERKS, MVKE-MTPOS) FROM MVKE
      WHERE MATNR = ORDER_ITEMS_IN-MATERIAL
      AND   VKORG = WWW_ORDER_HEADER_EXP-VKORG
      AND   VTWEG = WWW_ORDER_HEADER_EXP-VTWEG.
    IF MVKE-MTPOS EQ 'LUMF' OR MVKE-MTPOS EQ 'ZLUM'.
      READ TABLE ORDER_PARTNERS WITH KEY ITEM_NUMB = V_ITM_NUMBER
                                     PARTN_ROLE = 'WE'.
      REFRESH : DA_MASTB,
                DA_STKOB,
                DA_STZUB.
      CALL FUNCTION 'CS_ALT_SELECT_MAT'
         EXPORTING
        ALL            = ' '
             CAPID          = 'SD01'
             DATUV          = SY-DATUM
        DIALF          = ' '
        LOSGR          = 0
             MATNR          = ORDER_ITEMS_IN-MATERIAL
        NOTAB          = 'X'
        NRFDC          = ' '
        STLAL          = ' '
        STLAN          = ' '
        VPRIO          = ' '
             WERKS          = V_WERKS
        TABLES
             MASTB_WA       =   DA_MASTB
             STKOB_WA       =   DA_STKOB
             STZUB_WA       =   DA_STZUB
        EXCEPTIONS
             ALT_NOT_FOUND  = 1
             BOM_NOT_ACTIVE = 2
             BOM_NOT_FOUND  = 3
             CALL_INVALID   = 4
             NO_ALT_FOUND   = 5
             NO_BOM_FOUND   = 6
             OTHERS         = 7.
      READ TABLE DA_MASTB INDEX 1.
      IF SY-SUBRC = 0.
        CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
            EXPORTING
                 CAPID                 = 'SD01'
                 DATUV                 = SY-DATUM
                 EMENG                 = 1
                 MEHRS                 = 'X'
                 MTNRV                 = ORDER_ITEMS_IN-MATERIAL
                 RNDKZ                 = '2'
                 STLAL                 = '01'
                 WERKS                 = V_WERKS
            IMPORTING
                 TOPMAT                = CSTMAT
             TABLES
                  STB                  =  TSTB
               MATCAT                =
             EXCEPTIONS
                  ALT_NOT_FOUND         = 1
                  CALL_INVALID          = 2
                  MATERIAL_NOT_FOUND    = 3
                  MISSING_AUTHORIZATION = 4
                  NO_BOM_FOUND          = 5
                  NO_PLANT_DATA         = 6
                  NO_SUITABLE_BOM_FOUND = 7
                  OTHERS                = 8.
        DESCRIBE TABLE TSTB LINES V_LINES.
      ENDIF.
      V_LINES1 = V_LINES + V_LINES1 .
      CLEAR V_LINES.
    ENDIF.
  ENDLOOP.
hope this will help you.
Reward points if it helps
regards,
krishna

Similar Messages

  • 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.

  • 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?

  • BAPI Sales order create - Ship to party Error

    Dear All,
    I have an issue with BAPI_SALESDOCU_CREATEFROMDATA1.
    I need different ship to party's on the items , irresspective of the header ship to party. Currently the order is getting created with the same ship to party for all the items , same as the header ship to party. Please refer the code below and help.
    Sales document type
      IF zdemmast-doc_type = 'X'.
        header-doc_type = 'ZDMM'.
      ELSEIF zdemmast-doc_type = 'ZDME'.
        headerx-doc_type = 'X'.
      ENDIF.
    Sales organization
      header-sales_org = '1000'.
      headerx-sales_org = 'X'.
    Distribution channel
      header-distr_chan = '10'.
      headerx-distr_chan = 'X'.
    Division
      header-division = '10'.
      headerx-division = 'X'.
      headerx-updateflag = 'I'.
    Sold to
      partner-partn_role = 'AG'.
      partner-partn_numb = zdemmast-kunnr.
      APPEND partner.
    Ship to
      partner-partn_role = 'WE'.
      partner-partn_numb = zdemmast-kunnr.
      APPEND partner.
      LOOP AT it_zdem_item INTO wa_zdem_item.
        itemx-updateflag = 'I'.
        item-itm_number = wrk_item_number.
        itemx-itm_number = 'X'.
        item-material =  '000000000000000016'. "wa_zdem_item-matnr.
        itemx-material = 'X'.
        item-plant = '1000'.
        itemx-plant = 'X'.
        item-target_qty = wa_zdem_item-cret.
        itemx-target_qty = 'X'.
        lt_schedules_in-itm_number = wrk_item_number.
        lt_schedules_in-sched_line = '0001'.
        lt_schedules_in-req_qty = wa_zdem_item-cret.
        lt_schedules_inx-itm_number = wrk_item_number.
        lt_schedules_inx-sched_line = '0001'.
        lt_schedules_inx-updateflag = 'X'.
        lt_schedules_inx-req_qty = 'X'.
        partner-partn_role = 'WE'.
        partner-partn_numb = wa_zdem_item-kunnr.
        partner-itm_number = wrk_item_number.
        APPEND item.
        APPEND itemx.
        APPEND lt_schedules_in.
        APPEND lt_schedules_inx.
        APPEND partner.
        wrk_item_number =  wrk_item_number  + 10.
      ENDLOOP.
    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.
    Please suggest.
    Thanks in advance

    Hi,
    try the following:
    Fill tables parameter SALES_PARTNERS (BAPIPARTNR).
    For header don't fill field ITM_NUMBER.
    For position fill field ITM_NUMBER.
    For example (BAPIPARTNR):
    SP | 0000010000 | 000000 | ...
    SP | 0000009034 | 000001 | ...
    At header the ship to will be "10000" and at item 1 it will be "9034".
    Regards

  • Getting Error while creating multiple Orders using Sales order Create BAPI

    Hi,
    I am trying to create 2 orders thru the Sales order create BAPI before I commit and save the orders. The Orders are getting created and the BAPI is coming back with success, but it is not setting the system status on the line items of the 1st order. So when I try to cancel the line items on the first order I get the error 'No status object is available for SDI 4924/10' . I would really appreciate if anyone has encountered such error before and could help me out with the reason for this error and the possible solution.
    Thanks in advance,
    David.

    Hi,
    Check the following link:
    http://www.sap-img.com/bapi.htm
    Regards,
    Bhaskar

  • Need code for sales order create report using bapi's

    need code for sales order create report using bapi's

    Hi,
    Go through below link
    http://www.saptechies.com/bapi_salesorder_createfromdat2/
    <b>Reward points if it helps,</b>
    Satish

  • Function module which uses both BAPI's for sales order create and change

    Please name the function module which uses both BAPI's for sales order create and change.
    BAPI_SALESORDER_CREATEFORMDAT2
    BAPI_SALESORDERCHANGE

    Yup.
    you must write a piece of code for this.
    with if else condition.first check if SO is exsist than use second FM to change it else create new SO from first FM.
    logic somethig like this.
    Amit.

  • HAI PROBLEM SALES ORDER CREATE

    hi,
    my requirement is to create a salesorder for quotation.
    But in BAPI_SALESORDER_CREATEFROMDAT2 ,i did not see any reference to quotation.please help me to do this
    regards
    Guru

    Hi Guru,
    Here is some documentation on it.
    Method
    SalesOrder.CreateFromDat2
    Sales order: Create Sales Order
    Functionality
    You can use this method to create sales orders.
    You must enter at least sales order header data (via ORDER_HEADER_IN structure) and partner data (via the ORDER_PARTNERS table) as input parameters.
    Enter the item data via the ORDER_ITEMS_IN table. You can allocate item numbers manually, by filling in the relevant fields, or the system does it, according to the settings for Customizing, by leaving the relevant fields blank.
    If you have configurable items, you must enter the configuration data in the ORDER_CFGS_REF, ORDER_CFGS_INST, ORDER_CFGS_PART_OF and ORDER_CFGS_VALUE tables.
    Credit cards can be transferred via the BAPICCARD structure, on the one hand, data for card identification, on the other, data for a transaction which has taken place in an external system.
    Once you have created the sales order successfully, you will receive the document number (SALESDOCUMENT field). Any errors that may occur will be announced via the RETURN parameter.
    If no sales area has been created in the sales order header, then the system creates the sales area from the sold-to party or ship-to party, who has been entered in the partner table. If a clear sales area cannot be created, you will receive a system message, and the sales order will not be created.
    Notes
    Mandatory entries:
    ORDER_HEADER_IN : DOC_TYPE Sales document type
    SALES_ORG Sales organization
    DISTR_CHAN Distribution channel
    DIVISION Division
    ORDER_PARTNERS..: PARTN_ROLE Partner role, SP sold-to party
    PARTN_NUMB Customer number
    ORDER_ITEMS_IN..: MATERIAL Material number
    Ship-to party:
    If no ship-to party is entered, use the following: Ship-to party =
    sold-to party.
    Commit control:
    The BAPI does not have a database commit. This means that the relevant application must leave the commit, in order that can be carried out on on the database. The BAPI BAPI_TRANSACTION_COMMIT is available for this.
    German key words:
    The following key words must be entered in German, independantly of
    the logon language:
    DOC_TYPE Sales document type, for example: TA for standard order
    PARTN_ROLE Partner role, for example: WE for ship-to party
    Thanks,
    Susmitha

  • Sales order create/append difference

    Hi,
    I've been trying to find a standard way to find out whether a sales order is being created or appended through any means other than the below:
    1) VBAK-VBELN can be checked to see if the sales order number has beencreated while in a user exit
    2) SY-TCODE can be checked for value 'VA01' or 'VA02' - of course this will not work while calling a BAPI to create the order
    3) T180-TRTYP Again, this is line specific, it will only show if a line is being inserted or amended - so this doesn't help me
    Does anyone know any other way, preferrable using a SAP standard field to figure out the difference between sales order create and append?
    Thanks,
    Tabraiz

    What i mean to say is if the exit triggers in bapi execution and
    if the any of the parameter in your exits has the document number,
    then you can just do a select single from db and confirm whether its change or create.
    like
    if ( sy-tcode = 'BAPI' ) or ( sy-code CP 'Z*' )  or ( sy-tcode = 'SE38' ) or ( sy-tcode = 'SE37' ).
    select single * from abc.....
    elseif sy-tcode = 'VA01'.
    elseif sy-tcode = 'VA02'.
    endif.
    also
    did you check the field TCODE in table T180

  • Sales order creating

    Hi friends,
    Please give the process for
    Sales Orders Creating/Changing by
    1)BAPI
    2)  Recording Methods
    With Regards,
    Sarath.

    Hi,
    Check this sample program for creating sales orders using the BAPI..
    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.
    Thanks,
    Naren

  • Delete sales order created more than three days ago

    Hi Experts,
    "Business has created lot of sales order  for prepayment. Only part of them are converted to deliveries, rest are stored in database.
    In Open sales orders report old orders are confusing, because of Country legislation the conditions of a sales order are valid during 3 working days. Therefore after 3 days not paid orders should be deleted."
    Kindly let me know if we have a standard fucntionality in SAP through which we can pull open sales order more than 3 days old and then can delete the same.
    If not can you help me in understanding the Logical Flow that is needed to meet the Business Requirement through a customized program.
    Looking forward to seeing your replies.

    Hi,
    As per your business requirement stated above I recommend not to delete any sales order instead use a Zprogram for sales order and mark them as "MARK FOR REJECTION".
    Doing this will solve your problem of getting unnecessary sales order in standrad report of Open sales order as in standard Rejected Sales order are not considred as in VA05 Report. and also keep record of the sales order created by you for future purpose.
    further to this as per your business requirement you have to mark line Item wise "Mark For Rejection.
    Here in coding you can give logic from Document creation date or Document Date + 3 Days if that is < system date then mark them for rejection.
    Hope this solves your purpose.

  • 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 when trying to search a sales order created by other user

    Hi. I'm running SAP HANA One PL 04. I have a problem when I log on with User1 and try to search for sales orders created by another user. I got an error message. I think the user has enough permissions.. Is there anything else I should consider??
    Hope anyone can give an idea why this happens
    Thanks

  • 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

Maybe you are looking for

  • In Exports sales process, how you configure the Duty Draw Back

    in my case we r creating Exports but duty unavailability of time and time taking process in export processing we are creating Excise invoice and cenvat is debited . now we r asking the govt. for the duty draw back for the value already cenvat is debi

  • Max number of files that can be opened in harddrive through AEBS?

    What is the maximum number of files that can be opened in a external hard drive (Lacie 500 GB, USB 2.0) connected through the AEBS? Looks like there is a limit. When I am trying to 'seed' files through a bit-torrent client (Azureus 2.5.0.4) many of t

  • Error occured while obtaining stored procedure

    Hi, I'm trying to configure a Database adapter to call a stored procedure. When I try to select the procedures in a package I get an error saying: "Error occurred while obtaining the stored procedure, Please verify the Database connection" The databa

  • Using jmf when doing an install

    when creating a program that is going to use jmf, does the host machine need to have jmf installed to do an rtp transmission of streaming video? or do i need to include a jmf.jar file in the installer package? or is the jmf pieces I need part of the

  • Purchasing group -- Organizational responsibility

    Hello, We are trying to create a report(BDC) to attach purchasing group to purch org. In the Flat file we would be entering the basic data, address, function and responsibity. But for reponsiblity we are able to find only the product category respons