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

Implement a BADI reuse code

Former Member
0 Likes
1,958

Hello Guys,

Please give me  an advice , I need to implement same code in two different methods of a BADI implementation ,   so I dont want to repeat the code in both obviously , I was thinking create third method in a global class but there I wont have  available elements of Interface of the BADI ( like methods  ) what do you recommend me for REUSE?  I appreciate your advices.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,838

There is always a recommendation for reuse!

If your two different methods are in one BADI implementation (class), why don't you add a private method to it doing the job and calling from the two methods?

Another approach would be to create an own "service" class with an appropriate method, which does the job and you can call from the both BADI methods.

11 REPLIES 11
Read only

matt
Active Contributor
0 Likes
1,838

Create a private method within the implementation class and call that.

Read only

Former Member
0 Likes
1,839

There is always a recommendation for reuse!

If your two different methods are in one BADI implementation (class), why don't you add a private method to it doing the job and calling from the two methods?

Another approach would be to create an own "service" class with an appropriate method, which does the job and you can call from the both BADI methods.

Read only

0 Likes
1,838

Hello Armin,

thanks for your answer , What do you mean with add  ? in the BADI implementation ?  could you give more details of the other option  "service" please.

thanks.

Read only

matt
Active Contributor
0 Likes
1,838

Do you have any knowledge of ABAP Objects? You see, if you can't understand the terminology, how will you understand any solution given?


This site doesn't exist to teach you ABAP basics, I'm afraid.

Read only

0 Likes
1,838

Create a Z-class in SE24 and inside that a method with the required import and export parameters. Call this method in your implementation.

Read only

0 Likes
1,838

Hello Matthew ,

Bravo ! honestly  I dont know how an answer as yours could be constructive somehow .   I was asking for advice no for criticism .

Regarding your fantastic answer,  there are hundreds of programs in the standard  which use a procedural approach , are you telling me  because they didnt use POO they dont know the  "BASICS"  ? .

Man Avoid those answers , what a terrible attitude.

Read only

matt
Active Contributor
0 Likes
1,838

BADIs are Object Oriented. To be able to use them effectively requires understanding the basics of ABAP Objects.

My question was merely to assess your level of knowledge, not to criticise. If you don't know the basics of ABAP Objects then do not use the methods suggested that utilise OO techniques. However, it would be far better if you were to learn the basics. You can do this through material on this site and others, by going on a training course or getting a book a working your way through it. If you are a competent programmer you should not find this difficult.

What you cannot do and really should not do, is request a step by step guide to your solution in this discussion. If you don't know what you're doing,you won't understand the solutions, and may be hard pressed to maintain it.

My personal view is that so much of SAP is now OO, that ABAP Objects has become part of the basic knowledge set required to work in it effectively.

Read only

matt
Active Contributor
0 Likes
1,838

There is no benefit to this. The correct OO approach is to create a private method and call that.

Read only

0 Likes
1,838

Hi Jose,

with "add" I mean: create an additional method (private) to your BADI implementation class. If you navigate to the class you are in the class builder, where you can implement your BADI methods. And also it's possible to create new methods.

The "service" idea is, that you encapsulate the reused logic into an own class with a public method (maybe static). The big advantage here is, that you could reuse the logic also for other parts in your application. But this depends in a strong way of your logic you want to seperate and reuse.

So, if you need the logic only in the BADI methods or it is only meaningful in this context, I would prefer the private method.

Additionally I want to say, you are in an OO context with the BADI methods, so use also the OO techniques in a correct way.

If you are new to OO, please take some time to learn more about it. A well defined usage of the correct concepts is very powerful for your application and it can simplify your maintenance work later. But using bad concepts can lead to frustration. That's also valid for procedural or functional programming

Kind regards,

Armin

Read only

0 Likes
1,838

Hello Armin,

    Thank you for your advices . I really appreciate them.

Read only

Patrick_vN
Active Contributor
0 Likes
1,838

What