‎2016 May 11 11:51 AM
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.
‎2016 May 11 11:58 AM
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.
‎2016 May 11 11:57 AM
Create a private method within the implementation class and call that.
‎2016 May 11 11:58 AM
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.
‎2016 May 11 12:09 PM
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.
‎2016 May 11 1:02 PM
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.
‎2016 May 11 1:24 PM
Create a Z-class in SE24 and inside that a method with the required import and export parameters. Call this method in your implementation.
‎2016 May 11 1:39 PM
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.
‎2016 May 11 2:21 PM
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.
‎2016 May 11 2:22 PM
There is no benefit to this. The correct OO approach is to create a private method and call that.
‎2016 May 11 2:51 PM
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
‎2016 May 11 2:56 PM
Hello Armin,
Thank you for your advices . I really appreciate them.
‎2016 May 11 1:39 PM
What Matthew Billingham wrote in his first post. Though if you don't understand what he says, maybe consider creating a function module.