Home > ABAP, API > BAPI_SALESORDER_CHANGE to change configuration data

BAPI_SALESORDER_CHANGE to change configuration data

September 12th, 2009 Leave a comment Go to comments

BAPI BAPI_SALESORDER_CHANGE can be used to change or delete sales orders. You can change header, item, schedule line and configuration data.

In general, You must enter the order number in the SALESDOCUMENT structure.You must always enter key fields for changes. You must always specify the update indicator in the ORDER_HEADER_INX.

The BAPI does not run a database Commit, which means that the application must trigger the Commit so that the changes are read to the database. To do this, use the BAPI_TRANSACTION_COMMIT BAPI.

This BAPI is very easy to use, but it is a little bit tricky when updating the material configuration data. I will record what I have done to explain how to change the configuration data.

Step 1. Use BAPI BAPISDORDER_GETDETAILEDLIST to get the sales document detail information.

  lv_bapi_view-item   = 'X'.
  lv_bapi_view-sdcond = 'X'.
  lv_bapi_view-configure = 'X'.
 
  CLEAR lt_sales_doc.
  ls_sales_doc-vbeln = gs_output-vbeln.
  APPEND ls_sales_doc TO lt_sales_doc.
 
  CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
    EXPORTING
      i_bapi_view                   = lv_bapi_view
    TABLES
      sales_documents               = lt_sales_doc
      order_items_out               = lt_items
      order_conditions_out          = lt_condition
      order_cfgs_curefs_out         = lt_cfgs_curefs
      order_cfgs_cucfgs_out         = lt_cfgs_cucfgs
      order_cfgs_cuins_out          = lt_cfgs_cuins
      order_cfgs_cuvals_out         = lt_cfgs_cuvals.

Step 2. Make the changes on the characteristic you want to change and also append the unchanged characteristic to final structure. Because We need to provide a complete configuration to the BAPI in order to make changes.

We also need to build item structure of the BAPI. The tricky thing is that even if we do not need to change the PO_ITM_NO in the item level, we still need to set it to ‘X’. Otherwise, it will not be able to work in certain condition. Please refer below code for detail information.

  ls_item_in-itm_number = ls_items-itm_number.
  ls_item_in-hg_lv_item = ls_items-hg_lv_item.
  ls_item_in-po_itm_no = ls_items-itm_number.
  ls_item_in-material = ls_items-material.
  APPEND ls_item_in TO lt_item_in.
 
  ls_item_inx-itm_number = ls_item_in-itm_number.
  ls_item_inx-updateflag = 'U'.
  ls_item_inx-po_itm_no = 'X'.
  ls_item_inx-config_id = 'X'.
  ls_item_inx-inst_id = 'X'.
  APPEND ls_item_inx TO lt_item_inx.

Step 3. Finally, we need to call BAPI BAPI_SALESORDER_CHANGE to update the sales order.

* call BAPI 'BAPI_SALESORDER_CHANGE' to modify the configuration data and the condition record
  CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
    EXPORTING
      salesdocument               = ls_sales_doc-vbeln
      order_header_inx            = ls_header_inx
    TABLES
      return                      = lt_return
      order_item_in               = lt_item_in
      order_item_inx              = lt_item_inx
      order_cfgs_ref              = lt_cfgs_ref
      order_cfgs_inst             = lt_cfgs_inst
      order_cfgs_value            = lt_cfgs_value
      conditions_in               = lt_cond_in
      conditions_inx              = lt_cond_inx.
 
* Database update
  COMMIT WORK AND WAIT.

SAP Note number 562124 – Configuration change via BAPI also provide an detail code sample for this purpose.

  1. No comments yet.
  1. No trackbacks yet.