Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 23

Aim: To create a BADI implementation for CS01 transaction, that does not allow user to create alternative BOMs

for already
created BOM.

Hint: If an alternative BOM is created the field STALT from MAST table will be increased by 1. We can control future creation of
BOM using this field. Or if the particular material for which we are creating BOM has an entry in MAST then we should not
allow to create again. So the Badi can be approached in two ways. But I use the former method in this example you try the
latter method.

Step1:

Keep a break point in “CALL METHOD cl_exithandler=>get_class_name_by_interface” line inside the get_instance method of
the class cl_exithandler in Class builder (SE24).
Step2:

Now execute CS01 transaction, you will see the debugger that you set in SE24 transaction. Double click on the changing
parameter “EXIT_NAME”. Press F8 sequentially and make a note of the exit names.

Step3:

After you see CS01 just continue with the BOM creation and in mean time note all the Exit names that you come through in the
debugger.
Continue with BOM creation as follows.

Step4:

Click on save to find final set of BADI’s.

The BADI’s triggered is as follows.

Before SCREEN1
BOM_IPPE

IPPE_DOCID

IPPE_ENG_CHECK_EXT

W_RETAIL_SYSTEM_IDENT

Before SCREEN2

ECM_BOM_DECO

ECM_DOC_DECO

ECM_IPPE_DECO

ECM_MAT_DECO

ECM_055_DECO

ECM_060_DECO

ECM_061_DECO

ECM_062_DECO

ECM_ROUT_DECO

ECM_075_DECO

ECM_077_DECO

ECM_079_DECO

After clicking save:

BOM_UPDATE

BOM_EXIT

EHSS_SPEC_CHECKS

Step 5 :

Search for the “STALT” field inside any of the methods inside the BADI classes.

Shortcut: I know it’s the time killing process so I suggest you an easier way to find the specific class and method.

Goto SE19 in create implementation block under classic BADI enter the BADI names one by one and find out
whether implementation can be created or not. After doing this you will have very less BADI’s now go to SE24 and
add CL_EX_(BADI NAME) and check for methods that have the parameter STALT.

Step 6:

After finding the BADI and method in which you want to implement the code. Goto SE19 and create
implementation for that particular BADI.
Step 7: Enter implementation short text

Step 8 : Click on interface tab.


Step 9 : Double click on the method in which you want to write code as decided. You will see the following.

Step 10 :

Write the following code in the method.

method IF_EX_BOM_UPDATE~CHANGE_AT_SAVE.

if I_STLAL > 1.
message 'Alternative BOM cannot be created for this particaular material' type 'W'.
endif.

LEAVE PROGRAM.

endmethod.

Step 11 :

Save and activate the code and come back.

Step 12 :

Activate the Implementation and go to CS01 and try to create BOM for second time.
Implementing BADI for the transactions VL02 & MM02
Introduction to BADI

1. Based on OOPS concept.


2. No access key required.
3. All BADI’s can be seen in a class ‘CL_EXITHANDLER’.

Step 1:

Run the transaction SE24. Under object type put the class name ‘CL_EXITHANDLER’.

Click on display button.

Under this class ‘CL_EXITHANDLER’ select the method ‘GET_INSTANCE’ and double click.
Under the method ‘GET_INSTANCE’ put break point on a function module called

‘CALL METHOD CL_EXITHANDLER=>GET_CLASS_NAME_BY_INTERFACE’


Step 2:

Then according to the requirement run the transaction. In this example transaction code is VL02.

Run the transaction VL02. As in 1st step we have putted a break point, that function module will give all BADI used
by the transaction in each screen and activity on the application (VL02).

Under the parameter EXIT_NAME this debugger screen will give all BADI name for each screen.
Each time press F8, you will get all BADI used for the screen. After that system will go for next screen.

BADI NAME: EHS_DG_001

LE_SHP_DELIVERY_PROC

LE_SHP_PRICING

BADI_LAYER

CU_CONFIG_DELEGATION

1st screen of transaction VL02.

Step 3:

Choose your BADI name and you can see the detail in transaction SE18. Lets take a BADI ‘BADI_LAYER’. Click on
display button.
Press F8 to get the details of the corresponding BADI.

Here we can get the attribute and interface details of the BADI. As this one is screen BADI sub-screen tab also is
there.

Step 4:

To implement the BADI, we have transaction SE19. To create new BADI to implement the put your BADI name
here. If the BADI is an enhancement-point then put the BADI name in option NEW BADI and if only BADI then put
the name in CLASSIC BADI.

Give the BADI name and click on create button.

Press F8.

Again press F8. Give an implementation name. Let it be ZTTTTT


Give the description and select a suitable method double click to get into the method to put the ABAP code.

Implementing BADI for the transactions VL02 & MM02

To edit an implemented BADI the below portion is used. Click on the change button to edit the BADI.
EXAMPLE: To change the description of a material in transaction MM02.

Step 1: Run the transaction SE24. Under object type put the class name ‘CL_EXITHANDLER’. Click on display
button.

Under this class ‘CL_EXITHANDLER’ select the method ‘GET_INSTANCE’ and double click.

Under the method ‘GET_INSTANCE’ put break point on a function module called
CALL METHOD CL_EXITHANDLER=>GET_CLASS_NAME_BY_INTERFACE’

Step 2:

Then according to the requirement run the transaction. In this example transaction code is MM02.

