Skip to Content
Technical Articles

Reversing Goods Receipt and its corresponding Goods Issue for a Stock Transport Order

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.
2 Comments
You must be Logged on to comment or reply to a post.
  • Sorry, I’m confused…

    You are saying “data objects not cleared” in BAPI call. If this is true (I could not find any SAP Note to that effect), then why this hasn’t been brought to the attention of SAP Support?

    BAPI should be running in it’s own LUW without any RFC and there should be COMMIT done after that. There seems to be confusion about LUW and RFC session (they are not the same). RFC call you’re describing is about a synchronous vs. asynchronous update. Not sure how this could relate to any variables not being cleared (even assuming shared memory is used). I’m guessing this would solve the issue if FM was starting too fast, before BAPI COMMIT was completed but that’s not what the blog says.

    Not sure if I missed something but the whole story doesn’t quite add up. Might want to clarify.

    P.S. Edit: just noticed “BAPI and FM are called in a same LUW” – why? That doesn’t make sense… Now I’m even more confused.

     

    • Hi Jelena Perfiljeva

      Read that BAPI and FM are calling in same context. hence, the FM was failing.

      The workaround is to call BAPI and FM as separate sync. RFC call. This enables the FM to be called in its own context. hence, the uncleared data objects of BAPI doesnt pose any probblem to FM.

      FM was able to clear the GI document.

      Have informed this to SAP support.  

      Regards,

      Thiyagarajan