2018 Oct 19 7:45 PM
Hello ABAP'ers,
I have an Enhancement Spot BAdi (FAGL_LIB) that I want to call twice. (It's a kernel-type, new. It allows multi-use, but it has no filters) The first call will use an SAP-provided Class, which I don't want to modify. The second call will use my own Class with my custom logic. I need them to execute in that order. I am confused on the difference between creating multiple Enhancement Implementations, versus creating multiple BAdi Implementations within the same Enhancement Implementation.
Functionally both of these setups seem to work the same, in that both of my Classes are called up at the Spot, one after the other. I have seen numerous postings that explain that the execution order of multiple Enhancement Implementations for an Enhancement Spot cannot be controlled (without another special BAdi). However, in my testing with multiple BAdi Implementations within the same Enhancement Implementation, I have seen that it appears to always execute the BAdi Implementations in the order which they are shown in the Enhancement Implementations screen, which happens to be according to BAdi Implementation technical name. Therefore I feel like I can guarantee the order of execution by creating one Enhancement Implementation containing both BAdi Implementations and naming appropriately.
Can anyone confirm or deny this behavior?
Thanks,
Bryan
2018 Oct 22 3:53 PM
"The reason that I could understand behind this behavior is the implementations are stored in a table SXC_ATTR with Implementation Name (IMP_NAME) as the table key which when retrieved during implementation call are obviously sorted as per their names in alphabetical order."
Maybe I've misunderstood what you're saying, but you seem to say that the implementations are done in alphabetical order, as that is the order in which they're stored in the table. If that is what you are saying, then I'm afraid you are dangerously wrong.
In relational databases - Oracle, HANA etc. -, there is no concept of ordering on a table. The sort order is undefined. You absolutely cannot rely on it. To do so is to introduce a possibly very hard to find bug.
This misunderstanding crops up frequently, even among experienced programmers. See my comments on this blog: https://blogs.sap.com/2018/10/02/semi-automatic-custom-code-adaptation-after-sap-s4hana-system-conve... Records tend to remain in the table in the order they're entered - hence the idea that there is an order. But if some are removed, and others inserted and then there's database reorg, you'll find that the order is no longer as expected.
So, for the OP.
"Therefore I feel like I can guarantee the order of execution by creating one Enhancement Implementation containing both BAdi Implementations and naming appropriately."
No. You can't and you must not.
2018 Oct 19 8:19 PM
Hi Bryan,
Although SAP's standard documentation about multiple implementations suggests that we cannot control the order of implementation call, but I have also observed in couple of my experiences with multiple BAdI implementations that the implementations always seem to execute in the order in which they are shown in the Enhancement Implementations screen, which happens to be according to BAdi Implementation technical names. The reason that I could understand behind this behavior is the implementations are stored in a table SXC_ATTR with Implementation Name (IMP_NAME) as the table key which when retrieved during implementation call are obviously sorted as per their names in alphabetical order.
Not sure why it is a common understanding that order of implementation cannot be controlled.
Regards.
Sapeksh
2018 Oct 22 3:13 PM
2018 Oct 22 3:54 PM
2018 Oct 19 9:22 PM
2018 Oct 22 3:19 PM
2018 Oct 22 3:53 PM
"The reason that I could understand behind this behavior is the implementations are stored in a table SXC_ATTR with Implementation Name (IMP_NAME) as the table key which when retrieved during implementation call are obviously sorted as per their names in alphabetical order."
Maybe I've misunderstood what you're saying, but you seem to say that the implementations are done in alphabetical order, as that is the order in which they're stored in the table. If that is what you are saying, then I'm afraid you are dangerously wrong.
In relational databases - Oracle, HANA etc. -, there is no concept of ordering on a table. The sort order is undefined. You absolutely cannot rely on it. To do so is to introduce a possibly very hard to find bug.
This misunderstanding crops up frequently, even among experienced programmers. See my comments on this blog: https://blogs.sap.com/2018/10/02/semi-automatic-custom-code-adaptation-after-sap-s4hana-system-conve... Records tend to remain in the table in the order they're entered - hence the idea that there is an order. But if some are removed, and others inserted and then there's database reorg, you'll find that the order is no longer as expected.
So, for the OP.
"Therefore I feel like I can guarantee the order of execution by creating one Enhancement Implementation containing both BAdi Implementations and naming appropriately."
No. You can't and you must not.
2018 Oct 22 10:44 PM
Ok, message received, thanks Matthew. I was not very keen on relying on the "natural" order of entries in a table to guarantee the execution order.
Bryan
2018 Oct 23 5:49 AM
Hello,
you can control the execution of the BAdI's with BAdI BADI_SORTER. Here is a blog about it.
https://blogs.sap.com/2016/10/02/badisorter-with-kernel-badi-and-other-sorting-options/
Best regards, Tapio
2018 Oct 23 3:22 PM
Hi Tapio,
Yes I am aware of that solution, but it seemed overly complex to implement an entire separate BADI just for that purpose, which is why I posted this to the group.
Regards,
Bryan
2018 Oct 23 8:05 PM
Hi Brian,
if you have access to the BAdI reference there is an attribute "badi_reference->impls" where all implementations are available for the BAdi. So, you can create your own sorting. Anyway, BADI_SORTER is the tool which is made exactly for this.
Best regards, Tapio