Application Development 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: 

Problem with BAPI_SALESORDER_CHANGE

former_member239066
Participant
0 Kudos

Hi Experts,

I am facing a problem with the BAPI_SALESORDER_CHANGE. I am using it in a user exit to update sales order upon creation of delivery and I am getting the error message' Enter a document number'. The problem is that I have passed the document number to the BAPI. When I use the BAPI in SE37 with the same parameters, there is no error message.

I have debugged to check where the eroor message is coming from. It is from the subroutine BELEG_LESEN of the program MV45AF0B_BELEG_LESEN (line 36):

if vbak-vbeln is initial.

message e045.

endif.

This routine is called in the FM SD_SALES_DOCUMENT_READ (line 61) just after the statement VBAK-VBELN = DOCUMENT_NUMBER.

I have also debugged both calls and found a difference as follows:

1. In SE37, when the statement VBAK-VBELN = DOCUMENT_NUMBER is executed, both (SAPLV45A)VBAK-VBELN and (SAPMV45A)VBAK-VBELN are assigned the order number.

2. When i debug the call in the user exit, only the (SAPLV45A)VBAK-VBELN is assigned the order number and (SAPMV45A)VBAK-VBELN remains initial and that is why i am getting the error message.

Can anybody please tell me why the (SAPMV45A)VBAK-VBELN is not assigned the order number same as when I test in SE37?

Is there any solution for this problem?

Thanks,

Vitz.

5 REPLIES 5

former_member226234
Contributor
0 Kudos

Hi,

As you said, it works in Se37, but fails in the userexit. I would suggest to check the import paramaters and tables data you are passing to the BAPI in the user exit. There should be some data field missed to populate. Ask a reviewer (different pair of eyes) to check the code.

Regards,

Sandeep

Jelena
Active Contributor
0 Kudos

It is not feasible to update the sales order at the same time as updating the delivery. The delivery locks the sales order as a preceding document (becaus it needs to update the statuses and stuff) and no updates may be carried forward. Even if there was no error, you wouldn't be able to update anything. This has been discussed in the forums before - use search.

One of the known ways to work around this is to use the delivery output and a link it to a program. The output is generated after the updates, so the lock has been released by then.

0 Kudos

Hi Jelena,

It is possible to do the update at the same time. The solution is to create a function module to do the update and call that function module using the addition STARTING NEW TASK. Call the BAPI BAPI_SALESORDER_CHANGE in the function module created and the sales order will be updated at the same time the delivery is created / updated.

Cheers,

Vitz.

Jelena
Active Contributor
0 Kudos

And where exactly would you put this function module? Keep in mind that STARTING NEW TASK will create a new LUW, so you might end up with the sales order updated and delivery update failed.

0 Kudos

Hi Jelena,

No, iit does not fail. the update on the sales order is committed and the delivery updated/created perfectly. I have called the function module in the user exit userexit_save_document_prepare of the program MV50AFZ1.

Cheers,

Vitz.