Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

badi prob

Former Member
0 Kudos

* Declaring the handler
class: cl_exithandler definition load.

* Interface Reference
data: badi_interface type ref to ZIF_EX_BUSINESSADDIN.


start-of-selection.

call method cl_exithandler=>get_instance
changing
instance = badi_interface.

if not badi_interface is initial.
call method badi_interface->method
changing parameter = w_str.
endif.

i am new to abap oop, pls help me to understand ...

here we are taking an interface ref variable, we are passing it to cl_exithandler => get_instance and in return we are getting the instance, using the instance we calling the methods

as per sap help....

The application developer uses a factory method to create an instance of this adapter class in the application program and calls the corresponding method, if necessary.

but in badi the methods are within the interface, and there is also an adapter class which gets created as soon as a badi is defined. so what is the relation between cl_exithandler , adapter class and the interface ? what is this factory method?

pls explain in details.

2 REPLIES 2

Former Member
0 Kudos

Hi Akash,

method get_instance from the class CL_EXITHANDLER is the factory method.

 Classic BADI approach

DATA r_exit TYPE REF TO <badi_interface>.

CALL METHOD cl_exithandler=>get_instance
  CHANGING
    instance = r_exit.   " Creates an instance of adapter class using which interface methods are called

ADAPTER CLASS: Its used to call the active BADI implementations.

In the classical BAdI technology, the BAdI adapter class is automatically generated when you define

the BAdI or the BAdI interface. In new BAdI technology adapter classes are no longer required, which saves the SAP application program from having to instantiate them. Instead, at the application programu2019s runtime, the system generates a BAdI handle in the kernel, which performs the same function as the adapter class, but calls the available implementation

methods much more efficiently.

New BADI approach,
DATA r_exit TYPE REF TO <badi_interface>.

TRY.
GET BADI R_EXIT.   " Obtain BADI Handle
CATCH CX_BADI_NOT_IMPLEMENTED.
...
ENDTRY.


CALL BADI R_EXIT->ABC   " Method call to BADI Handle

If GET BADI finds no active implementation of the BAdI, it triggers the exception
cx_badi_not_implemented.

Regards,

Bharath

Edited by: bharath padmanabhan on Jun 15, 2011 2:35 AM

0 Kudos
DATA r_exit TYPE REF TO <badi_interface>.
 
CALL METHOD cl_exithandler=>get_instance
  CHANGING
    instance = r_exit.   " Creates an instance of adapter class using which interface methods are called

as per interfaces definition ...interfaces dont have any implementation part, so they are implemented by classes...is this the reason for using an adapter class?

but r_exit is an instance of the interface <badi interface> then how come it holds the instance of the adapter class ?