Instantiation of BAdIs

38

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.

1

Provide short text and continue.

2

Now create a BAdI definition.

3

Provide BAdI name , description and Continue.

4

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.

5

6

provide a interface name and double click on it.

7

YES to continue.

8

Provide a method name . Save , Activate and go back.

9

Now create a BAdI implementation.

10

Provide a enhancement implementation name and continue.

11

provide a BAdI implementation name and an implementing class name and continue.

12

Go to the implementing class.

13

Double click on the class name.

14

In the  attributes section create an instance attribute.

15

Go to the methods section.

16

Provide the below code and activate the class and go back.

17

Activate the badi implementation.

18

Lastly activate the enhancement spot.

19

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.


39.png


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

20

Program Output.

21


Now in the BAdI definition, change the Instance Creation Mode as- Reusing Instantiation.

22

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.


40.png

Now run the same program again.

23

Program output.

24


Now change the Instance creation mode as – Context Specific Instantiation.

25

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 .


41.png


Let’s create a class that implements the interface IF_BADI_CONTEXT.

26

create type and a table type in the types section.

2728

Create an attribute of the table type.

29

Create a static method and provide below parameters.

30

The idea is to create a singleton design pattern. 

31

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

34

Now create the program and run this.

36

Output.

37


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s