Implementing Extraction Enhancement using SAPI BAdI – Encapsulation via Classes
Extraction enhancement can be defined as supplementing additional fields to an extract structure. One part is to extend (enhance) the extract structure with one or more fields. The other part is the program logic to fill these additional fields. It can be applied in any SAP source system. Although technically possible, you will rarely or never use it in the SAP BW system itself.
The best practice for applying the program logic is using the Business Add-In (BAdI) technique, i.e. implementing BAdI RSU5_SAPI_BADI. It is based on ABAP Objects programming techniques such as classes and interfaces. The “older” enhancement technique, i.e. enhancement RSAP0001, is obsolete and should not be used anymore in new implementations.
One of the main advantages of the BAdI is that you can create more than one implementation. It is now possible to create DataSource specific implementations which are much easier to handle and support.
To make it even more comprehensive, you can create a single “generic” BAdI implementation where dynamically the DataSource specific class is determined and called. This avoids unnecessary calls for irrelevant BAdI implementations. It also complements the BAdI by offering filter functionality: the exit is only processed for a particular DataSource that is found in the control table.
The purpose of this document is to describe how to realize such a generic solution, using ABAP Object Oriented programming.
Please have a look here to download the attachments.
Implementing BAdI RSU5_SAPI_BADI
Business Add-In (BAdI) RSU5_SAPI_BADI is available for realizing DataSource enhancements. The following methods of interface IF_EX_RSU5_SAPI_BADI can be implemented:
- DATA_TRANSFORM – Business Add-Ins Method for General Data Transfer;
- HIER_TRANSFORM – Business Add-Ins Method for Hierarchy Data Transfer.
We will discuss how to create a new implementation of the BAdI, how the generic ABAP coding is realized in both methods, which interfaces are necessary and why two DataSource template classes are convenient.
Create an Implementation
First you have to create a new implementation of BAdI RSU5_SAPI_BADI. Go here via t/code SE19 or SAP menu path:
Tools > ABAP Workbench > Utilities > Business Add-Ins > Implementation
Figure 1: Create BAdI Implementation (1)
Then you have to give the implementation a technical name in the customer namespace (i.e. starting with a Y or Z).
Figure 2: Create BAdI Implementation (2)
On the new screen, you have to enter a description.
Figure 3: Create BAdI Implementation (3)
Finally, you activate the BAdI implementation.
You can use the Class Builder to change the implementing class YCL_IM_RSU5_SAPI_BADI.
Go here via t/code SE24 or SAP menu path:
Tools > ABAP Workbench > Development > Class Builder
Method IF_EX_RSU5_SAPI_BADI~DATA_TRANSFORM is called for every extraction, except hierarchies. The coding is set up in a generic way; please refer to the attached coding example.
Please note that the class name is determined dynamically. Control table YBWSAPIBADI is read to retrieve the DataSource specific enhancement class. In case an enhancement class is found, method YIF_SAPI_BADI_DATA_TRANSFORM~DATA_TRANSFORM of this class is called. If the class does not exist or the method name does not exist, the system catches the exception and issues an error message in the monitor log. Otherwise, the DataSource specific class method is executed.
Method IF_EX_RSU5_SAPI_BADI~HIER_TRANSFORM is only called for hierarchy extraction. The coding is set up in a generic way; please refer to the attached coding example.
Please note that the class name is determined dynamically. Control table YBWSAPIBADI is read to retrieve the DataSource specific enhancement class. In case an enhancement class is found, method YIF_SAPI_BADI_HIER_TRANSFORM~HIER_TRANSFORM of this class is called. If the class does not exist or the method name does not exist, the system catches the exception and issues an error message in the monitor log. Otherwise, the DataSource specific class method is executed.
Interface for Method DATA_TRANSFORM
An interface has to be created for method DATA_TRANSFORM, e.g. YIF_SAPI_BADI_DATA_TRANSFORM. The interface is based on the general BAdI interface IF_EX_RSU5_SAPI_BADI. It only contains the method DATA_TRANSFORM of the interface. The method DATA_TRANSFORM has to be defined as a static method.
The parameters of method DATA_TRANSFORM are copied from the same method of the general BAdI interface.
Figure 4: Parameters of Method DATA_TRANSFORM
Interface for Method HIER_TRANSFORM
An interface has to be created for method HIER_TRANSFORM, e.g. YIF_SAPI_BADI_HIER_TRANSFORM. The interface is based on the general BAdI interface IF_EX_RSU5_SAPI_BADI. It only contains the method HIER_TRANSFORM of the interface. The method HIER_TRANSFORM has to be defined as a static method.
The parameters of method HIER_TRANSFORM are copied from the same method of the general BAdI interface.
Figure 5: Parameters of Method HIER_TRANSFORM
DataSource Template Classes
It might be convenient to create two template classes which can serve as an example for the various DataSource implementations, e.g. YCL_BW_SAPI_BADI_DATA_EXAMPLE (Example Enhancement Class for DataSource – Data) and YCL_BW_SAPI_BADI_HIER_EXAMPLE (Example Enhancement Class for DataSource – Hierarchies).
The previously created corresponding interface is inserted in the class.
Figure 6: Example Class – Interfaces
The method DATA_TRANSFORM is automatically inherited in this example.
Figure 7: Example Class – Methods
You can also include a coding example to facilitate a more uniform programming style.
Other ABAP Workbench Objects
In this chapter, the remaining ABAP workbench objects are discussed. It consists of the following objects:
- T100 messages;
- BW control table.
A new message class YBWSAPIBADI (Error Messages RSU5_SAPI_BADI) has to be created. The message class should contain the following messages:
Message Short Text
Error occured during extraction enhancement using RSU5_SAPI_BADI
Error in calling class &1
Error in calling method YIF_SAPI_BADI_DATA_TRANSFORM~DATA_TRANSFORM
Error in calling method YIF_SAPI_BADI_DATA_TRANSFORM~HIER_TRANSFORM
BW Control Table
BW Control Table YBWSAPIBADI has to be created. The table should be created as “customizing table” and “table maintenance” enabled. A table maintenance dialog can be generated for this table.
The delivery and maintenance settings of the BW Control Table are as follows.
Figure 8: BW Control Table – Delivery and Maintenance Settings
Table YBWSAPIBADI is used by the extraction enhancement using BAdI RSU5_SAPI_BADI. This table stores the DataSources with their accompanying enhancement class. The configuration of the table looks as follows.
Figure 9: BW Control Table – Fields
Figure 10: BW Control Table – Entry Help/Check
The following foreign key relationships have been maintained.
Figure 11: BW Control Table – Foreign Key (1)
Figure 12: BW Control Table – Foreign Key (2)
Procedure for DataSource Enhancement
The last part of this document describes the procedure for creating a DataSource specific enhancement class.
The first step is to copy one of the example classes.
Figure 13: Copy of Example Class
The next step is to enter the necessary coding in method YIF_SAPI_BADI_DATA_TRANSFORM~DATA_TRANSFORM in this case.
Figure 14: Coding Example
Please refer to the attached file for an example DataSource enhancement.
Once the enhancement class is ready, you have to maintain BW control table YBWSAPIBADI.
Figure 15: Table Maintenance
Now the new DataSource specific enhancement class should be called.