Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BAPI_GOODSMVT_CREATE

Former Member
0 Likes
1,720

Hi Everyone-

My requirement is to automatically do a 261 and 262 movement from my program. The way I am achieving this is by using the SAP BAPI "BAPI_GOODSMVT_CREATE". I have to post both these movements only if both are successful. So I am executing the BAPI for the 261 first without the COMMIT and then for the 262 without the COMMIT. I am storing the returns I get from both these BAPI's and only if there is no error message in the return I am executing both these BAPI's again with the COMMIT statement. This approach worked for non-serialized materials but when I try to do it for a serialized material I am getting an error "Stock data of serial number XXX not suitable for movement" on my second attempt of the BAPI. Is there some kind of refresh I need to perform after my first call?

Below is the flow of my code:

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'     "with the 261 movement.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'     "with the 262 movement.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

if gt_return IS INITIAL.


      CALL FUNCTION 'BAPI_GOODSMVT_CREATE'     "with the 261 movement.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

      CALL FUNCTION 'BAPI_GOODSMVT_CREATE'     "with the 262 movement.
     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.


ENDIF.


2 REPLIES 2
Read only

NAeda
Contributor
0 Likes
1,085

Hi,

Use the Destination 'NONE' Statement and also use RFC_CONNECTION_CLOSE.

Find the below code :

if gt_return IS INITIAL.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'  DESTINATION 'NONE'. "with the 261 movement.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' DESTINATION 'NONE'.

* Close RFC connection

   CALL FUNCTION 'RFC_CONNECTION_CLOSE'

     EXPORTING

       destination = 'NONE'.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'    DESTINATION 'NONE'. "with the 262 movement.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' DESTINATION 'NONE'..

* Close RFC connection

   CALL FUNCTION 'RFC_CONNECTION_CLOSE'

     EXPORTING

       destination = 'NONE'.

ENDIF.

Message was edited by: Aeda N

Read only

former_member188827
Active Contributor
0 Likes
1,085

First try to post data manually using MIGO with same data that you are using in your program to ensure that this error is not due to incorrect data or some customizing setting. Then,please make sure to clear the structures and internal tables first and then populating them again before each bapi call, specially check the TABLES parameter: i_gm_serialnumber.

Following link might be helpful to you:

http://scn.sap.com/thread/3269123

http://scn.sap.com/thread/57228

Regards