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: 

User Exit For VA01 To Restrict From Entering The Same Material twice

Former Member
0 Kudos

Hello All,

I have a requirement that in sales order creation(VA01) i want to restrict From entering the same material

more than once in a sales order i.e more than one same material not allowed in sales order i have tried alot of user exists but of no use

can u tell me the exact user exit

Regard's,

Mahesh Dasari

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Mahesh,

You can use user exit USEREXIT_SAVE_DOCUMENT_PREPARE which is available in include MV45AFZZ. This user exit will get triggered just before saving the data, here you can check Material No in internal table XVBAP. If you want to write conditions based on the Creation or change mode then you can make use of variable T180-TRTYP which will give you the mode type.

T180-TRTYP = 'H' : Creation Mode

T180-TRTYP = 'V' : Change Mode

Thanks & Regards,

Faheem.

18 REPLIES 18

Former Member
0 Kudos

Hi Mahesh,

You can use user exit USEREXIT_SAVE_DOCUMENT_PREPARE which is available in include MV45AFZZ. This user exit will get triggered just before saving the data, here you can check Material No in internal table XVBAP. If you want to write conditions based on the Creation or change mode then you can make use of variable T180-TRTYP which will give you the mode type.

T180-TRTYP = 'H' : Creation Mode

T180-TRTYP = 'V' : Change Mode

Thanks & Regards,

Faheem.

0 Kudos

Hi Faheem,

Thanks for u r quick responce i already tried their but there is some issue while deleting the twice entered material

can u tell me the exact user exit where i can do it i.e tell me at the time of entering the second material we can do something

Regards,

Mahesh Dasari

0 Kudos

Hi,

Yes you can use MV45AFZA Include, and write your validation code in FORM USEREXIT_MOVE_FIELD_TO_KOMPD.

it will trigger when user wil press Enter.

Regards,

Sujeet

0 Kudos

Hi ,

i have used user exit USEREXIT_SAVE_DOCUMENT_PREPARE which is available in include MV45AFZZ

which is giving proper result but pertaining to flashing msg of having duplicate material code on other line item.

the screen is getting grayed out when msg is flashed. when double clicked on line item system opens up to delete

the duplicate line item. after selecting the duplicate line and deleting it system removes the additional line .

now the issue raises when i tried to save the sales order the same msg appears after deleting the duplicate entry.

there might be possibility of issued related to retaining the cache

please help me on this

Regards,

Mahehs Dasari

0 Kudos

Hi Mahesh,

XVBAP-UPDKZ will give you the status of the line item. If XVBAP-UPDKZ = 'D', then this line item got deleted.

Thanks & Regards,

Faheem.

0 Kudos

@Sujeet: Why would you suggest a user exit for communication area population? That's a totally improper point of attack for this requirement...

@Mahesh: You mentioned that you tried alot of user exits - which ones? Wouldn't you rather validate the condition at item entry and not wait until save time, where the user exit doesn't handle that type of check very well? It does not make sense to delete an item behind the scenes w/o user interaction or the opportunity for the user to change anything. Why don't you use USEREXIT_CHECK_VBAP?

0 Kudos

@Brad: i already tried this user exit USEREXIT_CHECK_VBAP? but of no use can

please help on thid

Regards,

Mahesh Dasari

0 Kudos

@Brad: i already tried this user exit USEREXIT_CHECK_VBAP? but of no use can

please help on thid

What exactly did you try? Post your code...this requirement is easily done in this user exit. Also, note the differences in naming of the 2 VBAP exits - 'CHECK' and 'MOVE_FIELD' - which one do you think is correct? See the documentation for the exits as well.

You can easily read the XVBAP table - it sounds like you're only looking at the table header...

Former Member
0 Kudos

Hi Mahesh Dasari,

The User Exit you should use is : USEREXIT_MOVE_FIELD_TO_VBAP

Program : MV45AFZZ -

Form : USEREXIT_MOVE_FIELD_TO_VBAP

Code Logic :

VBAP structure will contain the record which should be validated against XVBAP.

Loop at the XVBAP Assigning <FS_XVBAP>.

if <FS_XVBAP>-POSNR ne VBAP-pOSNR

and <FS_XVBAP>-matnr eq VBAP-PSONR

and <FS_XVBAP>-updkz ne 'D'.

clear VBAP.

Message "Duplicate material entered " TYPE 'I'.

endif.

Endloop

Hope you find this useful

Regards,

Arun Thiyagarajan

0 Kudos

hi arun,

Program : MV45AFZZ -

Form : USEREXIT_MOVE_FIELD_TO_VBAP

can u tell me exactly where this user exit trigger

what would u do if one mateial at line item 10 and other one at 90

regards,

mahesh dasari

0 Kudos

Hi Mahesh Dasari,

1.This user exit is used to add additional datat to VBAP struture like custom fields. And this user exit is called for every single line item when processed.Say you have 10 items then this user exit will be triggered before each entry is populated in the XVBAP.

2.When the user enters item 10 with material 1 we allow him, then for the next line item say 20 we check if the material entered or processed ( this will be available in VBAP structure ) is available in XVBAP and the line item 10 is not deleted.

3. If the above check true then it means that the material entered is already existing else its not so it will proceed to next line item

e.g. in your question , item 10- Mat1 , item-20- Mat12, item-90-Mat1,

Then as per the code I have given , item 90 will be deleted or removed.

4. Now you can either delete the line item by clearing VBAP as I have done or give a error message that will be as per your requirement.

Use the logic I have provided in my earlier post , and see the behaviour.

Hope you find this answer helpful and set this questions answerd

Regards

Arun Thiyagarajan

0 Kudos

hi arun,

as per u r code i tried but the thing is that when u enter only the current posnr is in the xvbap or vbap structure

by that how we could compare line item by previous line item

regards,

mahesh dasari

0 Kudos

please

Arun Thiyagarajan

tell me correct work area to loop into it so xvbap is correct but <FS_XVBAP> is unknown .

tell me ASAP .

thanks alot .

0 Kudos

I GET field symbols : <FS_XVBAP> TYPE vbapvb.

but vbap has empty why ???

Former Member
0 Kudos

Hi Monoj,

if u use my code it will give a message and delete the item .

Please provide the code of what you have tried and the tested scenario.

Regards

Arun Thiyagarajan.

0 Kudos

hi everyone,

the issuse is resolved by everone's help. thank everyone for your valuable support

Thanks & Regards,

Mahesh Dasari

0 Kudos

Then mark the question as answered and post your solution!!!

0 Kudos

hi mahesh,

I am also having the same problem can u provide the code how did u solve this issue

Thanks and regards

Rakesh S