SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow

ABAP bapi_salesorder_change to Delete Sales Order in SAP


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





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

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



SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.