Thursday, January 16, 2014

How to Find BADI-Different Methods Every ABAPer Should Know

finding-badi-using-different-methods
Finding BADI using different methods every ABAP'er should know. It is another way of implementing enhancements to the standard programs with out modifying the original code. BADI’s are implemented using OO ABAP programming technique. Technically a BADI is nothing but an interface.



How to Find BADI-Different Methods Every ABAPer Should Know

Each BAdi consists of the method with out implementation called as BAdi definition. We need to create classes to write the abap code by implementing the methods called as BAdi implementation.




TCODES for BADI Definition and Implementation

Se18 is the tcode for BAdi definition. 

Se19 is the tcode for BAdi implementation. 

The interface name for a BAdi will be as below. 

Ex:- IF_EX_<BAdi NAME> 

The class name for a BAdi will be as below. 

Ex:- ZCL_EX_<IMPLEMENTATION NAME> 


Advantages of using BADI's

The main advantage of using BADI’s is , we can create multiple implementations for a single BADI definition. 

Where as with the exits, we can create a single implementation. i.e A single project for a enhancement

We cannot create another project (implementation) for enhancement which is already used. That is why we go for BAdi’s.


Finding BADI's Using Different Methods


As an ABAP developer writing code may not be problem however where to write the code is always the key point to think of.

These different methods should help the ABAP developer to find best suited BADI for their requirement.


The BAdI’s can be found in the following ways


1. Through SPRO


2. Through ST05 -> SQL Trace and Buffer Trace (Performance Analysis)


3. Through SE24 -> CL_EXITHANDLER.


4. Through function module SXV_GET_CLIF_BY_NAME.


Apart from the above mentioned methods we can also find the BADI using the two methods below, Though not very effective but it‘s a GOOD-TO-KNOW information.


5. Through SE30 Runtime analysis


6. Through TADIR table entry.



Every method has been explained with screen shots and examples, hope this post helps you to know different methods for finding BADI.




1) Finding BADI through SPRO Transaction Code


The most basic method is searching through SPRO.

For example here we are searching for all the BAdI for Purchasing (This includes both PR and PO in the Material management module)


Step1. 

Execute Transaction SPRO

-> SAP Reference IMG

-> Material management (As our requirement specific to MM module)

-> Purchasing.


Finding-BADI-through-SPRO-Transaction-Code



Navigate through this node you would find the Node Business Add-In’s for Purchasing NODE.


Finding-BADI-through-SPRO-TCode
Read through the Documentation available and check if the BAdI satisfies your requirement and then create an implementation. 

It is not mandate that the BAdI node will appear in the same manner for other module. 


We need to navigate through the all the nodes and find the BAdI node. For example In Purchasing we directly get the NODE business add-in however if we navigate through Sales and Distribution we get under the system modification.


Finding-BADI-through-SPRO-Transaction



Though this gives us all the BAdI that we have for the given module however it‘s not very specific to the transaction we may be looking for.



The Next method is the one through ST05. This answers to our problem, we can find all BAdI that trigger for a given transaction code.





2) Finding BADI through ST05 Transaction Code -> Performance analysis


This method is based on the fact that all BAdI are registered in SAP database tables and during a transaction execution if any BAdI is called then these tables will surely be accessed. 

The BAdI database tables are SXS_INTER, SXC_EXIT, SXC_CLASS and SXC_ATTR. 

These tables are always accessed by the views V_EXT_IMP and V_EXT_ACT. 

When we create a trace for the given transaction we can filter the trace by these view names to get all BAdI.


Step1. 

Switch on the TRACE through Transaction ST05 (Performance analysis) and set the flag for ‘BUFFER TRACE’ ‘SQL TRACE’ and activate the trace.

Finding-BADI-through-ST05-Transaction-Code

Step2. 

Execute the transaction for which we need to find the BAdI, in our case it ME52N. Navigate through the transaction like change a data, check the document and save etc doing so the trace would capture all BAdI that would trigger on these events.



Step3. 

Execute Transaction ST05 and deactivate the Trace -> display trace. 

This would popup the screen ‘Set Restriction for displaying trace’. 

Under the field Objects fill values and hit OK.


Finding-BADI-through-ST05-Transaction


Finding-BADI-through-ST05

Finding-BADI-through-ST05-Code
Step4. 

Export the trace list to an excel document by hitting on the Trace list option in the MENU OPTIONS and SAVE as LOCAL file.


Finding-BADI-through-ST05-TCode
And save in the desired location.



