Application Development and Automation 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: 
Read only

call different badi implementation although is not multiple use

Former Member
0 Likes
1,289

Hi,

we got the problem, that we have to implement a BADI that is not is multiple use.

With oder words:

We can either implement Badi (A) oder Badi (B).

So we decedied to implement Badi (A)

As a result the statement:

     GET BADI lr_data_provision.

returns Badi (A).


We got now the requirement that - in special cases - not Badi (A) should be called. Instead  Badi (B) should be called.

Is there a special ABAP statement where I can overwrite the implementing class in lr_data_provision?


Thanks

Regards

Mario



1 ACCEPTED SOLUTION
Read only

ceedee666
SAP Champion
SAP Champion
0 Likes
1,182

Hi Mario,

I would suggest the following approach to implement this requirement using the strategy pattern.

1.) Implement one BAdI S. This is the BAdI that is active in the BAdI customizing.

2.) Inside S check for you special case. If the special case is present call implementation class B, otherwise call implementation class A.

This way you don't need any modifications or something like this.

Christian

Hi Mario,

I would suggest the following approach to implement this requirement using the strategy pattern.

1.) Implement one BAdI S. This is the BAdI that is active in the BAdI customizing.

2.) Inside S check for you special case. If the special case is present call implementation class B, otherwise call implementation class A.

This way you don't need any modifications or something like this.

Christian

6 REPLIES 6
Read only

ceedee666
SAP Champion
SAP Champion
0 Likes
1,183

Hi Mario,

I would suggest the following approach to implement this requirement using the strategy pattern.

1.) Implement one BAdI S. This is the BAdI that is active in the BAdI customizing.

2.) Inside S check for you special case. If the special case is present call implementation class B, otherwise call implementation class A.

This way you don't need any modifications or something like this.

Christian

Read only

Former Member
0 Likes
1,182

Hi Christian,

nice approach!!

Would you tell me how to/which ABAP statement  to use to call e.g. the implementation of BADI (B)

Unfortunatelly the BADI has no constuctor; I guess that is the SAP intention.

A BADI is compareable to a factory; That is, why you habe to use the GET BADI statement.

Regards

Mario

Read only

0 Likes
1,182

Hi Mario,

the BAdI is implemented using a class that implements a certain interface. Simply instantiate the BAdI implementation class in your custom code. So instead of GET BADI simply use data badi_ref = new <badi implementation class>.

The only drawback I see for this approach is that you code against a specific class implementation not against a specific BAdI implementation. That means if e.G. SAP changes teh implementation class used to implement BAdI Implementation X from Class cl_badi_impl_1 to cl_badi_impl_2 your code would still invoke cl_badi_impl_1. However, I see this a merely a theoretical issue.

Christian

Read only

Former Member
0 Likes
1,182

Thanks

I already coded a variant of your suggestion!

Works fine!

10 Points!

Read only

PeterJonker
Active Contributor
0 Likes
1,182

Can you not place the code in one BADI with a conditional expression:

if condition badi a

   code which is in badi a

elseif condition badi b

      code which is in badi b.

endif.

Read only

0 Likes
1,182

Hi Peter,

you missunderstoud my question.

Instead of calling BADI (A) (wich is customized as implementation) I want to call BADI (B).

Regards Mario