Você está na página 1de 11

How to Implement a BADI in SAP ABAP with Tutorial

Aug 6th, in Articles, Enhancement & User Exit, SAP ABAP, by Raj

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 cant 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_EXITHANDLERs 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).

Step 2:
Go to Transaction code SE18.
Open BADI : BADI_MATERIAL_CHECK.
Go to menu option Implementation Create.

Step 3:
Give the implementation name as ZMM_MAT_CHECK.

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.

Step 5:
Go back and Activate the implementation.

Step 6:
So now its the time to Disco !!!!!!!Upsssss Sorry its 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.

Implementing BADI for the Transactions VL02 and MM02


...Previous

BADI used.
BADI_MATERIAL_OD
ECM_EXIT
BADI_LAYER
GOS_SRV_SELECT
BADI_MATERIAL_OD
ECM_EXIT

Change the description line and click on SAVE icon.

BADI name:
BADI_GTIN_VARIANT
BADI_MATERIAL_CHECK
EHSS_SPEC_CHECKS
Step 3:
Run the transaction SE18 to see the details of BADI.

Click on display button to see the methods declared in that.

Choose the method where the material description is defined.

Step 4:
Run the transaction SE19 and create an implementation for the corresponding BADI. Click on create
button to create an implementation.

Give a name for the implementation.

Give the description. Click on save icon and double click on the method chosen.

On a double clicking system will provide you the editor to write the code.

Code is
DATA:WA1 TYPE SHORT_DESC.

DATA: WA TYPE SHORT_DESC.


WA-MAKTX = 'HELLO'.
LOOP AT STEXT INTO WA1.
CONCATENATE WA1-MAKTX WA-MAKTX INTO WA1-MAKTX.
MODIFY STEXT FROM WA1.
ENDLOOP.