Understanding and Implementing Classic BADI - aidamate13/AMS-Knowledge-Base GitHub Wiki

[!NOTE] SAP has provided us a class CL_EXITHANDLER for classical BADI purpose. We will use GET_INSTANCE method of CL_EXITHANDLER class to find the classic BADI for our requirement.

Requirement :- While creating a material through MM01 transaction code,

image

image

The Customer wants that if I am providing basic unit of measure as KG then I should get a error, when I click on save button.

Ways to find a Classical BADI :-

There are mainly three ways to find a Classical BADI , I will discuss the first one here and then I will discuss the rest of the two in the next part. In this part, we will find our required Classical BADI through debugging.

Finding Classical BADI for the above requirement :-

  • Step 1 :- Go to SE24 transaction code and display class CL_EXITHANDLER → double click on GET_INSTANCE method.

image

Put a debugger as shown above.

  • Step 2 :- Now go to mm01 transaction code for our requirement.

image

  • Step 3 :- Click on save button → It will take you to the debugging mode.

image

  • Step 4 :- Whatever BADI is available in this program, you get in the variable EXIT_NAME, you just need to keep pressing F8.

[!NOTE] Whatever BADI you will get here, you need to go to SE18 and check the BADI that it fits to your requirement or not.

  • Step 5 :- For the above requirement, the suitable BADI is given below.

image

In this BADI_MATERIAL_CHECK we have a dedicated method which we will use for our requirement.

image

Implementing Classic BADI for our requirement :-

  • Step 1 :- Go to SE19 transaction code and select Classic BADI radio button.

image

  • Step 2 :- Pass the name of the BADI that we have found above in the debugging and click on create button.

image

Provide a implementation name for our BADI.

image

  • Step 3 :- Click on the interface tab → The name of the implementing class will be appeared automatically.

image

  • Step 4 :- Double Click on the implementing class.

image

  • Step 5 :- Double click on the check data method to write the logic.

  • Step 6 :- In this method we have a table WMEINH, where we will find the entered basis unit of measure from MM01 screen, So, We can write our logic here.

image

Now, go back to BADI and activate the BADI first.

image

Testing the Implementation :-

Go to MM01 transaction code and fill the details.

image

Press enter and fill the rest of the details.

image

Click on save button.

image

We got the error message.