cancel
Showing results for 
Search instead for 
Did you mean: 

MV45AFZA

Former Member
0 Kudos

Hi all.

I have this problem... after some validation, some positions of the sales order must be either deleted or blocked. I'm trying to do this in user exit SAVE_DOCUMENT_REFRESH, in include MV45AFZA using the BAPI BAPI_SALESORDER_CHANGE. If i run the BAPI in se37, it makes all the modifications correctly, but when i run it in the user exit, it returns error V1 045 'Enter the document number'. The data passed to the BAPI is exactly the same in both cases, i even try putting a break point in the user exit, and on that moment ran the BAPI in se37, and it work out correctly. Did anyone ever had this problem?

I'm on SAP ECC 5.0

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Are you in create mode(VA01) or change mode (VA02)?.

In most of the internal tables within SAPMV45A there is a field called UPDKZ that is used to control what happens to the record. This is espicially important in change mode. This field has to be set to:

'D' - Delete

'U' - Update

'I' - Insert.

It is also important with the user exits to manage both the X and Y internal tables. For example YVBAP should contain the data before the change and XVBAP should contain the record with the updated data.

Also, if you are trying to delete an item, you probably need to make sure that all of the data for that item is deleted - vbap, vbep, vbpa, etc.

Chris

Former Member
0 Kudos

Thanx a lot!! your answers have been very usefull.

Former Member
0 Kudos

Hi Chris. I've tried using the xvbap internal table and it worked out fine when i need to create a new record in vbep table, but when i want to delete an item in the sales order, i put a 'D' to the field xvbap-updkz, but it doesn't delete it. Is there any other field i should consider?

I'm usin USEREXIT_SAVE_DOCUMENT_PREPARE in MV45AFZZ.

Thanx!

Former Member
0 Kudos

Jesus,

Are you creating or changing a document when you are trying to do this? Did you ensure that you are updating both the XVBAP and YVBAP internal tables?

Other than that I am not sure. I have never had to delete an item before.

Can you post your code in the message?

Chris

Former Member
0 Kudos

I'm trying to do this while changing the order. This is the code in my user exit....

FORM userexit_save_document_prepare.

......

VALIDATION AND SELECT POSITION

......

xvbap-updkz = 'D'.

MODIFY xvbap INDEX sy-tabix.

LOOP AT xvbep WHERE posnr EQ xvbap-posnr.

xvbep-updkz = 'D'.

MODIFY xvbep INDEX sy-tabix.

ENDLOOP.

ENDFORM. "USEREXIT_SAVE_DOCUMENT_PREPARE

*eject

Former Member
0 Kudos

Jesus,

I have added some code to what you sent. The key to the below code is you need to append the Y tables before making modifications to the X tables.

One other thing. If this doesn't work try updating the YVBAP/YVBEP-UPDKZ field with 'D'. I forget if for deleting you need this in both tables or not.

  • INSERT THIS CODE

read table yvbap with key posnr = XVBAP-POSNR.

if sy-subrc ne = 0.

append xvbap to yvbap.

endif.

xvbap-updkz = 'D'.

MODIFY xvbap INDEX sy-tabix.

LOOP AT xvbep WHERE posnr EQ xvbap-posnr.

  • INSERT THIS CODE

read table yvbep with key posnr = xvbep-posnr

etenr = xvbap-posnr.

if sy-subrc ne 0.

append xvbep to yvbep.

endif.

xvbep-updkz = 'D'.

MODIFY xvbep INDEX sy-tabix.

ENDLOOP.

Chris

Former Member
0 Kudos

Hey Chris, thanx a lot! this is how i solved it...

xvbap-updkz = 'D'.

MODIFY xvbap INDEX sy-tabix.

READ TABLE yvbap WITH KEY posnr = xvbap-posnr.

IF sy-subrc EQ 0.

yvbap-updkz = 'D'.

MODIFY yvbap INDEX sy-tabix.

ENDIF.

LOOP AT xvbep WHERE posnr EQ xvbap-posnr.

xvbep-updkz = 'D'.

MODIFY xvbep INDEX sy-tabix.

ENDLOOP.

LOOP AT yvbep WHERE posnr EQ xvbap-posnr.

yvbep-updkz = 'D'.

MODIFY yvbep INDEX sy-tabix.

ENDLOOP.

Former Member
0 Kudos

Great. Glad I could help.

Answers (1)

Answers (1)

Former Member
0 Kudos

Jesus,

Are you trying to change a different order with the BAPI then the one you are editing?

What you are trying to do is not clear. If you are trying to manipulate data in the current sales order you are working on, take a look at some of the other SAPMV45A user exits. For example you can manipulate data in subroutine USEREXIT_SAVE_DOCUMENT_PREPARE in program MV45AFZZ before the sales order is changed. For example if you want to block items you can loop at internal table XVBAP and set the appopriate blocks.

Chris

Former Member
0 Kudos

Hi Chris. Thanx for your reply...

I'm trying to modify the same order with the BAPI. I did try to use the USEREXIT_SAVE_DOCUMENT_PREPARE but it doesn't allow me to delete nor add a new position to the order. There are 3 things i have to do to the order, depending on a validation and a user choice:

1) Add a new Schedule line (Table VBEP) and block the current position (Field ABGRU)

OR

2) Delete the current position

OR

3) Do nothing

Former Member
0 Kudos

You <u><b>cannot</b></u> update the same order while in the same order using the BAPI. You don't have to. You are already in the sales order processing, why do you need to call another BAPI to change the same sales order? All you need is to modify the internal table xvbap and set the deletion indicator or add a record to xvbep internal table and remove the old one.

If this is happening after the order is created, you can simply write a program to take the user choices and call the BAPI. If you want to do this dynamically while creating and changing the order, then you need to use the MV45AFZZ.

Srinivas