Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
jyothi7
Explorer
561

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: 

  • Newly created instantiation 
  • Reused instantiation 
  • Context-dependent instantiation 

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 

jyothi7_0-1719466066696.png

2. Provide a short description and continue, save it in your package 

jyothi7_1-1719466066698.png 

3. Now create a BADI definition 

jyothi7_2-1719466066699.png         

4. Provide a BADI name, description and continue 

jyothi7_3-1719466066700.png

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 

jyothi7_4-1719466066701.png

6. Below screen will be appear 

jyothi7_5-1719466066703.png

7. Provide a interface name

jyothi7_6-1719466066704.png

8. Double click on interface screen the below screen will appear click yes to continue and save it in your project.  

jyothi7_7-1719466066705.png     

9. Provide a method name and activate and go back 

jyothi7_8-1719466066706.png

10. Right click implementation we will get Create BADI implementation on create 

jyothi7_9-1719466066707.png

11. Provide implementation name short description and click on continue 

jyothi7_10-1719466066709.png

12. Next provide a BADI implementation name and provide a implementing class name and click on continue. 

jyothi7_38-1719467129964.png

13. Double click on implementation class 

jyothi7_12-1719466066711.png

14. Double click on class name 

jyothi7_13-1719466066712.png

15. In attribute section declare a one instance attribute 

jyothi7_14-1719466066714.png

16. Go to the method section inside a method right a logic 

jyothi7_15-1719466066715.png

17. Activate the BADI implementation 

jyothi7_16-1719466066716.png

18. Lastly activate the enhancement spot 

jyothi7_17-1719466066717.png

 

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. 

jyothi7_0-1719470366289.png

19. Create a program and call the BADI method with GET BADI and CALL BADI statement. 

jyothi7_19-1719466066719.png

20. Output for newly creating instantiation 

jyothi7_20-1719466066720.png

 

Now in the BADI definition, change the instance creation mode as  reusing instantiation. 

jyothi7_21-1719466066721.png

 

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. 

jyothi7_22-1719466066722.png

 

1. Now the same program again run it. 

jyothi7_23-1719466066723.png

2. Output for reusing instantiation. 

jyothi7_24-1719466066724.png

 

Now change the instance creation mode as context specific instantiation 

jyothi7_25-1719466066725.png

 

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. 

jyothi7_26-1719466066726.png

 

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. 

jyothi7_27-1719466066727.png

2. Inside a class I am using custom interface ZIF_BADI_CONTEXT that I have copied in a standard interface as IF_BADI_CONTEXT. 

jyothi7_28-1719466066729.png

 

3. Now Create type and a table type in the types section. 

jyothi7_29-1719466066731.png

jyothi7_30-1719466066734.png

4. Create a attribute of the table type 

jyothi7_31-1719466066736.png

5. Now create a static method and provide the parameters below. 

jyothi7_32-1719466066738.png

6. Declare a returning and importing parameter 

jyothi7_33-1719466066740.png

 

7. Provide the below code. A new object of the class is created for a different context name else the previous object is retuned. 

jyothi7_34-1719466066743.png

8. Now just simply call the IF_BADI_CONTEXT interface inside the class 

jyothi7_35-1719466066745.png

9. Now create a report program and run it 

jyothi7_36-1719466066747.png

10. Output for context specific instantiation 

jyothi7_37-1719466066750.png

 

2 Comments
Mohanreddy
Explorer

Excellent blog

Divya_palem
Explorer

Helpful Information, Thank you

Labels in this area