Run the transaction MM02. As in 1st step we have putted a break point, that function module will give all BADI used
by the transaction in each screen and activity on the application (MM02).
Press F8 to get the BADI used.

BADI name before calling the main screen of MM02.

BADI_SCREEN_LOGIC_RT

W_RETAILSYSTEM_IDENT

Press enter to get into the details.


BADI name after calling the main screen of MM02.

BADI_MATERIAL_OD

Press enter to proceed.

Defining and Implementing Business Add-ins (BADI) (Step-by-step with


screenshots)
Defining a Business Add-in

SAP provides the BADI’s where are applicable in the standard applications. Application programmer whoever
wishes to have a Business Add-ins in a particular program can define the interface for an enhancement in the
Business Add-in builder. Programmer has to program the interface call in the program at the appropriate place.
Customers can select the add-in and implement it accordingly to their business needs.

1. From SAP menu, choose Tools -> ABAP Workbench -> Utilities -> Business Add-ins or transaction code
SE18. The example, which is illustrated, is the string conversion in the program. And giving the provision
to the users to determine themselves how their strings are to be converted. Application developer define
an enhancement, consists of interface with a method with changing parameter used to pass the string.
2. Enter the BADI name and choose create

3. Enter the short text, choose the interface tab.

4. Double click on the interface name field. The system branches to the class builder.
5. In the class builder assign a method to the interface and define a parameter with the attributes.

6. Save and activate the interface and navigate back to the Business Add-in definition. Now in
the BADI screen, displays the method you have created for the interface. When you maintain the
interface methods, corresponding executing class (Adapter class) is generated.
7. Save your entries and document the description of the Business Add-in. Documentation is important for
the users to understand the purpose of the Add-in.

Implementation of BADI

1. The list of Business Add-ins available in the system can be found through SAP Reference Implementation
guide (IMG) or in component hierarchy. BADI’s definition is included in IMG so that the customer/partner
can create suitable, company-specific implementations
2. In the SAP menu, choose ABAP Workbench -> Utilities -> Business Add-ins or transaction
code SE19.
3. Enter the implementation name and click on the create button.
4. Enter the BADI name

5. Enter the short description for the BADI implementation and implement the interface in the class
appearing in the BADI implementation screen.
6. Double click on the implementation class and insert the desired source code for the implementation
between the method ZIF_EX_BUSINESSADDIN~CONVERSION. And Method. In this particular example
enter the statement translate parameter to upper case. Save and activate your entries and return to the
change implemention screen.
7. Choose Activate, now you can use this implementation when the application program is executed. Several
implementations may exist for a Business Add-in but that is not used in multiple use basis. However only
one implementation can be activate at any one time. But in case of multiple use of the BADI, we can have
multiple implementations activate. The instance generation of the implementing class must set the
attribute as public and not as private, protected or abstract. System will give dump if you do so.
8. Following is the code for the class ZCL_CONVERSION_BADI_IMPL method CONVERSION

Method ZIF_EX_BUSINESSADDIN~CONVERSION.
translate parameter to upper case.
endmethod.

Calling BADI in the Application

1. When we define BADI, enhancement management generates a class that implements the interface. The
application developer uses a factory method to create an instance of adapter class in the application
program and calls corresponding method. The adapter class method generated by the enhancement
management decides by checking the entries in the table whether one or several active implementations
need to be called. If required, the implementations are subsequently executed. The application program
ensures only the adapter class method is called. The application program doesn’t know which
implementations are called.
2. Call the string conversion Business Add-in, the program calling the Business Add-in. Following is the ABAP
source code

REPORT ZMPTEST_BADI.
* Declaring the handler
class: cl_exithandler definition load.
* Interface Reference
data: badi_interface type ref to ZIF_EX_BUSINESSADDIN.
* String
data: w_str(15) type c value 'baddi test'.
*************************************************
****Start of Selection Event.....................
************************************************
start-of-selection.
call method cl_exithandler=>get_instance
changing
instance = badi_interface.
write: / 'Please click here'.
*************************************************
****At line-selection Event.....................
************************************************
at line-selection.
write: / 'original word', w_str.
if not badi_interface is initial.
call method badi_interface->conversion
changing parameter = w_str.
endif.
write: / 'Converted word', w_str.

Filter dependent Badi

1. Business Add-in definition level (for example a country, industry sector) we can have filter dependent option. If
an enhancement for country specific versions then it is likely that different partners can implement this
enhancement. The individual countries can create and activate their own implementation.
2. In the enhancement definition, all the methods created in the enhancement’s interface need to have filter
value as their importing parameter. The application program provides the filter values for the implementation
method.
3. Filter dependent BAdi is called using one filter value only, it is possible to check active implementation for the
filter value using the function module SXC_EXIT_CHECK_ACTIVE.

Multiple use Badi

1. There are multiple use and single use Business Add-ins. This option can be choose at Business Add-in definition.
2. The distinction is base on the procedure or event character of an enhancement. In the first case the program
waits for the enhancement to return a return code. Typical example is benefit calculation in HR depending on
the implementation, alternative calculations can be executed. In case of multiple use add-ins, an event that
may be interest to other components in program flow. Any number of components could use this event as a
hook to hang their own additional actions on to.
3. There is no sequence control for multiple-use implementations of BAdi’s. Sequence control is technically
impossible, at the time of the definition the interface does not know which implementations parameters will be
change the implementations.
4. The concept of multiple use of the Business Add-in is that has been implemented once already can be
implemented again by right of the software chain.

You might also like