Vous êtes sur la page 1sur 14

Example on BAdI with 10 basic steps

For Basic enhancement knowledge please first view

http://debesh-exploringfacts.blogspot.in/2013/04/abap-enhancement-technologies.html .
Introduction: The BAdI is an object-oriented enhancement option. The BAdI defines an interface that can be implemented by BAdI-implementations that are transport objects of their own. Within the Enhancement Framework a BAdI is an enhancement option or an anchor point for an object plug-in. When to create a New BAdI? A developer while doing basic development of an object can anticipates where the customer or an industry solution might want to add some code at a particular point. In this case he creates both the development object to be enhanced at a later stage and defines an enhancement option. And it is essential to have such a hook: Where there is no hook you cannot attach anything. This analogy means that you can only insert an enhancement implementation where there is an enhancement option. With a BAdI the option provider defines what has to be done, but leaves it to the how he implements the BAdI. Moreover, the BAdI implementer cannot fiddle with the basic program. It is assured that a BAdI implementation can only change the parameters handed over to BAdI. To make something happen at an enhancement option, you need to implement it. The developer who implements an enhancement option attaches something to the hook. He need not care about the details of an enhancement option, but just know how he implements it. Steps: 1. The first thing you need when creating a BAdI is a container for the BAdI. For that purpose, you need to create a (simple) enhancement spot. This is the container in which you develop your BAdI. Go to transaction SE18 and create an enhancement spot.

By Debesh

Page 1

Example on BAdI with 10 basic steps

2. Create BAdI from enhancement spot.

By Debesh

Page 2

Example on BAdI with 10 basic steps

3. Up to now, you still do not have a BAdI. You need an interface where you can define the methods which determine what you can do with your BAdI. Create an interface for the BAdI or use a preexisting one.

4. Declare a method in the interface and add attributes for the method.

By Debesh

Page 3

Example on BAdI with 10 basic steps

If we want to use this BAdI now , our run the program at this stage dumps. This is it is mandatory to have exactly one active implementation for a single-use BAdI. You can handle this error by catching the respective exception cx_badi_not_implemented. The better solution is to use a fallback class. This class is used if there is no active BAdI implementation. The GET BADI command returns a handle to an instance of the fallback class and the respective CALL BADI calls the methods of the fallback class instance. As soon as there is an active BAdI implementation, the fallback class is no longer used at runtime.

By Debesh

Page 4

Example on BAdI with 10 basic steps


Using a fallback class serves two functions at once: the program runs with a single-use BAdI without throwing an exception. It is guaranteed that the fallback class is not used any more as soon as a BAdI implementation is supplied. The fallback class is selected conditionally. This is important because in most cases the BAdI provider does not know the details of some process. This is why a BAdI is used.

Fallback class is just like a default method. I am not using this for this example here.

5. By completing the steps above, you have created an enhancement spot and a BAdI with an interface. The interface has one method so far. However, just building a BAdI is not enough as it does not do anything. You need a BAdI instance and this instance must be called somewhere in the code. Since the BAdI only defines an interface, you need a class that implements this interface. 6. BAdI implementation on SE19.

By Debesh

Page 5

Example on BAdI with 10 basic steps

Give enhancement spot, BAdI implementation names.

By Debesh

Page 6

Example on BAdI with 10 basic steps

7. Till now nowhere the method definition is written. The declared method definition is written in a class. In the implementing class i/p field give an class name in which the class definition will be stored.

By Debesh

Page 7

Example on BAdI with 10 basic steps

8. Inside the class write the functional logic which you intended to do. 9. Now both the implementing class and the method of the interface are available with the BAdI implementation.

Save everything.

In my case I have written the logic like this side my BAdI method.

By Debesh

Page 8

Example on BAdI with 10 basic steps

Test it.

By Debesh

Page 9

Example on BAdI with 10 basic steps

10. Write a ABAP program and implement the BAdI inside that to use the predefined Logic inside that.

By Debesh

Page 10

Example on BAdI with 10 basic steps

If you have created a New BADI, then u need to use GET BADI and CALL BADI statements. For classic BADI you can use CL_EXITHANDLER=>get_instance.

By Debesh

Page 11

Example on BAdI with 10 basic steps

How to find existing BAdIs in a transaction before choosing the correct BAdI before Implementation? 1. Go to transaction SE24 and use GET_INSTANCE method of CL_EXITHANDLER.

2. Now put a break point at GET_CLASS_NAME_BY_INTERFACE and use the transaction on the command field for which the BAdI is needed.

By Debesh

Page 12

Example on BAdI with 10 basic steps

3. Enter the selection values.

By Debesh

Page 13

Example on BAdI with 10 basic steps


4. The execution will stop at the break point. Check the values of variable EXIT_NAME it will give you the BADI name called at that time.

5. Now after searching a proper BAdI, create am implementation in SE19. 6. Then choose a proper method based on import export parameters and write the proper code.

By Debesh

Page 14

Vous aimerez peut-être aussi