Saturday 19 October 2013

Classic BADI with Single Use(Single Implementation)

Scenario: Creation of Classic BADI definition with single use and creation of BADI implementation and calling the BADI implementation from program.

The current SAP system release is 605.

























Step1. Go to TCODE- SE18.










Step2. Select radio button BADI Name and provide a BADI definition name and click on Create button.
It gives a error message as 'Create operation is only possible for enhancement spots'.
As SAP provided a new concept of BADI as Kernal BADI, the classical BADI is restricted but 
still there is a way to go ahead in the system to create it.



















Step3. Provide the BADI name and go to the menu Utilities and Click on Create Classic BADI .



Step4. Provide a short description. In the properties section, the system automatically generates a BADI Class based on the BADI name. In the TYPE section, as the multiple use option is not selected, it means
 that it is a single use BADI.


Step5. Click on the Interface tab. The system also generate a Interface with no method based on the BADI name.Now double click on the interface name 'ZIF_EX_BADI_DEFN_DEMO1'.

Step6. It navigates to SE24 transaction. Now in the 'METHODS' tab, provide a method name as 'DISPLAY_MESSAGE', select the level and provide the description and activate the interface. At last  Click on the BACK button.

Step7. Now the method is added to the interface. Up to this point the BADI definition is created with interface containing an empty method.


Step8. Creating a BADI Implementation. Go to TCODE - SE19. Under the CREATE Implementation Section, Select the Radio button classic badi and provide the BADI definition name created above and click on the Create Impl. button and it 'll show a popup screen . Provide the Implementation name as 'ZBADI_IMPL_DEMO1' and click on the continue button.


Step9.  Provide a implementation short text and click on the Interface Tab.


Step10. For this implementation the system automatically creates a Implementing Class which implements the method 'DISPLAY_MESSAGE' of the interface associated with BADI definition.Now double click on the method 'DISPLAY_MESSAGE' to implement the method.


Step11. Provide some statement here and then click on the activate button and at last click on the back button.Now up to this point we crated a BADI implementation successfully.



Step12. Calling the BADI implementation form the program . Go to TCODE - SE38 and create a report program.

Step13. Create a reference variable referring to the Interface name associated with the BADI definition.
Then call the static method GET_INSTANCE of the class CL_EXITHANDLER. Pass the BADI definition name and it ll return the object of the active  implementing class to the reference variable. Activate the program and run it.


Step14. Now it calls the methods and display the output.

_______________________________________________________________________________

Step15. Further scenarios. As the badi is a single use BADI let's create another implementation of it.
Go to TCODE- SE19 and in the Create Implementation Section provide the BADI definition name and click on the Create Impl. Button. In the popup screen provide the Implementation name and click on teh continue button.


Step16. Provide a implementation short text and then click on  the interface button.

Step17. Now for this implementation a new implementing class is generated and the interface associated with the BADI definition is implemented in this class. Now double click on the method 'DISPLAY_MESSAGE'
to implement it.

Step18. Provide some statement and activate the same . At last click on the back button.


Step19.  Activate the BADI Implementation.


Step20. Run the report as per shown below.

Step21. Now for this the sy-subrc = 5 [Single_exit_multiple_active]. As our BADI definition is not a multiple use badi (single uses badi) and we have multiple implementations of it.


Step22.The output is as follows.


XXXXXXXXXXXXXXXXXXXXXXXXX


No comments:

Comments system

Disqus Shortname