Monday 14 September 2015

Fallback class: A workaround of BADI implementation

In earlier post we discussed about why we need to create BADI and steps to do it. If you have missed that post Here You Go

As we have now created the BADI, we would be seeing how to use it in our code. I have created a simple ABAP program with one line to print.


Now I'll be calling that BADI in the code.


Now if we execute this program, it will go into dump.


The reason for this is that there is no active implementation exists yet for this BADI.

Note: Remember this dump occurs only if  'Multiple Use' option is unchecked in BADI definition. Means if you use in your code a BADI, for which multiple implementation CAN exists, but no active implementation yet exists, this dump will not occur.

So what is the remedy for this dump ? Well, we have not one but three :)

The very first is to catch the exception CX_BADI_NOT_IMPLEMENTED in your code. like below. Code will not go into dump instead will print the last line.



Second option is to implement the BADI, which we will cover in next post.

The third and the last is the magical Fallback Class :) . The dictionary meaning for fallback is 'an alternative plan that may be used in an emergency'. That's what exactly the fallback class is meant for.

Fallback class comes into picture when there is no active implementation exists for the BADI. In such case the code in fallback class's method executes. As soon as an implementation exists in system, the implementation call will be used automatically. This fallback class we give when we create the BADI definition.

We will be ticking the option for call Fallback class and a class name needs to be given there. Click on adjacent edit button.

Now if you execute the code, Both texts will be printed. One from the fallback class and one from the actual code.


Happy Learning :)

1 comment:

  1. Can you please post how to implement this BADI CHANGE_POINTER_ESM_BBY_ARTGRP

    ReplyDelete