Reversing Goods Receipt and its corresponding Goods Issue for a Stock Transport Order
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
The requirement is to reverse firstly the Goods Receipt and then Goods Issue and finally delete the Outbound Delivery.
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!
- 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.
- Call the function module ‘RFC_CONNECTION_CLOSE’ to close the connection which is called in above step.
- 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.
- 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.