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

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. vasu
    March 24, 2014

    nice dude… :-x

    Reply


  2. Barun
    March 5, 2014

    Hi Raj ,Nice tutorial dude , you saved me a couple of hours :)  thanksBarun

    Reply


  3. shamshuddin
    January 3, 2014

    Hi Raj,
    How can we know whether it is a Old badi or new badi?

    Reply


  4. Roopa MC
    December 21, 2013

    Hi,
    I searched so many sites for learning BADI Implementation but only you could provide me the solution for my problem. Its very easy to understand and presented very well.
    Thank you very much.

    Reply


  5. Rupesh
    November 7, 2013

    Hi Raj,
    Amazing turorial I have never seen before.
    Thanks a lot…….. :lol:
     

    Reply


  6. Vizy
    September 28, 2013

    Hello Raj/Sharmistha,
    Thank u for putting together a gr8 tutorial.
    I’m getting a error similar to Sharmishta.  How do I resolve it. -
    Field “A05” is unknown. It is neither in one of the specified   tables nor defined by a “DATA” statement . .
     
    Thanks,
    Vizy

    Reply


    • vigneshwaran
      October 25, 2013

      its same like a field exits……..  please give another sample!!!!!!!!

      Reply


  7. Shilpa Reddy
    August 30, 2013

    Can u tell me the field symbols and field groups?
    and how to use it and why use it?

    Reply


  8. Khushboo
    August 10, 2013

    Hi Raj,
     
    How will we implement a BAdI which would block PO Cancellation (prevent PO Cancellation/deletion) if advance payment has been made?
     
    Regards,
    KS

    Reply


  9. Dillip Reddy
    June 23, 2013

    Hi Raj,
    Could you please provide some docuemts on classical and interactive reports.
    Thanks,
    Dillip

    Reply


  10. Dillip Reddy
    June 23, 2013

    Hi Raj,
    Very good Explanation on Badi,User exits and Customer exits. If you have some documents on Kernal Badi, Could you please provide us.
     
    Thanks,
    Dillip

    Reply


  11. jogu
    May 30, 2013

    Hi  Raj
    Presenting The Enhancement it is very
     

    Reply


  12. Nikhil H
    May 10, 2013

    Hi Raj
    I have a requirement,suppose i am entering a value in a field lets   take an example,
    material group, if i enter material group value as MM_a05 then it should get save in database as a05, and whenever i go to mm03 transaction to display that material,It should give the value of material group as MM_a05.
    hope you understood my requirment.
    Thanks in Advance.

    Reply


  13. Nikhil H
    May 10, 2013

    Hi Raj
    I have a requirement,suppose i am entering a value in a field lets   take an example,
    material group, if i enter material group value as MM_a05 then it should get save in database as a05, and whenever i go to mm03 transaction to display that material,It should give the value of material group as MM_a05.
    hope you understood my requirment.
    Thanks in Advance.

    Reply


  14. sudha
    March 22, 2013

    hello sir.. i am new to abap and have a requirement..using VENDOR_ADD_DATA  badi , if you modify the data it should modify in database..so can you please say me the procedure and coding..pls help me out sir

    Reply


  15. Marco
    March 5, 2013

    Hi Raj,
    thanks for your great Tutorial!
     
    I’ve implemented the BADI “BADI_MATERIAL_CHECK”.
    Can you tell me, how  I can  check if the field “individual and coll. reqmts”, MARC-SBDKZ located on MRP 4 view in Material Master, has changed?
    So I don’t have to do my checks every time the material master is saved.
     

    Thanks,
    Marco.

    Reply


    • Raj
      March 6, 2013

      Hi Marco
      I guess I have not understood question correctly or you have over looked..as marc is in importing parameters you can validate the field content
      And raise exception or error message..

      Thanks
      Raj
      Sap ignite

      Reply


      • Marco
        March 6, 2013

        Hi Raj,
        thanks for your answer.
        Yes, I have marc in the importing parameters and I can check the current value of eg. MARC-SBDK. But how can I determine that this field has actually changed? I’m looking  for something like
        IF old_sbdk NE marc-sbdk.
        [Do some checks]
        ENDIF.
        The only way I know is to do a select on the current value stored in the database and to compare this to my current value in the structure marc.
        I hoped that there is a more “elegant” way to do this instead of doing a database read. (so maybe the old values are somethere in the memory or something like this).

        Thanks,
        Marco.
         

        Reply


        • Marco
          March 6, 2013

          It’s me again…

          I found the solution myself :wink:
          I use a dirty assign to get the old marc values:
          SPAN { font-family: “Courier New”; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; } FIELD-SYMBOLS:
          <ls_omarc> TYPE marc.

          * Get old MARC values by Dirty Assign
          ASSIGN (’(SAPLMGMU)OMARC’) TO <ls_omarc>.
          At this point <ls_omarc>-sbdk has the old value assigned and I can check with
          SPAN { font-family: “Courier New”; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S52 { color: #0000FF; } .L0S70 { color: #808080; }
          IF <ls_omarc>-sbdkz <> wmarc-sbdkz

          if the value has really changed.
          Thanks,
          Marco.

          Reply


  16. Rubencio
    February 15, 2013

    THX Raj.

    Reply


  17. Eshant
    January 11, 2013

    Hi Raj,
    I am learning ABAP and quite new. Could you please explain the basic concept of BADI.  Everywhere the way of using badi (business Addin) I see on internet is they use Class CL_EXITHANDLER’s GET_INSTANCE method. They find badi and then make some modifications. But I am not clear whats the concept behind this specific class name.

    Please put some light on basic flow  of steps or an approach to use badi.
    Why do we use it? Why can’t we use exits only?
     
    Regards,
    Eshant Garg
    :-)

    Reply


  18. mahesh reddy
    January 11, 2013


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


  20. Harshal
    September 29, 2012

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

    Reply


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


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


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


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


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


  26. Chetan
    March 16, 2012

    Great help! Thanks.

    Reply


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


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


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


  30. Thanks
    September 23, 2011

    my badi from you,thanks

    Reply


  31. Arumugam
    August 4, 2011

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

    Reply


  32. Oka
    July 27, 2011

    Nice tutorial
    Thanks
    oka

    Reply


  33. venu
    July 26, 2011

    Good

    Reply


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


  35. venky
    July 21, 2011

    Good job done!!

    Reply


  36. kevin
    June 23, 2011

    it ’s good to understanding the BADI, awesome

    Reply


  37. Nooruddin
    June 22, 2011

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

    Reply


  38. akein
    June 22, 2011

    Priceleesss!!!   :-P

    Reply


  39. Rajiv Das
    June 11, 2011

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

    Reply


  40. sai
    June 5, 2011

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

    Reply


  41. Kalyan
    April 18, 2011

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

    Reply


  42. BAdi Beginner
    January 18, 2011

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

    Reply


  43. rakesh
    November 29, 2010

    hi

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

    Reply


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


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


  46. uma gupta
    October 7, 2010

    hi dude…

      u ease my proble..
      

    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