Professional Documents
Culture Documents
mohammad afzal
Oct 8, 2007 3:52 PM
hai freinds i want to create a custom badi, i am doing through se18 and giving zdemo and create
but it gives error that create option is possible for enhancment spots only can any one help me
how to create the custom badi
regards
afzal
2168 Views
Topics: abap
Application program simply calls the adapter class methods; it does not know which
implementations are actually being called
Adapter class methods generated by add-in management decide which implementation is
to be called
BAdi Definition
Choose Tools ->ABAP Workbench -> Utilities -> Business Add-Ins (transaction SE18)
from the SAP menu
Create a new Business Add-In containing a maximum of 20 characters and move to
Interface Tab
BAdi Implementation
In order to create an implementation for the text conversion example, the add-in (in this
case, the interface's method) needs to be filled with logic that converts the string. This
logic will be run through every time the add-in is called from the application program
Insert the desired source code for the implementation between the method
if_ex_businessaddin~method. and endmethod. statements automatically provided to you
by the system.
Save and return to the Change Implementation screen
On Activation, this implementation may be executed from the application program
How it works
-Switch on Filter-dependency while defining the interface
-Select a suitable filter element
-All methods created in the interface will have filter 'FLT_VAL' as one import parameter
-Application program provides the filter value to the enhancement method
-The method then selects the active implementation for that value
A Data element
Underlying domain may contain a maximum of 30 characters and must be of Character
type
The data element must
-Either have a search help with a search help parameter of the same type as the data
element and this parameter must serve as both the import and export parameter or
-the element's domain must have fixed domain values or a value table containing a
column with the same type as the data element
Custom data element with the criteria may also be used
Same as before
Pass the filter value as export parameter to the method
There can be more than one implementations of the same BADI definition, and in that
case only the active implementations will be executed
You can activate or de-activate any of the implementations after creation
Enhancement, interface, and associated classes generated all lie in the appropriate
application development namespace
Business Add-In implementations lie in the respective namespaces of the people who
created them
Changes made to the interface and changes made to the Business-Add-In definition are
always incompatible
-If implementations already exist for a Business-Add-In definition, they are invalidated if
you make changes to the interface. This means that their syntax is no longer correct. No
statements can be given on the runtime behavior. Avoid making changes to the interface
or the Business-Add-In definition after the transport has taken place.
-If changes to the interface are inevitable, navigate to the Class Builder for all
implementing classes and clean up the method includes of these classes (Utilities > Clean
up > Method includes)
Thanks
Murali Poli
o Alert Moderator
o Like (0)
BADI
Regards
Aneesh.
o Alert Moderator
o Like (0)
ABAP Development
Previous post Next post
I have decided to write this blog after I saw there are some old-school user- exits still being used
while enhancing standard SAP functionalities with some customer specific requirements. The
idea behind this blog is to avoid keeping so many IF conditions inside the user-exits for calling
different requirements based on certain conditions. Instead, we can create our own BADI
definition with required filter combination and also we can create multiple implementations
based on different filter combination. So that it will be easy to separate the implementations and
maintenance will be easy if any problem occurs in any of the implementations. The defined
BADI can be called from user-exit by passing runtime filter values, so that system determines the
corresponding implementation for execution.
Introduction: The common meaning extracted from this saying is that too many people
working on a single task tend to make a mess of it. Lets think of situation where too many
developers working on a single piece of ABAP code. What will happen in that case??? Yes... it
will go for a big mess. This issue is especially difficult to deal with when there are multiple
functional requirements leveraging the same custom code object, form-based user-exit, or
function-based user-exit.
While current releases of SAP have good control of doing enhancements and customizations via
BADIs, Implicit and explicit enhancement points, there still exists many user-exits (Form
based / Function based) For customer specific requirements especially in case of IDOC
extensions.
Standard SAP solution for latest IDOCs: In case of latest IDOCs for few cases SAP
provided BADI definitions (With / without filters) for making different implementations specific
to different customer specific requirements. For example in case of IDOC
SHP_OBDLV_CONFIRM_DECENTRAL04 SAP provided BADI SMOD_V50B0001.
But still there are many IDOCS available without BADI functionality for making IDOC
extensions.
Note: Please note that this blog provides a simple roadmap of how to handle such situations to
use BADI functionality instead of using user exits. I am not trying to rule out the possibility of
doing it through Standard BADIS (If any during the same process), if they are available please
use them. In this blog I am using IDOC example since at many places for standard IDOCs
still SAP is using Function based user exits for customer specific requirements.
Requirement: So lets say multiple developers were creating different integrations based on the
shipment inbound IDOC. Each integration requires a separate set of custom functionality and
therefore, its own IDOC extension.
The problem is SAP has provided only one customer exit for doing this functionality and all
developers needed to be developing in it at the same time.
How to solve: I decided to create a custom BADI definition with attributes multiple-use, filtered
and create the implementations for each different requirement and use the filters to separate the
implementations. Actually you can implement your own BADI almost anywhere you need
alternate logic execution.
1.
Use SE18 transaction to create new enhancement spot definition. In the below example
the name is given as Z_EXIT_SAPLV55K_020since this enhancement spot will be used in
customer exit function EXIT_SAPLV55K_020.
2.
3.
Now create a new BADI definition and specify that new BADI definition will be multiple
uses.
4.
Create new filter and specify filter combination. In this example we are using BADI
definition to modify IDOC shipment data.Each integration has its
own control record and out of that Message type, Message code, Message function, IDOC
Type and extension will be always unique. So it is good to
define the filter combination accordingly to separate the implementations for different
requirements.
5.
Create the BADI interface that will be inherited by each implementing class. Define the
method and maintain the parameters exactly similar to
customer-exit function, since the BADI we are creating is the replication of customer-exit
function.
The same parameters (data) are being passed via the interface method as well.
6.
Create the BADI Implementation with required filters and add the code to the method just
like you would in customer-exit function.
7.
As a final step, the BADI has to be called from the customer-exit. Define the global
BADI object with reference to BADI definition. The idea behind
defining global BADI object is to prevent instantiations unnecessarily inside IDOC data
loop.
5027 Views
Average User Rating
(5 ratings)
inShare
Comments
7 Comments
Hi Bharat,
great topic and good blog. I had forgotten about the article that Kesavadas, in the
comment below, rightfully refers to.
Thanks!
Like (0)
Sorry... I havent read the article which kesavadas was mentioned before posting my article.
It was very good article which explained very clearly about the advantage and how to
implement a custom BADI inside the Enhancement.
But I think my article will give some clear picture on separating BADI implementations in
case of IDOC extensions with proper filter combination
Thanks!
Like (0)
Regards,
Andrea
Like (1)
Improved filter support allows non-character filter types and complex filter
conditions
In this document, I have demonstrated the various steps for creating a Kernel BADI and calling it
in our own Custom program.
1. First create a Enhancement spot from SE18. Kernel Badi's belong to an enhancement spot.
Enhancement spots carry information about the positions at which enhancement options were
created. One enhancement spot can manage several enhancement options of a Repository
object. Conversely, several enhancement spots can be assigned to one enhancement option.
Enter the description and if you want you can assign the new enhancement spot to a composite
enhancement spot. Composite enhancement spots are used for the semantic grouping of simple
enhancement spots. A composite enhancement spot contains either one or more simple
enhancement spots and/or one or more composite enhancement spots of the relevant type. You
can use composite enhancement spots to combine simple enhancement spots into meaningful
units.
2. On creating the Enhancement spot, you will be directed to Enhancement Spot Editor. Now we
need to create a new BADI Definition.
4. You will find certain options for the BADI definitions as below.
Usability - Multiple use - that is, there can be several active implementations
Limited Filter Use This makes the BADI Filter-dependent - that is, you apply a
filter value to each method called (for example, a country). A different (active)
implementation is then called for each value. Possible filter values are
characterized by the filter type.
Fallback Class - Fallback class for a BADI is used if there is no active BADI
implementation. This means: The GET BADI command returns a handle to an
instance of the fallback class and the respective CALL BADI calls the methods of
the fallback class instance. As soon as there is an active BADI implementation, the
fallback class is not used any longer at runtime.
5. Now we need to add an interface to the BADI. Expand the Node of BADI definition
name and double click on node Interface. You can either add existing interface or
will be prompted to create.
6. On clicking Yes, you will be navigated to the below screen, where you can add a
method to the new interface.
Save, activate and comeback to the BADI definition screen and activate the
Enhancement Spot.
7. Next we need to implement the Enhancement spot and BADI. Right click on the
BADI definition and select Create BADI Implementation.
8. First the system will ask for enhancement implementation name. Please enter a
name and description.
9. Next it will ask for BADI Implementation name and Class name for implementing
BADI. Enter the names and click ok.
10. Next we have to implement the interface method. Expand the BADI Definition
name and double click on BADI implementation.
11. You will be directed to the enhancement implementation screen, shown below.
Double click on the Interface method and you will be prompted to create
implementation for the method.
12. On clicking yes, you will be navigated to editor for the method. Add the following code for
showing a message or anything as per your requirement. Save it and activate.
Next we will see how we can call this Kernel BADI in our Custom program.
13. Create or open an existing program in SE38. Point to the line where you need to add
enhancement option. Right click and select Create Option.
14. Give an Enhancement point or section name and Enhancement spot implementation name.
Here I have opted an Enhancement point and have entered Enhancement spot implementation
name as ZENH_IMP_TEST (which we have created before).
15. Then add the below code which is shown in the red box below.
Apart from Classic BADIs which are been called by Proxy class cl_exithandler, Kernel BADIs
are called directly with the reference to the BADI definition via GET BADI and CALL BADI
statements. That is one of the reasons why Kernel BADI is faster than classic BADI. Also in
Classic BADI, while we call it via cl_exithandler, we use the reference to the interface rather
than BADI definition
16. Now activate the program and execute it. When the cursor reaches the enhancement point,
where the BADI is called it will trigger all the active implementations of that BADI. Here we
have only one implementation and that will be triggered, which shows the below message as we
have written in the BADI implementation.
If the program fails to trigger the BADI implementation, please recheck whether everything
associated with it is Activated after the creation.
Thank You.
3574 Views Topics: abap
Average User Rating
(26 ratings)
inShare
Comments
6 Comments
14. Give an Enhancement point or section name and Enhancement spot implementation name.
Here I have opted an Enhancement point and have entered Enhancement spot implementation
name as ZENH_IMP_TEST (which we have created before).
Like (0)
Abyson Joseph Feb 23, 2014 10:33 AM (in response to Sameej T.K.)
To call a Kernel BADI in a custom program we don't need any enhancement
options, as we can just write the code anywhere. Just meant to show reader the
creation of enh option and a point in a program. While creating an option either
you could use an existing enh spot imp or can create a new one there. Rather than
explaining the topic in an atmosphere of real business scenario, I focused on
giving the reader an understanding in the concepts.
Like (0)
can you please tell me what is the diff between kernel badi and normal badi
implementation. As you have implemented in normal way.
I know that kernel badi is faster than normal classical badi. but i never understood the
kernel badi. if you dont mind can you please reply to this or create new blog on kernel
badi,,,,
Like (0)
Delete Document
Are you sure you want to delete this document?
Check this Article to know how to implement a Business Add-ins with a Example.
Author : Raj
Author's Website | Articles from Raj
Step 1:
How to find appropriate BADI for this requirement??
Put the break- point into Class CL_EXITHANDLERs GET_INSTANCE method.
Go to transaction code MM01 , create a material and try to save it. it stops at many location with
different values of EXIT_NAME. (After checking into Se18 we got the
BADI_MATERIAL_CHECK which can be use for our requirement.
It also has WMARA table as input data (Material Group and Division comes in
MARA table).
Step 2:
Go to Transaction code SE18.
Open BADI : BADI_MATERIAL_CHECK.
Go to menu option Implementation Create.
Step 3:
Give the implementation name as ZMM_MAT_CHECK.
Step 4:
Double click on the method CHECK_DATA.If you notice the input parameters we have many
data related to batch , material and storage location etc..
For our requirement we need material group and devision Which exist in WMARA.Put the
below code inside the method then activate the class and method.
if WMARA-MATKL eq A05 and WMARA-SPART eq 02.
message Material creation for this Group should be avoided for animal products!! TYPE I.
endif.
This code is just checks the material group and division.
Step 5:
Go back and Activate the implementation.
Step 6:
So now its the time to Disco !!!!!!!Upsssss Sorry its the time to test this BADI.
For this go to transaction MM01 and try to create a material.
(if you are confused use material name as CH004 ,
Industry sector as Animal Health and
Material Type as Beverages )
Click on the ENTER Button and from the view select BASIC DATA 1.
Related Posts
ADVERTISE HERE
User Comments
1.
uma gupta
October 7, 2010
hi dude
u ease my proble..
Reply
2.
Yogesh Patil
October 18, 2010
Hi Friends,
I have total 4.5 Years of Exp. in SAP-ABAP, I gone through lot of documents but the way
these document and designed and presented on this portal are amazingcomments in
between like Brett Lee Bounser and Its a time to Disco
I mean to say apart from work there is something different which I liked most
No doubts about Document they are really very well documented and User friendlybut
to Present each and every thing you should have proper wayI appreciate this way of
publishing document
Thanks a lot& I appreciate UR effortsGood Job Done Keep it up!!!
Thanks & Regards,
Yogesh Patil
Reply
3.
asha
November 19, 2010
Elmira
August 12, 2011
4.
rakesh
November 29, 2010
hi
i am rakesh the way of your presention is very good
superb keep it up guyes
Reply
5.
BAdi Beginner
6.
Kalyan
April 18, 2011
7.
sai
June 5, 2011
Reply
8.
Rajiv Das
June 11, 2011
Awesome Presentation.I can see you in front of me, as u teaching in a light mode,..
Reply
9.
akein
June 22, 2011
Priceleesss!!!
Reply
10.
Nooruddin
June 22, 2011
Reply
11.
kevin
June 23, 2011
12.
venky
July 21, 2011
13.
sanju
July 25, 2011
Hi Dear,
Can u help me out to know how to know its edit implementation of badi or create
implementation. And again within dat which radio button to choose with sm examples.
Thanks
Sanju
Reply
Raj
July 25, 2011
Hi Sanju ,
Please find my comments below:
how to know its edit implementation of badi or create implementation
BADI is something is provided by SAP standard team what we do is we create an
implementation for it.
You cant edit the standard BADI.What we do is we create an implementation for
it and we modify the created
implementation.
And again within dat which radio button to choose with sm examples.
Its not clear what you want to ask.may be you are asking for.Can you put some
light on it.?
thanks
Raj
SAP IGnite.
Reply
14.
venu
July 26, 2011
Good
Reply
15.
Oka
July 27, 2011
Nice tutorial
Thanks
oka
Reply
16.
Arumugam
August 4, 2011
Reply
17.
Thanks
September 23, 2011
18.
Abhinesh Sinha
January 31, 2012
Hi,
It seems as somebody is teaching infront of me. It is presented in a very easy and
understandable way. It attracts the Reader attention.
Thanks for your kind support.
Reply
19.
ramya
February 15, 2012
hi raj,
am a hr abaper i got a requirement to set a default value for the field( id number) in
infotype 185 and subtype 02, i already created a classic badi zhrpadooinfty so using
this i need to set the default value, i asked my team leader he asked me to do using
implict enhancement so i am unable to do please help me on this.
thanks & regards
ramya
Reply
Raj
February 15, 2012
Hi Ramya,
If your question is how to implement the implicit Enhancement :
check out : How to implement Implicit Enhancement
If the code which you have placed in the BADI is not working thn and thn follow
your leads method.
Please paste the code which you are trying with program name so that i can check
it out in my system.
thanks & Regards,
SAP Ignite
~Raj
Reply
20.
ramya
February 16, 2012
Hi Raj,
i have return the below code in my badi (before_ouput
method) *************Setting default value for field ID number in IT 185***********
**************
DATA: i0185 TYPE p0185.
if ipsyst-ioper = INS and innnn-infty = 0185.
CALL METHOD CL_HR_PNNNN_TYPE_CAST=>PRELP_TO_PNNNN
EXPORTING
PRELP = innnn
IMPORTING
PNNNN = i0185.
MOVE PANNOTAVBL to i0185-icnum.
CALL METHOD CL_HR_PNNNN_TYPE_CAST=>PNNNN_TO_PRELP
EXPORTING
PNNNN = i0185
IMPORTING
PRELP = innnn.
endif.
for my classic badi the definition name is HRPAD00INFTY
Reply
21.
Chetan
March 16, 2012
22.
sharmistha
April 10, 2012
hii raj,
can u plz explain me why we chose badi_material_check.
i m new in badi.
Raj
April 11, 2012
Hi Sharmistha,
As i mentioned in the post. the BADI BADI_MATERIAL_CHECKs Check_data
method is triggered
during creation of the material .
we want when use is creating a material validation is done so the triggered timing
is perfect.
Also whatever data we want to validate it contains the the importing parameter of
the badi so
it can be used.
NOTE : there might be more thn one BADI who fulfill ur requirement ( triggering
time , proper importing data )
You can use any badi at that time,no restriction on it as such.
Please get back if i am not clear .
Thanks
RAJ
SAP IGnite.
Reply
sharmistha
April 11, 2012
23.
sharmistha
April 11, 2012
Hii,
when i create implementation through se18 ,i got the method
method IF_EX_BADI_MATERIAL_CHECK~CHECK_MASS_MARC_DATA.
which is diffrent from ur method method
IF_EX_BADI_MATERIAL_CHECK~CHECK_DATA.
and when i write the code inside the method like
method IF_EX_BADI_MATERIAL_CHECK~CHECK_MASS_MARC_DATA.
if WMARA-MATKL eq A05 and WMARA-SPART eq 02.
message Material creation for this Group should be avoided for animal products!!
TYPE I.
endif.
endmethod.
it shows a error Field WMARA-MATKL is unknown. It is neither in one of the
specified
tables nor defined by a DATA statement . . . . . . . . . .
what to do?
plz help
sharmistha
Reply
Raj
April 11, 2012
Hi
its very basic thing.all the bad might not have same importing parameters.
WMARA Is available in my badi .please check the signature of thwarting badi
which you are trying to use.it might not contain WMARA as its importing
parameter.
There might be different parameter which contains the data.
Thanks
Raj
SAP IGnite
Reply
24.
sharmistha
April 11, 2012
i just copy paste ur badi which u post ..but it shows the same error..and the badi have a
importing parameter wmara,which i check on double clicking on check_data
also tell me plz why ur method is different from my method like
method di IF_EX_BADI_MATERIAL_CHECK~CHECK_MASS_MARC_DATA.
which is diffrent from ur method method
IF_EX_BADI_MATERIAL_CHECK~CHECK_DATA.
i work on ecc 6.0.
thanks .
sharmistha
Reply
25.
Harikrishna
August 3, 2012
Hi Experts,
My requirement is, while creating a service using tcode ML81N, If the reference number
already exists means, then one error message has to be displayed.
Is there any BADI or User Exit available for this., please let me know.
Thanks in Advance.
Harikrishna
Reply
26.
Tab
September 13, 2012
Dear raj,
Thanks for the wonderful go thru of BADI implimentation, but I just wonder how and
where is the method CHECK_DATA being called when creating a material. I mean there
must be a call to the implemented method also during the flow of the transaction.
Reply
Raj
September 15, 2012
Hello Tab,
As i explained the BADI is a hook. Standard SAP creates it and place it in the
code.
That code contains call to the appropriate method ( like CHECK_DATA )
so in implementation phase you just need to implement it using Se19 ,
As the code is already placed to make a call it will trigger your implication
automatically.
Thanks
~Raj
Reply
27.
Harshal
September 29, 2012
28.
Rekha
Hi Raj,
I have seen so many articals and explanation in net regarding BAdi, Userexits , but u r
amazing yar, realing Happy & thanks a lot for u r effort.
Thaks,
By
Rekha.:-?
Reply
29.
Prem
July 10, 2014
Raj
You Explained these stuff in simple language that everyone can understand ..Thanks for
sharing this good work
Prem
Reply
30.
moshe
July 30, 2014
Hello Friends,
I have created a custom Badi definition ,interface, methods,class in the Enhancement Spot,
i need to call the custom badi in the executable program.
my problem is: while getting the instance of the interface by using
CALL METHOD cl_exithandler=>get_instance
here it goes to dump since there ie no entry in the table sxs_attr what can i do for that.
Thanks in advance.
Arun.
powered by plista
Jul 08 11
let me know ur mail id . I will forward you the right document with a sample program which
explains the one that you are trying .
Find some extract from the document below. This will explain how to handle
CALL METHOD CL_EXITHANDLER=>get_instance
RB.
***********************
*&APPLICATION LOGIC
&----
*& EVENTS
INITIALIZATION.
CALL METHOD CL_EXITHANDLER=>get_instance
CHANGING
INSTANCE = INSTANCE.
IF INSTANCE IS INITIAL.
MESSAGE E112(0) WITH 'ERROR IN BADI'.
ENDIF.
AT SELECTION-SCREEN.
IF ( R1 NE 'X' ) AND ( R2 NE 'X' ) AND ( R3 NE 'X').
MESSAGE E111(0) WITH 'INVALID SELECTION'.
ENDIF.
START-OF-SELECTION.
IF R1 EQ 'X'.
CALL METHOD INSTANCE->GET_CONNID
EXPORTING CARRID = P_CARRID
IMPORTING CONNID = P_CONNID.
IF NOT P_CONNID IS INITIAL.
WRITE : /20 'CONNID = ', P_CONNID .
ENDIF.
ELSEIF R2 EQ 'X'.
hi raj...
im having the same problem , my badi oriented data not available in table SXS_ATTR .
it shows a dump error as :
Short text
Exception condition "DATA_INCONS_IN_EXIT_MANAGEM" raised.
What happened?
The current ABAP/4 program encountered an unexpected
situation.
Error analysis
A RAISE statement in the program "CL_EXITHANDLER================CP" raised
the
exception
condition "DATA_INCONS_IN_EXIT_MANAGEM".
Since the exception was not intercepted by a superior
CL_EXITHANDLER================CP
Include
CL_EXITHANDLER================CM001
Row
155
Module type
Module Name
(METHOD)
GET_INSTANCE
Plz give me the solution ya . or else sent some document to my id get from my business card .
Thanks & Regards
Deepa.
Dec 08 18