A user exit is a place in a software program where a customer can arrange for their own tailor-made code. SD module has a large number of User exit available.
The below is the create/ change sales order screen (VA01/VA02).
The requirement is to put the validation to the line items such that the quantity field for the line item should not be less than 2 units.
Step 1: How to find the appropriate USER EXIT.
Go to object navigator(SE80) and select package from the list and enter VMOD in it. All of the userexits in SD are contained in the development class VMOD. Press enter and you will find all includes which contain userexits in SD for different functions like PRICING, ORDER PROCESSING etc. Select the userexit according to the requirement and read the comment inserted in it and start coding .
There is a lot of confusion in using USER EXIT, like do we need access key to modify the USER EXIT ?.
The answer is Yes as well as NO.
If you see the include MV45AFZZ.we have many FORMS and ENDFORMS init which is in custom name space. So we don’t need key to modify it. Check out the below screen shot.
So open that include and write your logic in ZMV45AFZZ_SAVE_DOCUMENT_PREP.
While some EXITs like MV50AFZ1. You need an access key to modify it Don’t get puzzled, this is how SAP has given J.
Step 2:
So we got our USEREXIT ZMV45AFZZ_SAVE_DOCUMENT_PREP. Open it and put the below code inside it.
data: lv_flag(1) type c.
* exit if not SAVE
if sy-ucomm ne ‘SICH’.
leave to screen sy-dynnr.
endif.
* check line items
clear lv_flag.
loop at xvbap where updkz ne ‘D’.
* This checks for quantity less than 2
* As xvbap-kwmeng is pack with 3 decimal we are comparing with 2000
if xvbap-kwmeng < 2000.
message i000(fb) with
‘quantity is less than 2’.
lv_flag = ‘X’.
clear sy-ucomm.
exit.
endif.
endloop.
if lv_flag = ‘X’.
leave to screen sy-dynnr.
endif.
Go To Transaction VA01/VA02 and try to create/change the order item quantity less than 2.