After the download, excel would look like below.

Finding-BADI-through-ST05-To-excel



The BAdI names are in the Statement field under col K.

Delete all the unwanted cols and then read through the definition documentation to understand if the BAdI will serve our purpose.

3) Finding BADI through SE24 Transaction Code -> CL_EXITHANDLER.


This is a very simple but efficient method to find the BAdI for a give transaction.


Step1. 

Execute Transaction SE24 and enter the class name as CL_EXITHANDLER. There would be numerous methods with this class but we are interested only in GET_INSTANCE method.


Step2. 

Double click on the method name and place a break-point on the ‘CALL METHOD cl_exithandler=>get_class_name_by_interface’.

Finding-BADI-through-SE24-Transaction-Code

Step3. 

Now execute the transaction for which the BAdI is required.

The code processing would stop at the break-point we have applied, click on the EXIT_NAME in the Changing parameter. 

The parameter EXIT_NAME holds the name of the BAdI. Take a note of the BAdI and hit F8. 

If for instance we are looking for a BAdI while saving the document then when the SAVE button is hit processing would stop at the break point and would give the name of the BAdI that would trigger at the SAVE event.


Finding-BADI-through-SE24-Transaction
The next method is same the above only that instead of putting a break point at CL_EXITHANDLER we can place a break point in the function module SXV_GET_CLIF_BY_NAMEat CALL FUNCTION 'SXV_ADD_PREFIX and execute the transaction.


Finding-BADI-through-SE24
The exporting parameter ‘NAME’ holds the value at the BAdI name.


Finding-BADI-through-SE24-TCode


Take a note of the BAdI that would trigger based on the requirement.


4) Finding BADI through Function Module SXV_GET_CLIF_BY_NAME.




Using the Function Module SXV_GET_CLIF_BY_NAME.

How to use this Function Module to Identify a BADI for a Transaction.

Step 1

Go to SE37 and display the Function Module SXV_GET_CLIF_BY_NAME.

Step 2. 

Put a break point at the ENDFUNCTION of the Above mentioned Function Module.

Step 3.

 Run the Transaction for which you want to search a BADI.



Note: For every operation the Code Breaks and Function Module return some values in its Parameters.

In the Parameter CLIF and NAME. you will get the BADI or Exit name.


Now the question is how to identify whether it is a BADI or Exit. Answer is, Parameter PREFIX of the Function Module.

If this is CL_EX then it is a BADI else it is a Exit. Example is shown in the below Screen shot. 

A BADI for Transaction FPP2 when you click on SAVE.


Finding-BADI-through-Function-Module-SXV_GET_CLIF_BY_NAME



Hope this document helps people who dont know this method of finding a BADI.


5) Finding BADI through SE30 Runtime Analysis.

The Runtime analysis measures the CPU time required by ABAP statements. The most important are the database access, context statements, Modularization units like Perform Call function Call screen Call transaction etc, Internal Table operations like append collect Insert etc, Data transfer like read dataset etc and for our specific requirement the ABAP object statements Though there are many other statements that Runtime Analysis measure, we may not move into details of that.


Once we have the hit list from the SE30, we can search through the HIT LIST for METHOD cl_exithandler.

Execute Transaction SE30 and under the Current session tab enter the transaction ME52N (as used through out this document) and execute. 

Flow through the transaction and save and exit. So we now have the Runtime analysis available for the transaction we just executed, Search through the HIT LIST for “CL_EXITHANDLER”. Select the line and then in the 

Menu bar -> Goto -> Display Source code.


This would take us to the code where either the BAdI name is directly passed in the instance or through a variable. if its through a variable double click on the variable for the variable definition. 

The variable would obviously be TYPE REF to an interface name .


IF_EX_<BAdI name>.

Any thing after the IF_EX is the BAdI name.


Finding-BADI-through-SE30-Runtime-Analysis



Finding-BADI-through-SE30-TCode

Finding-BADI-through-Runtime-Analysis


In the above case

lc_cacl_character_input type ref to if_ex_cacl_character_input.

Then cacl_character_input is the BAdI name.


6) Finding BADI through TADIR table entry


Lastly we can find some of the BAdI names from the TADIR table entry. 

Just as we can find the user exit from TADIR, BADI name can also be retrieved there. 

Though this is a good method for finding User exits however for BAdI this is just good-to-know information, the reason being that the BAdI name is fetched based on the Development class or the package. 

It may so happen that the package may contain all the BAdI provided by SAP for that transaction or the BAdI may exist in another Package which is accessed when the transaction is executed.

