Enterprise Resource Planning Blogs by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
cancel
Showing results for 
Search instead for 
Did you mean: 
thyagab
Product and Topic Expert
Product and Topic Expert
3,833
Requirement:

Recently, I came across a requirement from one of the customers to reverse the goods movements and delete the Outbound delivery created for a Stock Transport Order in a single execution via a custom program.

Below is the document flow for Stock Transport Order which is in discussion.

--> Stock Transport Order 

       -->Outbound Delivery 

       -->Goods Issue 

       -->Goods Receipt

The requirement is to reverse firstly the Goods Receipt and then Goods Issue and finally delete the Outbound Delivery.

Problem faced:

BAPI 'BAPI_GOODSMVT_CANCEL' is available to reverse Goods receipt and Function Module 'WS_REVERSE_GOODS_ISSUE' is available to reverse Goods Issue. The problem in standard is some of the data objects are not cleared at the end of BAPI call to reverse the Goods receipt. Later, when the function module to reverse GI is called, some of the include programs which are already called during the BAPI execution is also being accessed, causing the issue.

Since, the data objects are not cleared in the previous BAPI call context, FM to reverse Goods Issue fails miserably!

Solution:

  1. Wrap the BAPI to reverse GR in a custom Remote Function Module and call as Synchronous RFC and destination being 'NONE'. Perform 'COMMIT' or 'ROLL BACK' inside the RFC based on the success/failure of BAPI.

  2. Call the function module 'RFC_CONNECTION_CLOSE' to close the connection which is called in above step.

  3. Wrap the FM to reverse GI in another Remote Function Module and call as Synchronous RFC and destination being 'NONE'. Perform 'COMMIT' or 'ROLL BACK' inside the RFC based on the success/failure of FM.


Solution Snapshot:

  • The solution aims to call the BAPI and FM in a separate context through separate Synchronous RFC's. This will avoid processing both the calls in a single context.

  • Both the RFC's will be called in their own RFC context.

  • COMMIT or ROLL BACK must be called inside the respective RFC's. This will help to finish the respective LUW's.

  • Closing the RFC connection between the RFC calls is important here otherwise you would be facing the same kind issue.

3 Comments