ABAP bapi_salesorder_change to Delete Sales Order in SAP (2024)


I used ABAP BAPI bapi_salesorder_change to delete sales order in SAP system recently.
During ABAP development for migration of sales orders from an older SAP system to a newer SAP system, I had to delete sales orders I created for test purposes.
I chosed to use the ABAP BAPI bapi_salesorder_change to delete sales orders in SD (Sales and Distribution) since it is very easy to use.

I created an ABAP report which takes a range of VBELN (sales order document number) which defines the list of SAP sales orders created during migration tests.
The below SAP screenshot displays the SAP GUI selection screen of the sample ABAP program.

ABAP bapi_salesorder_change to Delete Sales Order in SAP (1)

REPORT Z_ORDERS_DEL_TEST .

SELECTION-SCREEN BEGIN OF BLOCK block-1 WITH FRAME TITLE text-001.
PARAMETERS : p_vbeln1 TYPE vbeln.
PARAMETERS : p_vbeln2 TYPE vbeln.
SELECTION-SCREEN END OF BLOCK block-1.

START-OF-SELECTION.

PERFORM u_delOrders.

FORM U_DELORDERS .

data : lv_vbeln TYPE vbeln.
data : ls_vbak TYPE vbak, lt_vbak TYPE TABLE OF vbak.

lv_vbeln = p_vbeln1.

WHILE lv_vbeln <= p_vbeln2.
PERFORM u_deleteorders USING lv_vbeln.
lv_vbeln = lv_vbeln + 1.
ENDWHILE.

ENDFORM.

FORM u_deleteorders USING lv_vbeln TYPE vbeln .

DATA :
f_headinx LIKE bapisdh1x,
t_ret type TABLE OF BAPIRET2.

CLEAR f_headinx.
f_headinx-updateflag = 'D'.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = lv_vbeln
order_header_inx = f_headinx
TABLES
return = t_ret.

COMMIT WORK.

ENDFORM.

Note that the BAPI_SALESORDER_CHANGE pattern requires salesdocument and order_header_inx parameters to be set for a successfull call.
To delete an SAP Sales Order, call bapi_salesorder_change function module with sales order number (VBELN) as the salesdocument parameter and set order_header_inx-updateflag to 'D' (indicates DELETE action).

ABAP bapi_salesorder_change to Delete Sales Order in SAP (2024)
Top Articles
Latest Posts
Article information

Author: Laurine Ryan

Last Updated:

Views: 6122

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Laurine Ryan

Birthday: 1994-12-23

Address: Suite 751 871 Lissette Throughway, West Kittie, NH 41603

Phone: +2366831109631

Job: Sales Producer

Hobby: Creative writing, Motor sports, Do it yourself, Skateboarding, Coffee roasting, Calligraphy, Stand-up comedy

Introduction: My name is Laurine Ryan, I am a adorable, fair, graceful, spotless, gorgeous, homely, cooperative person who loves writing and wants to share my knowledge and understanding with you.