It is necessary calculate the VAT for several ledge entries. Since the developer at SAP who defines the enhancement option does not know the VAT values for the specific country, he or she creates a BAdI.
The BAdI has no filters and is called once. No state has to be kept, so you can use static methods. Such a BAdI is defined in the core or in an industry solution and is implemented by the customer.
Since this is single-use BAdI (it requires exactly one implementation), a default class must be provided by SAP. Otherwise, the GET BADI statement will raise an exception if it is executed before the customer has inserted the respective implementation.
You have a calculation rule that depends on the country, for example a VAT rate which is different for different countries. It has default implementations for Europe, Asiaand America and a default class for the rest of the world.
This case is almost the same as the previous use case but with one important difference: there are different implementations for different countries.
Whenever you add an implementation for a specific country, it is selected with the respective filter value. The default implementation is selected if the country is in Europe, Asia, or America. Otherwise the default class is used.
If you have a piece of procedural coding which cannot be easily re-written in object-oriented style, you can use this code in combination with a BAdI. For that purpose, you need to use a single-use BAdI.
If there is no implementation, you get the exception CX_BADI_NOT_IMPLEMENTED . You can put the code you want to reuse in the respective CATCH clause. This code is executed if the BAdI has no active implementation. You code serves as a default implementation in that case.
If there are many implementations when you need exactly one, this is a more severe mistake and the handling of this exception must return you to a point in the call hierarchy where the next step of the current process is a step that can do without the result of the calculation.
Use a TRY-ENDTRY construct and put the procedural code you want to reuse in the CATCH construct:
*Go somewhere up in the call hierarchy
*Your code to be reused