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: 

Sales order user exit to make item quantity zero

Former Member
0 Kudos
268

Hello friends ,

Here is my requirement . When I am creating or changing the

sales order I need to check wether the material is discontinued

or not and if discontinued and if discontinued I need to make the

quantity as zero . Can you please hekp me out with this .

We are on version ECC 5.0

Can anyone tell me if this will resolve my issue .

<b>userexit_save_document_prepare</b>

Thanks ,

Varun .

16 REPLIES 16

naimesh_patel
Active Contributor
0 Kudos
98

In MV45AFZZ you can use the subroutines USEREXIT_MOVE_FIELDS_TO_VBAP or USEREXIT_MOVE_FIELDS_TO_VBEP for your purpose.

In USEREXIT_MOVE_FIELDS_TO_VBAP you can access XVBAP with the data and modify it.

In USEREXIT_MOVE_FIELDS_TO_VBEP you can access XVBEP with the data and modify it.

Regards,

Naimesh Patel

0 Kudos
98

Hi Naimesh ,

Thanks for your response . Since we are trying to change the item details I think

USEREXIT_MOVE_FIELD_TO_VBAP is more appropriate . But this exit will not get triggered if I merely change the item quantity . So I am wondering if the routine USEREXIT_SAVE_DOCUMENT_PREPARE will be of more help .

Can I have your opinion here please .

Thanks ,

Varun .

0 Kudos
98

Hi alll ,

Finally I had my code in this way in the exit : USEREXIT_SAVE_DOCUMENT_PREPARE

Here is my code :


data wmvke like mvke .

field-symbols : <f_xvbap> type VBAPVB .

loop at xvbap assigning <f_xvbap>.
select single * from mvke into wmvke where matnr = xvbap-matnr and
                               vkorg = vbak-vkorg and
                               vtweg = vbak-vtweg and
                               vmsta = '30' .
    if sy-subrc eq 0 .

    <f_xvbap>-kwmeng = <f_xvbap>-kwmeng * 0 .
    <f_xvbap>-updkz = 'U' .
    <f_xvbap>-abgru = 'PR' .

*    modify xvbap .
    endif .

endloop .

In the debug mode while saving the sales order I can see the process going through the code and table xvbap getting executed . But still I do not have any idea on why it is not reflected when I comeout from the debug mode .

Please help me with this .

Thanks ,

Varun .

0 Kudos
98

Ok if you want to use the USEREXIT_SAVE_DOCUMENT_PREPARE than you need to take a help of the field symbol. Because generally, it shows that XVBAP is being modified here but the database will not update.

Like:

data wmvke like mvke .
 
field-symbols : <f_xvbap> type VBAPVB .
 
loop at xvbap assigning <f_xvbap>.
select single * from mvke into wmvke where matnr = xvbap-matnr and
                               vkorg = vbak-vkorg and
                               vtweg = vbak-vtweg and
                               vmsta = '30' .
    if sy-subrc eq 0 .
 
    <f_xvbap>-kwmeng = <f_xvbap>-kwmeng * 0 .
    <f_xvbap>-updkz = 'U' .
    <f_xvbap>-abgru = 'PR' .
 
*    modify xvbap .
    endif .
 
endloop .
 

  FIELD-SYMBOLS: <xvbep>       TYPE table.  " <<
  ASSIGN ('(SAPMV45A)xvbap[]') TO <xvbap>.  " <<
  <xvbap> = xvbap[].  " << by assigning this it will change the data in XVBAP

Regards,

Naimesh Patel

0 Kudos
98

Hi Naimesh ,

Going in the debug mode I don't see any difference between the way I have coded and you have recommended . Here XVBAP refers to sapmv45a xvbap only .

Thanks ,

Varun .

0 Kudos
98

Ya that true, but your code will not change actual values in the XVBAP, whereas my code will the value in the XVBAP.

If you have written your code in the subroutine USEREXIT_MOVE_FIELDS_TO_VBAP than it will work.

Give a try and see what happends..!!

Regards,

Naimesh Patel

0 Kudos
98

Hi ,

Ha , this produced a database error saying the database update is terminated . That doesn't work Naimesh .Sorry to say this .

Thanks ,

Varun .

0 Kudos
98

Oh.. it is working for me though.

As I posted pervioulsy, try to use the USEREXIT_MOVE_FIELDS_TO_VBAP or USEREXIT_MOVE_FIELDS_TO_VBEP for clearing your quantity.

Basically, USEREXIT_SAVE_DOCUMENT_PREPARE and USEREXIT_SAVE_DOCUMENT are used when you need to update some other Ztable based on the data from the SO. So, please try to use the MOVE_FIELDS... subroutine.

Regards,

Naimesh Patel

0 Kudos
98

Naimesh ,

Do you mind posting the code . Please can you please post the code you have developed . Also is it working fine even if you are in VA02 ?

Thanks ,

Varun .

0 Kudos
98

Naimesh ,

The problem with moving to vbap and vbep is they do nottrigger for all changes . I would like to refer to this OSS notes 513342 for your reference . Also to mention we are on ECC 5.0 version here .

Regards ,

Varun .

0 Kudos
98

We had this type of problems in the MOVE subroutines so, we used this FIELD-SYMBOL way.

I have the same code what I had given you for modifying the the table XVBAP and it doesn't give me any problem in USEREXIT_SAVE_DOCUMENT. Try to put that code in this subroutine instead of the USEREXIT_SAVE_DOCUMENT_PREPARE.

Regards,

Naimesh Patel

0 Kudos
98

Hi ,

This is what I have now under <b>USEREXIT_SAVE_DOCUMENT</b>


data wmvke like mvke .

field-symbols : <f_xvbap> type VBAPVB ,
                <xvbap>   TYPE table.

loop at xvbap assigning <f_xvbap>.

select single * from mvke into wmvke where matnr = xvbap-matnr and
                               vkorg = vbak-vkorg and
                               vtweg = vbak-vtweg and
                               vmsta = '30' .
    if sy-subrc eq 0 .

    <f_xvbap>-kwmeng = <f_xvbap>-kwmeng * 0 .
    <f_xvbap>-updkz = 'U' .
    <f_xvbap>-abgru = 'PR' .

*    modify xvbap .
    endif .

endloop .

ASSIGN ('(SAPMV45A)XVBAP[]') TO <xvbap>. 
  <xvbap>[] = xvbap[].  

But still no Luck .

Regards

Varun .

0 Kudos
98

Oh...

Ok try something else otherthan MV45AFZZ.

Try to implement the User Exit: V45A0003.

FM: EXIT_SAPMV45A_003

Here you can find the table interface for the VBAP.

Try to put your code in this user exit.

Regards,

Naimesh Patel

0 Kudos
98

I am like halfway successful .

Earlier the xvbap-abgru was not even updated . But with this enhancement that is done . But still the quantity is not corrected to zero .

Regards ,

Varun .

0 Kudos
98

Hi all ,

Can any of you please come up with a solution for this requirement . I tried my best and find no progress .

Thanks ,

Varun .

Former Member
0 Kudos
98

Self