In This Blog We Will Discussed About What Is Instance Generation Modes in Kernel BADI And Creation of 3 Types of Mode.
Instance Generation Mode:-
Definition:-
This property controls the instantiation of the object plug-ins during execution of the statement GET BADI. The following are possible specifications:
Types:
Use:
The first two specifications define context-free BAdIs. In the case of the newly created instantiation, new object plug-ins are created at each execution of the statement GET BADI. In the case of reused instantiation, an object plug-in that was used once in the current internal mode is reused – if it is required more than once.
In the case of context-dependent instantiation, a context must be specified for GET BADI . This context controls instantiation. Only one object plug-in is created for each context and implementing class. Each time there is another GET BADI with the same context, it is reused. A context is an instance of a class that implements the tag interface IF_BADI_CONTEXT. The specification takes place in the form of a reference to such an instance.
Creation of instance generation mode.
1. Go to SE20 T-code to create a enhancement spot
2. Provide a short description and continue, save it in your package
3. Now create a BADI definition
4. Provide a BADI name, description and continue
5. This time the instance creation mode is newly creating instantiation. Now double click on the i Interface to create a new interface for the BADI definition
6. Below screen will be appear
7. Provide a interface name
8. Double click on interface screen the below screen will appear click yes to continue and save it in your project.
9. Provide a method name and activate and go back
10. Right click implementation we will get Create BADI implementation on create
11. Provide implementation name short description and click on continue
12. Next provide a BADI implementation name and provide a implementing class name and click on continue.
13. Double click on implementation class
14. Double click on class name
15. In attribute section declare a one instance attribute
16. Go to the method section inside a method right a logic
17. Activate the BADI implementation
18. 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 statements then for the sale implementing class two different objects are created and each one is assigned to the BADI reference.
19. Create a program and call the BADI method with GET BADI and CALL BADI statement.
20. Output for newly creating instantiation
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.
1. Now the same program again run it.
2. Output for reusing instantiation.
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.
1. Let's Create a class that implements the interface IF_BADI_CONTEXT. We can’t implement this interface because it is a standard interface. I have copied IF_BADI_CONTEXT into custom interface such as ZIF_BADI_CONTEXT.
2. Inside a class I am using custom interface ZIF_BADI_CONTEXT that I have copied in a standard interface as IF_BADI_CONTEXT.
3. Now Create type and a table type in the types section.
4. Create a attribute of the table type
5. Now create a static method and provide the parameters below.
6. Declare a returning and importing parameter
7. Provide the below code. A new object of the class is created for a different context name else the previous object is retuned.
8. Now just simply call the IF_BADI_CONTEXT interface inside the class
9. Now create a report program and run it
10. Output for context specific instantiation
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 |