ABAP – Multiple implementations of a “Single implementation only BAdI”

SAPIt is a problem when you need to have multiple implementations of a BAdI which does not implicitly allow multiple implementations by its definition. How to bypass this limitation? I’ll show sample solution on an SRM BAdI called BBP_CREATE_BE_PO_NEW.

1. Check BAdI specification

In SE18 open BAdI BBP_CREATE_BE_PO_NEW and check that checkbox “Multiple use” is not selected. This means the BAdI can have only ONE active implementation.

BAdI specification

2. Create the real BAdI implementation and implementation class

Create single BAdI implementation ZBBP_CREATE_BE_PO_NEW with its implementation class called ZCL_IM_BBP_CREAT_BE_PO_NEW

BAdI Implementation and its Implementation class

3. Create supporting Z-structure

Create Z-structure ZBBP_BE_PO_TRANSFER_PROVIDER containing just one field with type of the BAdI Interface IF_EX_BBP_CREATE_BE_PO_NEW

Supporting Z-structure

4. Implementation class container for pseudo-implementations

In the implementation class create private attribute – internal table MT_BE_PO_TRANSFER of the Z-structure ZBBP_BE_PO_TRANSFER_PROVIDER

Class private internal table

5. Create pseudo-implementations

Create new Z-classes – one Z-class per each of your required psuedo-implementations. In each class, add the same interface as used in the main implementation class into the Interfaces tab. In our case we created Z-class ZCL_BBP_CREAT_BE_PO_DELV_ADDR which will handle delivery address manipulation.

Pseudo-implementation class

6. Implement class constructor and register pseudo-implementations

Create main implementation class constructor and add programatically as many entries in the class attribute (itab) as you need – one for each Z-class, each with type of the specific Z-class

Registering pseudo-implementations in constructor

7. Distribute the interface method calls to pseudo-implementation’s methods

In all interface methods of the main implementation class loop over your class attribute (itab) and call the same method with the same parameters for each line.

Distributing method calls

8. Implement interface methods in your pseudo-implementations

In each of your Z-classes implement the necessary interface methods. Each Z-class interface method will now handle just the part of data manipulation that is required.

Pseudo-implementation class method contents

Leave a Reply