Bapi to return a Sales order (RMA)

Hi guys,
I am trying to do a return using a sales order as reference. I am using:
- BAPI_OUTB_DELIVERY_CREATE_SLS <<< to create a delivery
- BAPI_TRANSACTION_COMMIT <<< to commit my changes
- WS_DELIVERY_UPDATE <<< to PGI
It doesn't produce any errors but when I go to MB52 the stock level does not change. I see in some posts that the correct bapi to post a return for a sales order is: BAPI_CUSTOMERRETURN_CREATE but i'm not sure which parameters i need to set for this bapi. Can you please help? Here's my code so far...
*Create delivery
  CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS'
    IMPORTING
      delivery          = delivery
      num_deliveries    = num_deliveries
    TABLES
      sales_order_items = sales_order_items
      serial_numbers    = serial_numbers
      deliveries        = deliveries
      created_items     = created_items
      extension_out     = extension_out
      return            = return.
*Check for errors
  READ TABLE return INTO wa_return WITH KEY type = 'E'.
  IF sy-subrc EQ 0. "error found
    p_lv_err_flag = 'X'.
    LOOP AT return INTO wa_return WHERE type = 'E'.
      CONCATENATE wa_return-message p_lv_error_message INTO p_lv_error_message SEPARATED BY space.
    ENDLOOP.
    ROLLBACK WORK.
    RETURN.
  ELSE.             "no error found
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      IMPORTING
        return = return_commit.
    IF return_commit-type = 'S' OR return_commit-type IS INITIAL.
      READ TABLE return INTO wa_return WITH KEY type = 'S' id = 'VL'.
      IF sy-subrc = 0.
        p_lv_err_flag = 'S'.
        MOVE wa_return-message TO p_lv_error_message.
      ENDIF.
    ELSE.
      p_lv_err_flag = 'X'.
      MOVE return_commit-message TO p_lv_error_message.
    ENDIF.
  ENDIF.
* Perform picking, confirmation W-M status and PGI.
  CLEAR: vbkok_wa, vbpok_tab.
  REFRESH: vbpok_tab.
* Clearing the implicit lock that mb_create_goods_mvt has. That
* prevents it from bieng called more then once within same LUW.
  PERFORM clear_xcommit IN PROGRAM saplmbwl.
  LOOP AT created_items INTO created_items_wa.
    vbkok_wa-vbeln_vl = created_items_wa-deliv_numb.
    vbkok_wa-vbtyp_vl = 'C'. "order
    vbkok_wa-vbeln = created_items_wa-deliv_numb.
    vbkok_wa-wabuc = 'T'. "returns delivery
    vbpok_wa-vbeln_vl = created_items_wa-deliv_numb.
    vbpok_wa-posnr_vl = created_items_wa-deliv_item.
    vbpok_wa-vbeln = created_items_wa-deliv_numb.
    vbpok_wa-posnn = created_items_wa-deliv_item.
    vbpok_wa-matnr = created_items_wa-material.
*  vbpok_wa-charg = fp_afpo-charg. "batch number???
    READ TABLE p_lt_rma_be INTO ls_rma_be WITH KEY matnr = created_items_wa-material.
    vbpok_wa-werks = ls_rma_be-werks.
    vbpok_wa-taqui = 'X'.
    vbpok_wa-pikmg = created_items_wa-dlv_qty.
    APPEND vbpok_wa TO vbpok_tab.
  ENDLOOP.
  CALL FUNCTION 'WS_DELIVERY_UPDATE'
    EXPORTING
      vbkok_wa                 = vbkok_wa
      synchron                 = 'X'
      delivery                 = delivery_ws
      update_picking           = 'X'
      nicht_sperren            = 'X'
      if_database_update       = '1'
      if_error_messages_send_0 = 'X'
    TABLES
      vbpok_tab                = vbpok_tab
      prot                     = prot.
* Checking if any error in PGI
  READ TABLE prot WITH KEY msgty = 'E' TRANSPORTING NO FIELDS.
  IF sy-subrc EQ 0.
    MESSAGE e046 WITH delivery_ws.
    ROLLBACK WORK.
    RETURN.
  ENDIF.
  READ TABLE prot WITH KEY msgty = 'A' TRANSPORTING NO FIELDS.
  IF sy-subrc EQ 0.
    MESSAGE e046 WITH delivery_ws.
    ROLLBACK WORK.
    RETURN.
  ENDIF.
  COMMIT WORK AND WAIT.

