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: 

Create Custom BADI and not implement all methods

Missschaaa
Participant
0 Kudos
1,729

Hi Guys,

I'm trying to create some custom BADI for our custom reports. Therefor I created BADI definition and interface with three methods in it. Now when I do an implementation of BADI and do NOT implement all interface methods, SE19 throws error that I have to implement all methods. How can I change this? Not every customer has to implement all methods of the BADI.

I saw this flag default IGNORE or default FAIL, but it looks like that it has no impact on the error if I set it to FAIL. Only setting it to IGNORE lets the message disappear. My problem is in the custom report I have some coding where the BADI is implemented. Now if I do an empty method in the BADI implementation it looks like that method is implemented an customer wants to use this BADI method, so I need a criteria to find out if a BADI method is used or not. How can I do that? Of course I could give a EXPORTING parameter lets say ED_IMPLEMENTED which I set to true or false, but does not sound that smart.

Regards
Michael

9 REPLIES 9

Sandra_Rossi
Active Contributor
0 Kudos
1,557

That's weird, I don't remember to do anything about BAdI methods I don't use, I just implement the one method I need, activate the class, the other methods are just created empty and there's no error...

I just checked by creating an enhancement spot, BAdI definition, implementation, no problem.

I guess the second part of your question is a workaround for the main issue, so I think that you don't need an answer to it, you just need to understand what's the issue with the first part.

0 Kudos
1,557

Actually it is not a syntax error in the class, but when activate the implementation, it always requires adjustment and afaik it also get problems when trying to transport some unadjusted badi.

Sandra_Rossi
Active Contributor
0 Kudos
1,557

I see this in CALL BADI documentation: ABAP Keyword Documentation (sap.com)

If a method is added to a BAdI afterwards, it may be missing in a BAdI implementation. In this case the call is executed as if the method existed with an empty implementation. Actual parameters that are bound to EXPORTING or RETURNING parameters passed by value are initialized. All other actual parameters remain unchanged.

Missschaaa
Participant
0 Kudos
1,557

Yes, i know that. Let my explain my intention more detailly.

I defined a custom BADI interface which has three methods in it. In my custom report there are lets say three coding places where the three methods are called individually. Every method stands for a time for example at init, at save, after save. Now if it gets enrolled to a customer, not every customer uses all three methods, so if he just uses one of them I normally would create a BADI implementation where i only implement the desired method and not the other two. When I do that, when activating the badi i get the attached screen in my previous post. I can activate the badi but whenever i get into it i come to this screen. And i did not test it but in my mind if i want to transport the badi implementation it gets error when releasing the transport request because system says please to adjustment at first.

So to get rid of the problem i can just say i would implement all the three methods, two of them empty. But when doing that i now get some problems with my coding implementation. I need - if doing like that - a criteria which gives me difference if method is implemented empty or method is implemented with code because in my main program where the badi is called it should stop if method is implemented empty. So i thought best way is to not implement the method and then catch not implemented exception but when doing that i get the above named problem when activating the badi implementation.

Sandra_Rossi
Active Contributor
0 Kudos
1,557

It's what I said in my answer, I don't reproduce on my system, if I implement only one method, the other method is created empty implicitly. We should investigate about how you "implement only one method", about your system version, etc.

I don't get what is the issue (apart the issue about the dump which requires some investigation).

It's difficult to me to discuss without example, here is my proposal below.

CALL BADI custom_badi->action_1 EXPORTING ... RECEIVING result = DATA(result_of_action_1).
IF result_of_action_1-verb_to_describe_action_1 = abap_false.
" STOP
ENDIF.

If empty or not implemented, it will stop.

If there is an implementation, it must always contain:

result-verb_to_describe_action_1 = abap_true.

Missschaaa
Participant
0 Kudos
1,557

But this means that I have to create a parameter lets name it rd_method_in_use in every method just to check if method is "really" implemented with code or just "fake" implemented without any code?

Sandra_Rossi
Active Contributor
0 Kudos
1,557

There are two kinds of BAdI methods concerning your topic.

  1. Those which don't impact the code to run after CALL BADI: change of variable value, display of custom screen, database update, etc.
  2. Those which impact the logic after CALL BADI (IF ... ELSE ...)

There's no problem to use the second kind of methods.

I think you are confusing "really implemented" with a BAdI method returning a boolean (or multiple choices) to select the logic to apply.

Missschaaa
Participant
0 Kudos
1,557

Hm the problem is the considered BADI is a mix of both. In my example I have a button which is above an alv tree. The button visibility is dependent on badi implementation. So no badi implementation, no button. But when badi is implemented button click reaction is that some tree entries get filtered and tree gets updated.

So first call would be true or false return to control button visibility, second call would be importing a tree entry and returning flag for each tree entry which will be looped after pushing the button. But with these two different calls I have to set some parameter optional because first call of course canot import tree entry. Of course I could differ in two different interface methods but creating one method just to proove button active or not sounds a bit overdesigned for me.

Sandra_Rossi
Active Contributor
0 Kudos
1,557

I think you're wrong, you should create 2 methods, it's better design. Simple as that.