Difference between different BAdI instantiation.
The below three instance creation method can be used during BAdI instantiation.
- Newly created instantiation
- Reused instantiation
- Context-dependent instantiation
The post describes by creating a enhancement sport and a BAdI definition and then creates a Enhancement Implementation and the badi implementation with implementimg class.
in Tx- SE20 create a enhancement spot.
Provide short text and continue.
Now create a BAdI definition.
Provide BAdI name , description and Continue.
This time the instance Creation mode is- Newly Creating Instantiation. Now double click on the Interface to create a new interface for the BAdI definition.
provide a interface name and double click on it.
YES to continue.
Provide a method name . Save , Activate and go back.
Now create a BAdI implementation.
Provide a enhancement implementation name and continue.
provide a BAdI implementation name and an implementing class name and continue.
Go to the implementing class.
Double click on the class name.
In the attributes section create an instance attribute.
Go to the methods section.
Provide the below code and activate the class and go back.
Activate the badi implementation.
Lastly activate the enhancement spot.
In instance creation mode as – Newly Creating instantiation for each GET_BADI statement, a new object of the implementing class is created. Now if you have two GET_BADI statement then for the sale implementing class two different objects are created and each one is assigned to the badi reference.
Create a program and call the BADI method with GET BADI and CALL BADI statements.
Now in the BAdI definition, change the Instance Creation Mode as- Reusing Instantiation.
In instance creation mode as – Reusing instantiation for the first GET_BADI statement, a new object of the implementing class is created. Now then if you have a second GET_BADI statement then the same object of the implementing class is reused for the second badi reference.
Now run the same program again.
Now change the Instance creation mode as – Context Specific Instantiation.
For Context Specific Instantiation, all GET_BADI statements receive the same object of the implementing class that belongs to the same context. To enable context specific instantiation a new class should be created which implements the interface: IF_BADI_CONTEXT .
Let’s create a class that implements the interface IF_BADI_CONTEXT.
create type and a table type in the types section.
Create an attribute of the table type.
Create a static method and provide below parameters.
The idea is to create a singleton design pattern.
Provide the below code. A new object of the class is created for a different context name else the previous object is returned.
Now create the program and run this.