I got past the previous error. I'm now getting the following error:
External number assignment is not defined for document type ZRE
Sales document 0000000018 was not changed
Here's the code:
*& Report  ZTEST_BAPI_RETURN_SALES_ORDER
REPORT  ztest_bapi_return_sales_order.
DATA: return_partners TYPE TABLE OF bapiparnr,
      wa_return_partners TYPE bapiparnr,
      return_header_in TYPE bapisdhd1,
      return_header_inx TYPE bapisdhd1x,
      return_items_in TYPE TABLE OF bapisditm,
      return_items_in_wa TYPE bapisditm,
      return_items_inx TYPE TABLE OF bapisditmx,
      return_schedules_in TYPE TABLE OF bapischdl,
      return_schedules_inx TYPE TABLE OF bapischdlx,
      return TYPE TABLE OF bapiret2,
      wa_return TYPE bapiret2,
      salesdocumentin TYPE bapivbeln-vbeln,
      salesdocument TYPE bapivbeln-vbeln.
DATA: lv_knumv TYPE vbrk-knumv.
DATA: i_konv LIKE konv OCCURS 0 WITH HEADER LINE,
      i_conditions TYPE TABLE OF bapicond WITH HEADER LINE.
salesdocumentin = '0000000018'.
SELECT SINGLE knumv FROM vbrk INTO lv_knumv WHERE vbeln = salesdocumentin.
IF sy-subrc = 0.
  SELECT * FROM konv
  INTO TABLE i_konv
  WHERE knumv = lv_knumv
  AND kposn = '000010'
  AND kschl = 'ZRSK'.
*  AND kschl = 'ZPR0'.
*  AND kschl = 'ZRSK'.
*  AND kschl = 'ZKF1'.
*  AND kschl = 'CTXJ'.
*  AND kschl = 'JRC1'.
*  AND kschl = 'JRC2'.
*  AND kschl = 'VPRS'.
  LOOP AT i_konv.
    i_conditions-itm_number = i_konv-kposn.
    i_conditions-cond_type = i_konv-kschl.
    i_conditions-cond_value = i_konv-kbetr.
    i_conditions-currency = i_konv-waers.
    i_conditions-cond_unit = i_konv-kmein.
    i_conditions-cond_p_unt = i_konv-kpein.
    i_conditions-numconvert = i_konv-kumza.
    i_conditions-denominato = i_konv-kumne.
    i_conditions-condorigin = i_konv-kherk.
    i_conditions-accountkey = i_konv-kvsl1.
    i_conditions-condcntrl = i_konv-ksteu.
    i_conditions-condclass = i_konv-koaid.
    i_conditions-condchaman = i_konv-kmprs.
    APPEND i_conditions.
  ENDLOOP.
ENDIF.
CLEAR: return_header_in, return_header_inx.
return_header_in-price_date = sy-datum.
return_header_in-ref_doc = '0000000018'.
return_header_in-doc_type = 'ZRE'.
return_header_in-sales_org = '1000'.
return_header_in-distr_chan = '10'.
return_header_in-division = '10'.
return_header_in-sales_grp = '110'.
return_header_in-sales_off = '100'.
return_header_in-ship_cond = 'RE'.
return_header_inx-ref_doc = 'X'.
return_header_inx-doc_type = 'X'.
return_header_inx-updateflag = 'I'.
return_items_in_wa-itm_number = '000010'.
return_items_in_wa-material = 'TACKER'.
return_items_in_wa-target_qty = '1'.
APPEND return_items_in_wa TO return_items_in.
wa_return_partners-partn_role = 'AG'.
wa_return_partners-partn_numb = '0000200111'.
*wa_return_partners-itm_number = '000010'.
APPEND wa_return_partners TO return_partners.
CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE'
  EXPORTING
    salesdocumentin               = salesdocumentin
    return_header_in              = return_header_in
    return_header_inx             = return_header_inx
  IMPORTING
    salesdocument                 = salesdocument
  TABLES
    return                        = return
    return_items_in               = return_items_in
    return_items_inx              = return_items_inx
    return_partners               = return_partners
    return_schedules_in           = return_schedules_in
    return_schedules_inx          = return_schedules_inx
    return_conditions_in          = i_conditions
LOOP AT return INTO wa_return WHERE type = 'E'.
  WRITE:/ wa_return-message.
ENDLOOP.

