Register Login

Deleting Sales Orders Via BAPI BAPI_SALESORDER_CHANGE

Updated May 18, 2018

We have a requirement to delete a sales order using the BAPI_SALESORDER_CHANGE Bapi. We can delete/reject individual line items using this FM but the calling service does not know how many lines are on the order so we need to delete/reject the order at the header level.

The documentation says to just put D in the UPDATEFLAG in the ORDER_HEADER_INX in the ORDER_HEADER_INX import parameter table. When we do this we get a success message but the order remains unchanged.

We used the BAPI_TRANSACTION_COMMIT bapi to complete the transaction but no success.


Comments

  • 26 Oct 2016 2:05 pm Guest Best Answer

    First, please set D as the value of flag for updating.

    1) Use this in order to delete the Sales Order

    SALESDOCUMENT = <doc. number>.

    ORDER_HEADER_INX-UPDATEFLAG = 'D'.

    2) Please run the program below to delete an item of Sales Order

    SALESDOCUMENT = <doc. number>.

    ORDER_ITEM_IN-ITM_NUMBER = <item number>.

    ORDER_ITEM_INX-ITM_NUMBER = <item number>.

    ORDER_ITEM_INX-UPDATEFLAG = 'D'.

    Max

  • 30 Jul 2013 12:25 pm Sushma

    Below are the possible causes for the line not being deleted:

    1. BAPI fields are populated incorrectly
    2. A subsequent document (e.g. an outbound delivery) exists for the lineitem. Such line items can not be deleted.

    Please try this sample test code given below copied from another link.

    PARAMETERS: p_vbeln TYPE vbeln,
    p_posnr TYPE posnr.

    DATA: s_order_header_in LIKE bapisdh1.
    DATA: s_order_header_inx LIKE bapisdh1x.

    DATA: BEGIN OF i_order_item_in OCCURS 0.
    INCLUDE STRUCTURE bapisditm.
    DATA: END OF i_order_item_in.
    DATA: BEGIN OF i_order_item_inx OCCURS 0.
    INCLUDE STRUCTURE bapisditmx.
    DATA: END OF i_order_item_inx.
    DATA: BEGIN OF it_return OCCURS 0.
    INCLUDE STRUCTURE bapiret2.
    DATA: END OF it_return.

    * Header update indicator
    s_order_header_inx-updateflag = 'U'.

    * Line items
    i_order_item_in-itm_number = p_posnr.
    i_order_item_inx-updateflag = 'D'.
    i_order_item_inx-itm_number = p_posnr.
    APPEND: i_order_item_in, i_order_item_inx.

    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
    EXPORTING
    salesdocument = p_vbeln
    order_header_in = s_order_header_in
    order_header_inx = s_order_header_inx
    behave_when_error = 'P'
    TABLES
    return = it_return
    order_item_in = i_order_item_in
    order_item_inx = i_order_item_inx.

    LOOP AT it_return.
    MESSAGE
    ID it_return-id
    TYPE 'I'
    NUMBER it_return-number
    WITH
    it_return-message_v1
    it_return-message_v2
    it_return-message_v3
    it_return-message_v4.
    ENDLOOP.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
    wait = 'X'.

    Thanks.


×