How to Implement a BADI in SAP ABAP with Tutorial

How to Implement a BADI in SAP ABAP with Tutorial

Check this Article to know how to implement a Business Add-ins with a Example.

Author : Raj

Author's Website | Articles from Raj

Raj (Raju Borda) is an Application Developer focusing on Custom Development - particularly in the areas of ABAP ,WD4A , JAVA , APO , Enterprise services , Mobile applications and PI Developer/consultant . He is also certified in ABAP , PI and insurance domain. Facebook

The Requirement is to put a information message while creating a material if Material Group is A05 and Division is: 02.

(Why can’t we use field exit ?? : As it needs two information ( Material group and Division ) for the material also user wants information message while saving the material. this cant be achieved using field exit ).

Step 1:

How to find appropriate BADI for this requirement??

Put the break- point into Class CL_EXITHANDLER’s GET_INSTANCE method.

Go to transaction code MM01 , create a material and try to save it. it stops at many location with different values of EXIT_NAME. (After checking into Se18 we got the BADI_MATERIAL_CHECK which can be use for our requirement.

  • It has a method CHECK_DATA which is called before saving the material.
  • It also has WMARA table as input data (Material Group and Division comes in MARA table).

Badi_step1

Step 2:

Go to Transaction code SE18.

Open BADI : BADI_MATERIAL_CHECK.

Go to menu option Implementation à Create.

Badi_step2

Step 3:

Give the implementation name as ZMM_MAT_CHECK.

Badi_step3

Step 4:

Double click on the method CHECK_DATA.If you notice the input parameters we have many data related to batch , material and storage location etc..

For our requirement we need material group and devision Which exist in WMARA.Put the below code inside the method then activate the class and method.

if WMARA-MATKL eq ‘A05′ and WMARA-SPART eq ‘02′.
message ‘Material creation for this Group should be avoided for animal products!!’ TYPE ‘I’.
endif.

This code is just checks the material group and division.

Badi_step4

Step 5:

Go back and Activate the implementation.

Badi_step5

Step 6:

So now it’s the time to Disco !!!!!!!Upsssss Sorry it’s the time to test this BADI.

For this go to transaction MM01 and try to create a material.

(if you are confused use material name as CH004 ,

Industry sector as Animal Health and

Material Type as Beverages )

Click on the ENTER Button and from the view select BASIC DATA 1.

Badi_step6

Badi_final

Related Posts



Like this post? Share it!

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

ADVERTISE HERE


User Comments


  1. uma gupta
    October 7, 2010

    hi dude…

      u ease my proble..
      

    Reply


  2. Yogesh Patil
    October 18, 2010

    Hi Friends,
    I have total 4.5 Years of Exp. in SAP-ABAP, I gone through lot of documents but the way these document and designed and presented  on this portal are amazing…comments in between like Brett Lee Bounser and It’s a time to Disco…
    I mean to say apart from work there is something different which I liked most…
    No doubts about Document they are really very well documented and User friendly…but to Present each and every thing you should have proper way…I appreciate this way of publishing document…
    Thanks a lot…& I appreciate UR efforts…Good Job Done …Keep it up…!!!

    Thanks & Regards,
    Yogesh Patil

    Reply


  3. asha
    November 19, 2010

    really presented well…in an understanding way..:-P

    Reply


    • Elmira
      August 12, 2011

      Infrotmiaon is power and now I’m a !@#$ing dictator.

      Reply


  4. rakesh
    November 29, 2010

    hi

    i am rakesh the way of your presention is very good
    superb  keep it up guyes

    Reply


  5. BAdi Beginner
    January 18, 2011

    Like the way you presented. Light and Easy! :-D

    Reply


  6. Kalyan
    April 18, 2011

    This was really helpfull …… and damn good presentation….  :)

    Reply


  7. sai
    June 5, 2011

    :idea: at Last i found the good concept in this
    tahking you
    :lol:

    Reply


  8. Rajiv Das
    June 11, 2011

    Awesome Presentation….I can see you in front of me, as u teaching in a light mode,..

    Reply


  9. akein
    June 22, 2011

    Priceleesss!!!   :-P

    Reply


  10. Nooruddin
    June 22, 2011

    This was really helpfull and Priceleesss!!!     Thank you very much.

    Reply


  11. kevin
    June 23, 2011

    it ’s good to understanding the BADI, awesome

    Reply


  12. venky
    July 21, 2011

    Good job done!!

    Reply


  13. sanju
    July 25, 2011

    Hi Dear,
    Can u help me out to know how to know its edit implementation of badi or create implementation. And again within dat which radio button to choose with sm examples.
     
     
    Thanks
    Sanju

    Reply


    • Raj
      July 25, 2011

      Hi Sanju ,
      Please find my comments below:

      how to know its edit implementation of badi or create implementation
      BADI is something is provided by SAP standard team what we do is we create an implementation for it.
      You cant edit the standard BADI.What we do is we create an implementation for it and we modify the created
      implementation.

      And again within dat which radio button to choose with sm examples.

      It’s not clear what you want to ask.may be you are asking for.Can you put some light on it.?

      thanks
      Raj
      SAP IGnite.

      Reply


  14. venu
    July 26, 2011

    Good

    Reply


  15. Oka
    July 27, 2011

    Nice tutorial
    Thanks
    oka

    Reply


  16. Arumugam
    August 4, 2011

    Thank You very much.
    Whenever I use BADI, surely I will remember you.
     

    Reply


  17. Thanks
    September 23, 2011

    my badi from you,thanks

    Reply


  18. Abhinesh Sinha
    January 31, 2012

    Hi,
    It seems as somebody is teaching infront of me. It is presented in a very easy and understandable way. It attracts the Reader attention.
    Thanks for your kind support.
     
     
     
     

    Reply


  19. ramya
    February 15, 2012

    hi raj,
    am a hr abaper i got a requirement to set a default value for the field( id number) in infotype 185 and subtype 02, i already created a classic badi  ’zhrpadooinfty’  so using this i need to set the default value, i asked my team leader he asked me to do using implict enhancement so i am unable to do please help me on this.
     
    thanks & regards
    ramya

    Reply


    • Raj
      February 15, 2012

      Hi Ramya,

      If your question is how to implement the implicit Enhancement :
      check out : How to implement Implicit Enhancement

      If the code which you have placed in the BADI is not working thn and thn follow your lead’s method.

      Please paste the code which you are trying with program name so that i can check it out in my system.

      thanks & Regards,
      SAP Ignite
      ~Raj

      Reply


  20. ramya
    February 16, 2012

    Hi Raj,
    i have return the below code in my badi (before_ouput method) *************Setting default value for field ID number in IT 185*************************
    DATA: i0185 TYPE p0185.
    if ipsyst-ioper = ‘INS’ and innnn-infty = ‘0185′.
    CALL METHOD CL_HR_PNNNN_TYPE_CAST=>PRELP_TO_PNNNN
    EXPORTING
    PRELP = innnn
    IMPORTING
    PNNNN = i0185.
    MOVE ‘PANNOTAVBL’ to i0185-icnum.
    CALL METHOD CL_HR_PNNNN_TYPE_CAST=>PNNNN_TO_PRELP
    EXPORTING
    PNNNN = i0185
    IMPORTING
    PRELP = innnn.
    endif.
    for my classic badi the definition name is HRPAD00INFTY
    so this what i have used can you help me on this,
    Thanks & Regards
    V.Ramya
     
     

    Reply


  21. Chetan
    March 16, 2012

    Great help! Thanks.

    Reply


  22. sharmistha
    April 10, 2012

    hii raj,
    can u plz explain me why we chose badi_material_check.
    i m new in badi.
    and ur badi material helps me a lot.
    if u have more material on badi plz send me on <><><>
    thanks,
    sharmistha.

    Reply


    • Raj
      April 11, 2012

      Hi Sharmistha,
      As i mentioned in the post. the BADI BADI_MATERIAL_CHECK’s Check_data method is triggered
      during creation of the material .
      we want when use is creating a material validation is done so the triggered timing is perfect.

      Also whatever data we want to validate it contains the the importing parameter of the badi so
      it can be used.

      NOTE : there might be more thn one BADI who fulfill ur requirement ( triggering time , proper importing data )
      You can use any badi at that time,no restriction on it as such.

      Please get back if i am not clear .

      Thanks
      RAJ
      SAP IGnite.

      Reply


      • sharmistha
        April 11, 2012

        yes i got it..
        thanks 4 ur reply..
        Sharmistha

        Reply


  23. sharmistha
    April 11, 2012

    Hii,
    when i create implementation through se18 ,i got the method 
    method IF_EX_BADI_MATERIAL_CHECK~CHECK_MASS_MARC_DATA.
    which is diffrent from ur method method IF_EX_BADI_MATERIAL_CHECK~CHECK_DATA.
    and when i write the code inside the method like

    method IF_EX_BADI_MATERIAL_CHECK~CHECK_MASS_MARC_DATA.
    if WMARA-MATKL eq ‘A05′ and WMARA-SPART eq ‘02′.
    message ‘Material creation for this Group should be avoided for animal products!!’ TYPE ‘I’.
    endif.
    endmethod.

    it shows a error     Field “WMARA-MATKL” is unknown. It is neither in one of the specified  
    tables nor defined by a “DATA” statement . . . . . . . . . .  
     
    what to do?

    plz help

    sharmistha

    Reply


    • Raj
      April 11, 2012

      Hi
      its very basic thing.all the bad might not have same importing parameters.
      WMARA Is available in my badi .please check the signature of thwarting badi
      which you are trying to use.it might not contain WMARA as its importing parameter.
      There might be different parameter which contains the data.

      Thanks
      Raj
      SAP IGnite

      Reply


  24. sharmistha
    April 11, 2012

    i just copy paste ur badi which u post ..but it shows the same error..and the badi have a importing parameter wmara,which i check on double clicking on check_data…
    also tell me plz why ur method is different from my method like
     method  di IF_EX_BADI_MATERIAL_CHECK~CHECK_MASS_MARC_DATA.
    which is diffrent from ur method method IF_EX_BADI_MATERIAL_CHECK~CHECK_DATA.
    i work on ecc 6.0….
    thanks .
    sharmistha

    Reply


  25. Harikrishna
    August 3, 2012

    Hi Experts,
    My requirement is, while creating a service using tcode ML81N, If the reference number already exists means, then one error message has to be displayed.
    Is there any BADI or User Exit available for this., please let me know.
    Thanks in Advance.
    Harikrishna
     
     

    Reply


  26. Tab
    September 13, 2012

    Dear raj,

    Thanks for the wonderful go thru of BADI implimentation, but I just wonder how and where is the method CHECK_DATA being called when creating a material. I mean there must be a call to the implemented method also during the flow of the transaction.

    Reply


    • Raj
      September 15, 2012

      Hello Tab,

      As i explained the BADI is a hook. Standard SAP creates it and place it in the code.
      That code contains call to the appropriate method ( like CHECK_DATA )

      so in implementation phase you just need to implement it using Se19 ,
      As the code is already placed to make a call it will trigger your implication automatically.

      Thanks
      ~Raj

      Reply


  27. Harshal
    September 29, 2012

    Thanks a ton Raj..
    Your posts are really helpful to beginner..
    Thanks again for your help.

    Reply


  28. Rekha
    October 18, 2012

    Hi Raj,

    I have seen so many articals and explanation in net regarding BAdi, Userexits , but u r amazing yar, realing Happy & thanks a lot for u r effort.

    Thaks,
    By
    Rekha.:-?

    Reply


  29. Prem
    July 10, 2014

    Raj
    You Explained these stuff in simple language that everyone can understand ..Thanks for sharing this good work
     
    Prem

    Reply


  30. moshe
    July 30, 2014

    Thanks RAj, very clear explanation.
    CL_EXITHANDLER is very powerfull. thanks for sharing it with us
    Moshe

    Reply

Leave a Reply

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