Similar Messages

  • A bapi problem of create sales order

    hello,experts,
    when I want to try the function of bapi 'BAPI_SALESORDER_CREATEFROMDAT1', the return message is the following,
    'Material 4070111 is not defined for sales org.4050,  distr.chan.01,  language ZH',actually,the sales org.4050 is defined for the material.
    pls help me out.appreciated.
    the content of the program:
    REPORT  ZWY_SALESORDER01.
    --Data Declaration--
    Data: st_BAPISDHEAD like BAPISDHEAD, " Sales Order Header Data
    ta_BAPIITEMIN like BAPIITEMIN occurs 0 with header line, " Ln item
    ta_BAPIPARTNR like BAPIPARTNR occurs 0 with header line, " Partner
    d_BAPIRETURN1 like BAPIRETURN1, " Bapi return msg
    d_vbeln like bapivbeln-VBELN. " Sales Order Number
    *Please note in the following program, sold to party (SP) has been
    *entered as 'AG' and ship to party (SH) as 'RG'.
    *SP----
    AG
    *SH----
    RG
    *Order type 'OR' as 'TA'
    *Please use TA instead of OR
    *Also if you set the * CONVERT_PARVW_AUART = 'X' parameter to 'X' you
    *can use sold to party as SP and ship to party as SH.
    Move the data to create sales order in the repective parameters------*
    move: '4OR' to st_BAPISDHEAD-DOC_TYPE, " Sales document type
    '15493' to st_BAPISDHEAD-PURCH_NO_C,
    '4050' to st_BAPISDHEAD-SALES_ORG,
    '01' to st_BAPISDHEAD-DISTR_CHAN,
    '00' to  st_BAPISDHEAD-DIVISION,
    '00010' to ta_BAPIITEMIN-ITM_NUMBER,
    '4070111' to ta_BAPIITEMIN-MATERIAL,
    '4000' to ta_BAPIITEMIN-PLANT,
    '1' to ta_BAPIITEMIN-REQ_QTY,
    'AG' to ta_BAPIPARTNR-PARTN_ROLE, " Sold to Party
    '0000006648' to ta_BAPIPARTNR-PARTN_NUMB.
    Append the internal tables-------------------------------------------*
    append ta_BAPIPARTNR.
    clear ta_BAPIPARTNR.
    append ta_BAPIITEMIN.
    clear ta_BAPIITEMIN.
    Move ship to party---------------------------------------------------*
    move: 'RG' to ta_BAPIPARTNR-PARTN_ROLE, " Ship to party
    '0000006648' to ta_BAPIPARTNR-PARTN_NUMB.
    Append the internal tables-------------------------------------------*
    append ta_BAPIPARTNR.
    clear ta_BAPIPARTNR.
    break-point.
    Call the Bapi to create the sales order
    CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
    EXPORTING
    ORDER_HEADER_IN = st_BAPISDHEAD
    WITHOUT_COMMIT = ' '
    CONVERT_PARVW_AUART = ' '
    IMPORTING
    SALESDOCUMENT = d_vbeln
    SOLD_TO_PARTY =
    SHIP_TO_PARTY =
    BILLING_PARTY =
    RETURN = d_BAPIRETURN1
    TABLES
    ORDER_ITEMS_IN = ta_BAPIITEMIN
    ORDER_PARTNERS = ta_BAPIPARTNR
    ORDER_ITEMS_OUT =
    ORDER_CFGS_REF =
    ORDER_CFGS_INST =
    ORDER_CFGS_PART_OF =
    ORDER_CFGS_VALUE =
    ORDER_CCARD =
    ORDER_CFGS_BLOB =
    ORDER_SCHEDULE_EX =
    break-point.
    if d_vbeln <> space.
    write: 'Sales order No. ', d_vbeln.
    endif.

    clear iohead.
      ihead-doc_type   = 'ordertype'.
      ihead-sales_org  = 'sales organisation'.
      ihead-distr_chan = 'distribution ch'.
      ihead-division   = 'division'.
      ihead-req_date_h = sy-datum.
      ihead-ship_cond  = 'shipping codition'.
      ihead-incoterms1 = 'incoterms'.
      ihead-pmnttrms   = 'payment terms'.
      ihead-purch_no_c = 'Purchase document'.
      ihead-purch_date = 'purchase doc date.
      ihead-accnt_asgn = 'account assignment'.
      ihead-pymt_meth = 'payment method'.
      clear ipartner.   refresh ipartner.
      ipartner-partn_role = 'AG'.
      ipartner-partn_numb = 'sold to party'.
      append ipartner.
      clear ipartner.
      ipartner-partn_role = 'WE'.
      ipartner-partn_numb = 'ship to party'.
      append ipartner.
      refresh : iitem, ibapischdl, ibapicond.
      clear   : iitem, ibapischdl, ibapicond.
      item-itm_number = '10'.
      item-material   = 'material'.
      item-plant      = 'plant'.
      item-val_type   = 'BLFG'.
      append item.
      ibapischdl-itm_number = '10'.
      ibapischdl-req_date   = sy-datum.
      ibapischdl-req_qty    = 'quantity'.
      append ibapischdl.
      call function 'BAPI_SALESORDER_CREATEFROMDAT2'
           exporting
              SALESDOCUMENT           =
                order_header_in         = ihead
              ORDER_HEADER_INX        =
              SENDER                  =
              BINARY_RELATIONSHIPTYPE =
              INT_NUMBER_ASSIGNMENT   =
              BEHAVE_WHEN_ERROR       =
              LOGIC_SWITCH            =
              TESTRUN                 =
              CONVERT_PARVW_AUART     = ' '
          importing
               salesdocument_ex        = wvbeln
           tables
               return                  = ibapiret2
               order_items_in          = item
              ORDER_ITEMS_INX         = IBAPISDITMX
               order_partners          = ipartner
               order_schedules_in      = ibapischdl
              ORDER_SCHEDULES_INX     =  ibapischdl
              order_conditions_in     = ibapicond
              ORDER_CFGS_REF          =
              ORDER_CFGS_INST         =
              ORDER_CFGS_PART_OF      =
              ORDER_CFGS_VALUE        =
              ORDER_CFGS_BLOB         =
              ORDER_CFGS_VK           =
              ORDER_CFGS_REFINST      =
              ORDER_CCARD             =
              ORDER_TEXT              =
              ORDER_KEYS              =
              EXTENSIONIN             =
              PARTNERADDRESSES        =
      if wvbeln ne space.
        call function 'BAPI_TRANSACTION_COMMIT'
             exporting
                  wait = wwait.
           IMPORTING
                RETURN  =
    sales document will be available in bapi return .
    saravanan

  • Returns on sales orders regarding contracts

    Hi Guys,
    I have a problem with returns on sales orders.
    We get returns on sales orders - like most companies.
    If the sales order has a parent order of the type contract / quantity agreement,
    the return is increasing the open quantity of the contract.
    Is there any possibility to prevent this behaviour in standard SAP,
    without a modification?
    Thanks - for any tip !!

    Hello Manuel,
    My understanding of ur situation:
    U have a qty contract, say for 100 items and have sold 25 items. The contract is updated and shows open qty as 75 items.
    After the sale, the customer has returned the 25 items and the contract is updated back as 100 items.
    And, you do not want this standard behavior of SAP to take place?
    In this case, go to the copy control of the item category and uncheck the update document flow indicator.
    However, plz note that if the update doc flow is not set the customer can order as much as he would like to, without the qty contract being updated. Niether would you be able to see the document flow.
    I hope this helps, plz get back for further clarifications.
    Rgds,
    Raghu.

  • Sales Order RMA Line Closed

    Hi All,
    I have a sales order RMA created once a line is received WF changeing its status in Closed.
    I need to still have the possibility to update DFF for closed line, does anybody knows how to setup process constraints to allow DFF updated when an OM lines is closed ?
    Thanks

    Thanks for the suggestion.
    Unfortunately these DFF are defined at the line level and the values there is different for each line so it's not possible to setup the same at the header level.
    There is some way to link DFF lines value to the SO Header WF status ?
    Thanks

  • Is there any FM or BAPI to delete the sales orders

    Hi,
    Is there any FM or BAPI to delete the sales orders
    Thanks,
    srinivas.

    BAPI_SALESORDER_CHANGE
    [Link|http://sap.ittoolbox.com/groups/technical-functional/sap-dev/bapi_salesorder_change-delete-sales-order-ver-470-1081398]

  • Customer return the sales order

    Hi,
    When any sales document processed and customer received the goods. But after it, if he returns the goods, then which table will be effected.
    Note: - If he return whole sales order or any material.
    Thanks

    Hi,
    it will be in restricted stock field.
    Edited by: amol khairnar on Nov 13, 2009 5:04 PM

  • Function module or BAPI to get the sales order details.

    Hi,
    Can any one revert back with the FM or BAPI to get the sales order details.
    I tried using BS01_SALESORDER_GETDETAIL, in my driver program of smartform but when i execute the form using VA03 -> Sales Document -> Issue output to -> Print preview, I am getting the required output.
    if i see the print preview in the overview of the sales order (enter sales order and press enter), the above specified FM is not populating any data.
    Thanks,
    Prathap

    Hi Prathap,
    The above specified FM BAPISDORDER_GETDETAILEDLIST should work. As you need the item conditions,
    Fill the I_BAPI_VIEW with header = 'X', item = 'X' and sdcond = 'X'.
    Fill the SALES_DOCUMENTS-vbeln = sales order number.
    Regards,
    Shylaja

  • R12, Sales Order RMA with line status "Awaiting Return"

    Hi guys
    Following the tips, I successfully managed to create RMA for entire SO. Now the SO lines are with the status "Awaiting Return". How I can update the inventory with the RMA quantities and close the order?
    Is there any particular concurrent program or API available to do this job?
    Thanks and regards,

    Hi Sandeep
    Thanks again. Actually I wanted to automate the entire " inventory > transactions > receipts > returns > customer tab > enter RMA order # and proceed" process by the means of using a proper API or concurrent program.
    As I was not getting satisfactory answers, I approached Oracle and they confirmed there are no public API available to establish this requirement. However they provided a workaround solution which points towards inserting records manually into receipts interface.
    Twice your suggestions truly helped me out to address immediate requirements and thanks again.
    Regards

  • Hi ,BAPI Needed to create sales order

    Hi,
    i want to create  a salesorder by giving quotation number as an input.
    whenever sales quotation is saved it should check for some conditions and finally it should automatically create the sales order of type ZMS without user intervention.
    Please can any one help in finding the BAPI .Please explain me how to implement same...
    regards
    manju

    Check the Program -
    REPORT ZCREATE_SO.
    DATA : ORDER_HEADER_IN1 TYPE BAPISDHD1.
    DATA: ORDER_PARTNERS1 TYPE BAPIPARNR OCCURS 0 WITH HEADER LINE.
    DATA: ORDER_ITEMS_IN1 TYPE BAPISDITM OCCURS 0 WITH HEADER LINE.
    DATA : SALESDOCUMENT1 TYPE BAPIVBELN-VBELN.
    DATA : RETURN1 TYPE BAPIRET2 OCCURS 0.
    DATA : RETURN2 TYPE BAPIRET2.
    DATA: WA_RETURN1 TYPE BAPIRET2.
    start-of-selection.
    Fill the Header Details
    order_header_IN1-DOC_TYPE = 'TA'.
    order_header_IN1-SALES_ORG = '1001'.
    order_header_IN1-DISTR_CHAN = '10'.
    order_header_IN1-division = '10'.
    Fill the Partner Details
    ORDER_PARTNERS1-PARTN_ROLE = 'WE'.
    ORDER_PARTNERS1-PARTN_NUMB = '0000000008'.
    append ORDER_PARTNERS1.
    Fill the Item details
    ORDER_ITEMS_IN1-MATERIAL = 'A0900002'.
    ORDER_ITEMS_IN1-TARGET_QTY = '10'.
    append ORDER_ITEMS_IN1.
    CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
    EXPORTING
    SALESDOCUMENTIN =
    ORDER_HEADER_IN = order_header_IN1
    ORDER_HEADER_INX =
    SENDER =
    BINARY_RELATIONSHIPTYPE =
    INT_NUMBER_ASSIGNMENT =
    BEHAVE_WHEN_ERROR =
    LOGIC_SWITCH =
    TESTRUN =
    CONVERT = ' '
    IMPORTING
    SALESDOCUMENT =
    TABLES
    RETURN = RETURN1
    ORDER_ITEMS_IN = ORDER_ITEMS_IN1
    ORDER_ITEMS_INX =
    ORDER_PARTNERS = ORDER_PARTNERS1
    ORDER_SCHEDULES_IN =
    ORDER_SCHEDULES_INX =
    ORDER_CONDITIONS_IN =
    ORDER_CONDITIONS_INX =
    ORDER_CFGS_REF =
    ORDER_CFGS_INST =
    ORDER_CFGS_PART_OF =
    ORDER_CFGS_VALUE =
    ORDER_CFGS_BLOB =
    ORDER_CFGS_VK =
    ORDER_CFGS_REFINST =
    ORDER_CCARD =
    ORDER_TEXT =
    ORDER_KEYS =
    EXTENSIONIN =
    PARTNERADDRESSES =
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
    WAIT = space
    IMPORTING
    RETURN = return2
    loop at return1 into wa_return1.
    endloop.
    Also go through the Documentation in SE37 it is very helpful.

  • BAPI to get the Sales order line item details

    Hi,
    My program gets Sale sorder and item as the input and I need to fetch all the item (Given item) details for this Sales Order from VBAP. Is there any BAPI to get the item details?

    Hi,
    This is a sample code of BAPI.Try to map it to your requirement.This is not related to vendor.This is related to sales 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 vbakgueen vbkdprsdt
    INTO (l_gueen, l_prsdt)
    FROM vbak
    INNER JOIN vbkd
    ON vbakvbeln = vbkdvbeln
    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
    Regards
    Rajesh Kumar

  • BAPI does not create Sales order

    Hi All,
    I am using BAPI_SALESORDER_CREATEFROMDAT2 to create sales order.
    It is working fine till now.
    But I found that whenever there is a material whose condition price is maintained and doesnot match with the valuation type, the Sales order does not get created, neither it gives any error msg.
    For e.g For Valuation type Consign , condition type ZPCS is valid and similarly for Turnkey , condition type ZPTK is valid.
    if a material has valuation type consign and condition type ZPTK.. The SAP system ofcourse will not allow to create a SO unless we delete the ZPTK entry from the SO and create ZPCS...
    BAPI also doesnot create the SO but doesnot return the error messge too.
    I try to put the ZPCS value to BAPI thru BAPICOND..but still not working?
    How do i handle such case?
    Points will be awarded to useful ans

    Hi,
    If you are saying that you cannot create a sales order with the Valuation type and Condition type mismatch even through VA01 manually, then there is nothing much you can do in BAPI also.
    2nd Case is you say that that BAPI RETURN table is not getting populated and it is empty in this issue which is not letting you know that Sales order is not Created.
    The one work around for this issue is you can check the exporting parameter SALESDOCUMENT if it has the Sales Order number or not. if the RETURN table is empty and the SALESDOCUMENT field has SO Number, then SO is created and if RETURN table is Initial and SALESDOCUMENT is also Initial, then it is the issue that you are facing.
    Also try posting a Query in OSS.
    regards,
    Mahesh

  • How to pass delivery date through BAPI while creating a sale order

    Dear frndz,
         I am using 'BAPI_SALESORDER_CREATEFROMDAT1'
    to create a sale order .
        I don't have any problem..
        But I have to pass schedule line delivery date through this bapi .
       I used REQ_DATE in structure BAPISCHDL.
       But I can' t get it.
       Through which parameter can i meet this..
       The sale order should be created line item wise along with my delivery date..
      Any suggestions...
    regards.
    siva

    Dear frnd,
        Danq for your response..I can't use DLV_DATE for this requirement..
        But I used REQ_DATE in the structure BAPISCHEDULE .
       I came to know that the problem i faced previously  was only
    internal data conversion.
        Now am able to pass my delivery date..
        so I am closing the thread..
    Regards.
    siva

  • BAPI For PGI against sales order

    Dear all,
                 I want BAPI for PGI(Post Goods Issue) against sales order.Can anybody suggest BAPI for this?

    Hi,
    Please check the link given below:
    bapi for PGI
    Hope it will help you.
    Thanks & Regards,
    Sarita singh Rathour

  • BAPI / Function Module for Sale order updation

    Hi,
         I need to update sale order details(Reason for rejection)..Can you please tell me any of the existing BAPI's / Function modules to do the same.

    hi,
      try bapi_salesorder_change
        <b>allocate points if useful</b>
    regards,
    pavan

  • Returns to sales order

    Hello Sap gurus,
    Actualy our transaction goes from sales order to returns ie, ZSP- ZRE. now we have a reuirement we have to do the reverse process that is from ZRE- ZSP. How to do it
    Points will be rewarded
    Thanks
    Edie

    Dear friend ,
    I f I understood you correctly.
    You want to create a sales order after the return order has been taken place.
    From RE -->OR suppose..
    Then you need to maintain copy control functions for
    Order to Order.
    The rest process from Order to delivery and billing is predefined...
    Correct me if I am wrong,,,
    edited by..,
    Amlan Sarkar

Maybe you are looking for