Enhancements Using BAdIs
Transcript of Enhancements Using BAdIs
-
7/23/2019 Enhancements Using BAdIs
1/8
ABAP Keyword Documentation
Enhancements Using BAdIsGET BADI
CALL BADI
Enhancements Using BAdIs
BAdIsare created in Enhancement Builderas a part of the enhancement conceptofABAP Wor!ench" TheseBAdIs# together $ith their calling points in ABAP programs# form e%plicit enhancement optionsof theseprograms are are assigned to enhancement spots"
If BAdIs and their calling points are defined in a s&stem# enhancementscan !e made in follo$'on s&stems !&
creating BAdI implementationsin these s&stems" A BAdI consists mainl& of a BAdI implementation class$hoseinstances enhance the functions of an ABAP program at runtime in the form of an o!(ect plug'in" In theenhancement concept# a BAdI implementation is an enhancement implementation elementand isadministrated !& enhancement implementations"
A BAdI consists mainl& of a BAdI interfacethat contains the declaration of BAdI methods# and a set of filters"The filters ena!le certain BAdI implementations to !e selected for use" The follo$ing settings can !e made inthe definition of a BAdI# in addition to the selection of the BAdI interface)
Whether a BAdI is intended for single or multiple use" If a BAdI is intended for single use# onl& a single
BAdI implementation can !e used in one internal session# and one BAdI implementation must !ea*aila!le for each use"
A fall!ac BAdI implementation classcan !e specified to !e used if no BAdI implementation matchesthe filter conditions"
A BAdI can !e defined as conte%t'free or conte%t'dependent" This setting controls the instantiation of
the o!(ect plug'ins" In conte%t'free BAdIs# it is possi!le to define $hether an o!(ect plug'in can !egenerated onl& once or multiple times $ithin an internal session" +or conte%t'dependent BAdIs# theo!(ect plug'ins are associated $ith a conte%t o!(ect"
Unlie earlier BAdIs# the ne$ BAdIs are supported directl& !& the ABAP runtime en*ironment $ith the follo$ingABAP statements)
GET BADI
Generates a BAdI o!(ectas a handle for o!(ect plug'ins"
CALL BADI
Calls BAdI methodsin o!(ect plug'ins"
The BAdIs of the enhancement concept are also freel& s$itcha!le using s$itches from ,$itch +rame$or"
Notes
http://change%28%27i1%27%29/http://change%28%27i1%27%29/ -
7/23/2019 Enhancements Using BAdIs
2/8
+or a BAdI intended for single use# it is !est to al$a&s enter a fall!ac implementation class and to
implement it in the same s&stem as the BAdI"
,ee also Enhancements $ith BAdIs"
GET BADI
,hort -eference
Syntax
GET BADI { badi [FILTERS f1 = x1 f2 = x2 ...] }| { badi TYPE (a!"#
[ {FILTERS f1 = x1 f2 = x2 ...}| {FILTER$TABLE f%ab}] }[C&'TET )*].
Extras:
." ... FILTERS f1 = x1 f2 = x2 ...
/" ... FILTER$TABLE f%ab
0" ... C&'TET )*
Eect
This statement generates a ne$ BAdI o!(ectand sets the BAdI referenceto the o!(ect in a BAdI reference*aria!lebadi" This statement has a static and a d&namic *ariant"
In the case of the static *ariant# addition TYPEis not declared" The static t&pe of the reference *aria!le
badimust !e a BAdI" This determines $hich BAdI $ill !e used"
In the case of the d&namic *ariant# a character'lie data o!(ect a!"is declared for addition TYPE"
When the statement is e%ecuted# this o!(ect must contain the name of a BAdI" The static t&pe of thereference *aria!lebadimust !e a superclass for all CL1BADI1BA,E BAdI classes"
To declare *alues for the BAdI2s filters# &ou can declare the additionFILTERS
in the static *ariant# or addition
FILTER$TABLEin the d&namic *ariant"
In the case of a conte%t'free BAdI# addition C&'TETcannot !e declared" In the case of a conte%t'specific
BAdI# ho$e*er# it must !e declared"
After instancing# the program searches for BAdI implementation classesfor the BAdI as follo$s)
-
7/23/2019 Enhancements Using BAdIs
3/8
." 3nl& BAdI implementation classes are selected that are assigned to a BAdI implementationthat hasthe status active"
/" 3nl& BAdI implementation classes are selected that are assigned to a BAdI implementation 4anenhancement5 that ha*e a s$itchin the status on" If no s$itch is assigned to a BAdI implementation# itis treated in the same $a& as an implementation $ith a s$itch in the status on"
0" All BAdI implementations are selected that satisf& the a!o*e re6uirements and for $hich the filtercondition of the BAdI implementation matches the *alues declared after FILTERSor in f%ab" If no
BAdI implementations are found $ith the filter specifications# the s&stem searches for BAdIimplementations that are mared as standard implementations" If there are also none of these# thefall!ac BAdI implementation class of the BAdI is used 4if one e%ists5"
7" If# for a BAdI defined for single use# multiple BAdI implementation classes $ith matching filterconditions ha*e !een found# then a conflict solutionis carried out" A successful conflict solution resultsin e%actl& one priorit& conflict'sol*ing enhancement implementationand onl& its BAdI implementationclass is selected" If se*eral conflict'sol*ing enhancement implementations ha*e the same priorit& or ifthere are no conflict'sol*ing enhancement implementations at all# then a correct conflict solution is notpossi!le and se*eral BAdI implementation classes $ill remain in the hit list"
If the resulting hit list is suita!le for the definition of the BAdI $hich means)
+or a BAdI defined for a single use# the hit list must contain e%actl& one BAdI implementation class#
+or a BAdI defined for multiple use# the hit list ma& contain se*eral or no BAdI implementation classes#
then references to o!(ect plug'insof the found BAdI implementations are sa*ed in the BAdI o!(ect" 3!(ect plug'insthat do not &et e%ist are generated for this purpose" Whether an e%isting o!(ect plug'in is generated orreused# or $hether a ne$ o!(ect plug'in is generated# depends on $hether the BAdI is conte%t'free or conte%t'dependent# and depends on the C&'TETaddition" The precise semantics are descri!ed in the addition"
If the hit list contains no or multiple BAdI implementations although the BAdI is defined for single use# an
e%ception occurs" If the BAdI reference *aria!lebadiis gi*en a *alid BAdI reference !efore the statement inan e%ception case# this is retained# other$ise it is initiali8ed"
Notes
It is not possi!le to access BAdI o!(ects directl& using BAdI references" The references are onl& used
to call the BAdI methodsin the referenced o!(ect plug'ins $ith the statement CALL BADI" 3ther$ise#
BAdI reference *aria!les can !e used in the same operand positions as normal o!(ect reference*aria!les" In particular# this means that assignments and comparisons are possi!le"
The method 9U:BE-13+1I:PLE:E9TATI39, of the class CL1BADI1;UE-
-
7/23/2019 Enhancements Using BAdIs
4/8
To access o!(ect plug'ins directl& re6uires the corresponding references" These can !e supplied# for
e%ample# !& BAdI methods"
The BAdI reference cannot !e used to handle an& instance e*ents of a BAdI" Instead# $hen the e*ent
handleris registered# either the addition F&R ALL I'STA'CESmust !e specified using SET
+A'DLER# or an reference to an o!(ect plug'in must !e entered directl&"
Addition !
... FILTERS f1 = x1 f2 = x2 ...
Eect
After addition FILTERS# the elementar& data o!(ects x1# x2# """ must !e declared for all f1# f2# """ filters of the
BAdI" If a filter in the BAdI has the propert& Constant Filter Value at Call# onl& literalsand constantscan !edeclared" The data o!(ects must !e compati!le $ith the data t&pe of the filters" FILTERScannot !e declared
for a BAdI $ithout filters"
Addition "
... FILTER$TABLE f%ab
Eect
Using the special internal ta!le f%ab# this addition assigns *alues to the filters of a d&namicall& declared BAdI"
The internal ta!le must ha*e ta!le t&pe BADI1+ILTE-1BI9DI9G,from ABAP Dictionar&" When statement GET
BADIis e%ecuted# the ta!le must contain e%actl& one ro$ for each of the BAdI2s filters" The ta!le columns are)
9A:E of t&pe )and length 0=
for the name of the filter in uppercase letters" Declaring a none%istent filter raises a non'handlea!lee%ception"
>ALUE of t&pe REF T& da%a
A reference to a matching data o!(ect" The *alue of the data o!(ect that the reference *aria!le in,AL-Erefers to is assigned to the filter declared in 9A:E"
The column'AEis the uni6ue e& of the sorted ta!le f%ab"
Addition #
... C&'TET )*
Eect
Using the addition C&'TET# for conte%t'dependent BAdIs# an o!(ect reference *aria!le)*must !e specified#
the static t&pe of $hich is# or includes# the tag interfaceI+1BADI1C39TE?T# and $hich contains a reference to
-
7/23/2019 Enhancements Using BAdIs
5/8
a BAdI conte%t o!(ect" If )*is initial# an e%ception is raised" The addition C&'TETcannot !e entered for
conte%t'free BAdIs"
The addition C&'TETcontrols the generation of the o!(ect plug'ins as follo$s)
Without the addition C&'TET# hence for conte%t'free BAdIs# the generation of the o!(ect plug'ins is
!ased on the setting of the BAdI" Either ne$ plug'ins are generated e*er& time the statement GETBADIis e%ecuted# or an o!(ect plug'in that has alread& !een generated in the current internal session
is reused# if it is re6uired again" An o!(ect plug'in of this t&pe is a singleton in terms of its BAdIimplementation class"
With the addition C&'TET# and hence for conte%t'dependent BAdIs# the same o!(ect plug'ins are
al$a&s used for the same content of )*" These o!(ect plug'ins are singletons in terms of their BAdI
implementation class and a BAdI conte%t o!(ect"
If a BAdI implementation class implements multiple BAdI interfacesand GET BADIis e%ecuted $ithin one
internal session for se*eral of these BAdIs# then multiple BAdI o!(ects can point to the same o!(ect plug'in"This ena!les the sharing of data !et$een different BAdIs" +or conte%t'free BAdIs# this is onl& the case forreuse" +or conte%t'dependent BAdIs# multiple BAdI o!(ects from the same conte%t can point to the same o!(ect
plug'ins"
Notes
The fact that o!(ect plug'ins can either !e ne$l& generated or reused can also !e e%pressed in terms
of an o!(ect plug'in !eing stateful or stateless $ith reference to a BAdI or a conte%t"
The tag interface I+1BADI1C39TE?T can !e implemented !& an& class" Possi!le applications range
from the implementation in a local class $ithout other components that ha*e the sole purpose ofena!ling internal program conte%t administration for BAdIs# to the implementation in a glo!alapplication class in $hich the o!(ects are specificall& enhanced"
Exce$tions
%atcha&'e Exce$tions
C?1BADI1C39TE?T1E--3-
Cause:A conte%t error has occurred in the d&namic *ariant of the statement"
C?1BADI1+ILTE-1E--3-
Cause:Incorrect information $as specified regarding the BAdI2s filters in the d&namic *ariant of the
statement"
C?1BADI1I9ITIAL1C39TE?T
Cause:The reference *aria!le declared after C&'TETis initial"
C?1BADI1:ULTIPL
-
7/23/2019 Enhancements Using BAdIs
6/8
Cause::ultiple BAdI implementation classes $ere found# although the BAdI is defined for single use"
,u!class of C?1BADI193T1,I9GLE1U,E"
C?1BADI193T1I:PLE:E9TED
Cause:9o BAdI implementation class $as found# although the BAdI is defined for single use"
,u!class of C?1BADI193T1,I9GLE1U,E"
C?1BADI1U9@93W91E--3-
Cause:The BAdI declared in the d&namic *ariant does not e%ist"
%A(( BADI
,hort -eference
Syntax
CALL BADI { badi$/!"%0 aa!"%"34i5%}| { badi$/(!"%03a!"# {aa!"%"34i5%
|aa!"%"3%ab4"5} }.
Eect
Calls a BAdI method" The statement has a static and a d&namic *ariant" In !oth *ariants a BAdI reference
*aria!lemust !e specified forbadi"
In the static *ariant# a BAdI reference *aria!leof the static t&pe of a concrete BAdI classmust !e
specified forbadi# and for!"%0a BAdI method of the corresponding BAdImust !e entered directl&"
In the d&namic *ariant# a BAdI reference *aria!leof the static t&pe of the a!stract super class
CL1BADI1BA,E must !e specified forbadi" +or!"%03a!"# a character'lie data o!(ect must !e
specified that must contain the name of a BAdI method in uppercase $hen the statement is e%ecuted"
With regards to the addressing of BAdI methods# the BAdI reference *aria!le !eha*es lie an interfacereference *aria!le$ith the static t&pe of the affected BAdI interface" A BAdI method declared as a componentof the corresponding BAdI interface is addressed directl& using its name" BAdI methods declared in componentinterfacesof the BAdI interface can !e addressed using the interface component selectoror an& alias names"
The additionsaa!"%"34i5%oraa!"%"3%ab4"5assign actual parameter to the formal parameters of
the BAdI method or handle non'class'!ased e%ceptions e%actl& as descri!ed in CALL ET+&D" The e%ceptions
that can occur in d&namic accesses are also the same as those of CALL ET+&D"
The effect of the statement CALL BADIis that the specified method is called in all o!(ect plug'insto $hich the
BAdI o!(ectreferenced !& thebadirefers"
-
7/23/2019 Enhancements Using BAdIs
7/8
If the BAdI is defined for single use# thenbadimust contain a *alid BAdI referencefor a static BAdI
call" Ifbadiis initial# a handlea!le e%ception is raised"
If the BAdI is defined for multiple use# thenbadimust contain a *alid BAdI referenceor can !e initial
for a static BAdI call" If the referenced BAdI o!(ect refers to multiple o!(ect plug'ins #then the call orderis the same for e*er& CALL BADIstatement" The e%act call order can !e determined in the definition
of the corresponding BAdI implementations# if the predefined BAdI BADI1,3-TE- of theenhancement spot of the same name $as implemented for the current BAdI" If the referenced BAdIo!(ect does not reference o!(ect plug'ins# or thebadiis initial# then the statement has no effect"
In a d&namic BAdI call# a handlea!le e%ception is al$a&s raised if there is an in*alid BAdI reference in
badi"
If a method is added to a BAdI after$ards# it can !e missing in a BAdI implementation" In this case the call ise%ecuted as if the method e%isted $ith an empt& implementation" Actual parameters that are !ound toEP&RTI'Gor RET-R'I'Gparameters passed !& *alue are initiali8ed" All other actual parameters remain
unchanged"
System )ie'ds
As for a regular CALL ET+&D# the s&stem field 56$57b)is either set to = or# $hen handling non'class'
!ased e%ceptions# it is set to the *alue specified after ECEPTI&'S"
Notes
BAdI o!(ects and BAdI references can onl& !e generated using the statement GET BADI"
In the terminolog& of the enhancement concept# the statement CALL BADIis no$n as an
enhancement spot element in*ocation"
The call of a BAdI method of a BAdI defined for single use !eha*es as a method call $ith CALL
ET+&D) the called method must e%ist" In contrast# the call of a BAdI method defined for multiple userather corresponds to the triggering of an e*ent $ith RAISE E,E'T) 3ne or more methods can e%ist#
or no methods at all"
Exce$tions
%atcha&'e Exce$tions
C?1BADI1I9ITIAL1-E+E-E9CE
Cause:The reference *aria!lebadiis initial either for the static call# although the BAdI $as defined
for single use# or for the d&namic call"
C?1,
-
7/23/2019 Enhancements Using BAdIs
8/8