Consider the Example below.

Execute Transaction Se11 and display table TADIR. 

Execute TADIR for table entries.

Enter the following values.

Program ID (PGMID) : R3TR.

OBJECT : SXSD (For user exit use ‘SMOD’)

Development Class (DEVCLASS) : MEREQ (for transaction ME52N)



data-browser-for-finding-badi

And execute.


finding-badi-for-table-tadir

Though ME52N has many other BAdI which are called however they exist in the package ME.


Decide which method suits better to your needs and requirements before using these different methods to find BADI's.

  

"You found the information helpful and want to say thanks? Your donation is enough to inspire us to do more. Thanks a bunch!"

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Categories

ABAP (1) ABAP Interview Questions (112) ABAP Open SQL Statements (1) ABAP Syntax Rules (6) ABAP WORKBENCH (2) ABAP-Interview-Questions (52) ALE IDOC (6) ALE IDOC Interview Questions (6) ale-idoc (6) ALE-IDOC-Interview-Questions (19) ALV Interview Questions (5) ALV-Interview-Questions (22) BADI (2) BAPI (1) BAPI Interview Questions (1) BAPI-Interview-Questions (14) BDC (6) BDC Interview Questions (6) BDC-Interview-Questions (9) big data (2) big data interview questions (1) Classical Reports Interview Question (3) Classical-Reports-Interview-Questions (22) Conditional Statements (1) Cross Applications (3) Cross-Applications (14) Data Dictionary (22) Data Type Questins (1) Data types (1) Data-Dictionary (48) Data-Type-Questins (6) Dialog programming (5) Dialog Programming Interview Questions (4) Dialog-Programming (30) DOMAIN Interview Questions (1) Domain-Interview-Questions (8) Function Module (2) hadoop (2) hadoop interview questions (2) hdfs (1) IDoc Tutorials (6) Interactive Report Interview Questions (4) Interactive-Reports-Interview-Questions (22) Internal Tables (1) interview questions (1) Lock Object Interview Questions (1) Lock-Objects-Interview-Questions (10) Logical Database (1) Modularization Interview Questions (4) Modularization-Interview-Questions (25) Module Pool Programming (5) Module-Pool-Programming (39) modules in sap (1) Object Oriented ABAP (19) Object Oriented ABAP Interview Questions (15) object-oriented-abap (2) Object-Oriented-ABAP-Interview-Questions (34) OOABAP (9) Reports (14) Reports Interview Questions (9) Reports-Interview-Questions (19) RFC (1) RFC Interview Questions (1) RFC-Interview-Questions (14) RICEF (1) RICEF Objects (1) SAP (4) SAP ABAP (4) SAP ABAP Interview Questions (42) SAP ABAP Introduction (46) SAP ABAP Message Types (2) SAP BADI Interview Questions (2) SAP Basics (71) SAP Books (2) SAP Certification (1) SAP CONSULTANTS (5) SAP CRM (1) SAP ENHANCEMENTS (3) SAP EXITS (2) SAP EXITS ( SAP ENHANCEMENTS ) Interview Questions (1) SAP Free Books (1) SAP HR (2) SAP Lock Object (1) sap modules (2) SAP Open SQL Statements (1) SAP R/3 Architecture (4) SAP Search help (1) SAP Smartforms (1) SAP Smartforms Interview Questions (2) SAP Tables (5) SAP Tcodes (10) SAP Views (1) SAP Webdynpro ABAP (12) SAP Work Processors (2) SAP Workflow (3) SAP-BADI-Interview-Questions (11) SAP-Enhancements (39) SAP-Exits (39) SAP-Exits-Enhancements-Interview Questions (3) SAP-HANA (1) SAP-HANA-Interview-Questions (1) SAP-Smartforms-Interview-Questions (2) SAP-Workflow (3) Scripts (3) Scripts Interview Questions (2) Scripts-Interview-Questions (32) Search Help Interview Questions (1) Search-Help-Interview-Questions (9) Smartforms (1) Table Maintenance Generator (1) Table-Maintenance-Generator (4) Tables in SAP (2) Tables Interview Questions (3) Tables-Interview-Questions (3) Type Group Interview Questions (1) Type-Group-Interview-Questions (7) Variable Declaration (1) Views Interview Questions (1) Views-Interview-Questions (5) Webdynpro (12) what is big data (1)

Protected Blog

 
This blog is not affiliated to SAP AG |SAP is trademark of SAP AG |The information collected from various sources use information with your own risk.