BAdIs - Typical Example
Let us use an example to clarify how to work with BAdIs.
You want to carry out country-specific validity checks upon completion of an order in the core. The interface of these validity tests is specified by the interface if_check_validity.
The current country is, as always, in the field sy-langu of the type lang. To be able to work with a method of a BAdI interface, you must first get an object that implements the interface if_check_validity (depending on the current country). In the second step, you can call the corresponding methods of this object (in this case, a BAdI with exactly on active implementation is semantically most useful) and the result of the validity tests is used in the core code. In this process, the core specifies the interface if_check_validity and its contract, while the subsequent systems provide the implementations.
You obtain a handle for a BAdI instance using the command GET BADI and call the interface methods using CALL BADI. If the BAdI definition created in the core is called badi_check_validity, check_validity(data) is the method that verifies the order data, and the country filter has the name language, the enhancement point is as follows:
DATA bd TYPE REF TO badi_check_validity.
GET BADI bd FILTERS language = sy-langu.
CALL BADI bd->check_validity exporting data = data.
This code fragment shows that a BAdI is represented by a variable of the type ref to badi_check_validity; BAdI names are thus in the same namespace as ABAP data types. Objects of this type are known as BAdI handles.
The GET BADI command then searches the Repository for currently active implementations and selects the one defined for the filter value sy-langu. It is instantiated and “appended” to the BAdI handle bd, which has also just been created. In the subsequent CALL BADI, the method call is passed on to the object instance of the BAdI implementation appended to the BAdI handle bd.