User EXITs in SAP ABAP with Tutorial

User EXITs in SAP ABAP with Tutorial

Check this beautiful article to know everything about USEREXIT. It also contains tutorial of how to implement a User EXIT.

Author : Raj

Author's Website | Articles from Raj

Raj is an Application Developer focusing on Custom Development - particularly in the areas of ABAP ,WD4A , JAVA , APO , Enterprise services and PI Developer/consultant . He is also certified in ABAP and PI. FacebookTwitter

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.

* 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.

if lv_flag = ‘X’.
leave to screen sy-dynnr.

Go To Transaction VA01/VA02 and try to create/change the order item quantity less than 2.


Related Posts

Like this post? Share it!

  • Tweet
  • Facebook
  • Diggit
  • Delicious
  • Diggit
  • Diggit
  • Diggit
  • Diggit
  • Diggit


User Comments

  1. shri dutt
    January 9, 2014

    Pleae give me 3-4 example for userexit and enhancement?


  2. Kunal
    January 8, 2014

    Hi Raj,
    I have a requirement while saving Invoice in VF01 the profit centers of Finished Goods should be bifurcated in Profit centers of the Raw materials used at the time of SAVE of invoice and that bifurcation should be displayed in Accounting.
    EX- A is Finished good and its made from 2 raw materials B and C who have different profit centers.So when i create an Invoice with reference to delivery in which Finished good A is used and SAVE that Invoice at the Time of SAVE the bifurcation shold take place for Finished Good ‘A’ and that will be in Accounting as on Raw materials B and C’s profit center the quantity used and amount etc. Overall this is the requirement am not able to decide which will be the suitable user exit for VF01 at the time SAVE for the same.
    If you can help please help.


  3. Elaine
    January 7, 2014

    Hi Raj,
    Thank you so much for your article. They are all very help!!!
    I have a question here – xvbap looks like a internal table, is it a particular parameter of user exit USEREXIT_SAVE_DOCUMENT-PREPARE? Are there any other parameters? Where to check?
    Many many thanks!


    • Raj
      January 8, 2014

      Hi Elaine,

      xvbap is declared as global data.You can access all the data which are declared as global data in the main program.
      for us in the include MV45AFZZ plus in the main top include.

      SAP IGnite


  4. Quiti
    October 4, 2013

    Thanks a lot Raj, it worked it! :)


  5. Hitesh
    May 26, 2013

    HI RAj,
    can u plz tell me why we are checking this condition???


    • Hitesh
      May 26, 2013

      updkz ne ‘D’. in above code


  6. Xavier
    March 12, 2013

    loop at xvbap where updkz ne ‘D’.
    why updkz ne ‘D’ ? pls tell me whats that field ‘updkz’ …


  7. Sivakumar V
    December 15, 2012

    Doing great! Many Thanks for your service!


  8. Tripti
    November 27, 2012

    Superb work Raj!

    Pls do keep posting new articles covering various topics of SAP ABAP..

    One question – Could you pls throw more light on – How to find User Exit for SD?

    Using SE80 with VMOD as package name, it gives many exits . So, its difficult to analyse each and find out which is suitable to my requirement?
    Any tip in this search?


    • Raj
      December 3, 2012

      Hi Tripti ,

      As we don’t have proper documentation of all the available user exits.The only way is either go via description or search on SDN for the same.

      Let me know if you need details regarding a particular transaction code or an application.

      SAP IGnite


  9. Shalini
    October 10, 2012

    Hi Everyone,
    I want to learn workflow , does anybody have  real-time scenario of workflow along with proper screen shot.
    Thanks in advance


  10. Shalini
    October 9, 2012

    Thanks Raj  :)


  11. Shalini
    September 27, 2012

    Hi ,
    Do we need access key only first time while changing in MV45AFZZ or MV50AFZ1 or everytime we write in form endform it will ask for access key??
    i tried to write code in MV50AFZ1 in FORM userexit_refresh_document , i created ENHANCEMENT it does’nt ask for the key.
    i am quite confused related to how to write code in that form endform and when it will ask for key.
    plz help…
    thx in advance


    • Raj
      September 29, 2012

      Hello Shalini,

      Once you applied the Access key you need not to enter it again and again.

      For the First time whenever you enter the key it gets stored in the DB table ADIRAKEY (**not 100% sure abt table name)
      And that particular object will be allowed for the future changes.

      You can directly write your code inside the form – Endform
      As an Example :

      *{ INSERT WDVK900314 1

      DATA : li_old_xlips like line of xlips occurs 0 with header line.
      DATA : li_xvbfa like line of xvbfa occurs 0 with header line.

      Perform MV50AFZ1_ZWM03.

      *** Perlu dilakukan karena proses split.
      IF T180-TRTYP = ‘H’ and CVBAK-VKORG = ‘A201′ and CVBAP-WERKS = ‘2012′
      and CVBAK-VTWEG ne ‘07′ and CVBAK-VBTYP = ‘C’.

      *** For Plant 2012 Re-arrange table xlips xvbup and xvbfa here ****
      ****>>> SY SYARIEN <<<>>> END OF ENHANCEMENT >>>>>****************


      Get back if its not clear.

      Thanks & regards,


  12. srikanth
    September 24, 2012

    Hi Raj,

    could please you tell me default package for QM module in sap.

    Waiting for your reply, & Thanks in advance. :-D

    Thanks & Regards



    • Raj
      September 25, 2012

      Hello Srikanth,

      The Default package is QM it self.
      tell me which business application you are looking for will tell you the package in which it belongs to.



  13. somnath
    March 1, 2012

    What is the Package for MM01/MM02 like VMOD for sales related


    • Raj
      March 1, 2012

      Hi Somnath ,
      Which kind of enhancement you are looking for ?
      the package for the MM01 is MG.

      thanks & regards,


  14. Nazi
    June 10, 2011

    when i tried to implement this  in my IDES( in include MV45AFZZ), it is asking for the access key.Can you guide  me ,please.


    • admin
      June 11, 2011

      Hi Nazi,
      You don’t have ABAP access in SAP Ides. Please use MiniSAP for doing ABAP Program.



    • Raj
      June 13, 2011

      Hi Nazi,
      You might have tried to modify the include MV45AFZZ.
      You need to double click on the PERFROM and u need to modify that include starting with “Z”.

      SAP IGnite.


      • Carajean
        January 12, 2012

        Boy that raelly helps me the heck out.


  15. Yogesh Patil
    October 18, 2010

    I found all documents well documented and special thing about these documents are self explainatory,User friendly…Good Job
    Keep it up Guys…


Leave a Reply

:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!:
  Twitter Followers Email Updates