We often encounter system standard data sources, or our self-built data sources cannot meet the requirements. In this case, add several related fields to the data source, this may meet our requirements. In this case, we need to use data source enhancements. The following two enhancement methods are used when the data source is to be written to the result table after data extraction is complete.
Preparation (self-built data source)
1)Rso2Create a simple Data source: sflight business data
Select an application component, enter the text information, and fetch the number directly from the database sflight. Click Save.
Click Save again
2)Rsa6Select the data source you just created and click
Create an additional structure and use the name provided by the system. Click
Fill in the short text and the fields to be added (Here we add a flag field. For flights with capacity greater than or equal to 90%, we intend to mark the flag as 'X ), then click to activate the additional structure
Rsa3Test Extraction
ALV Grid
You can see that the last field ID is empty now (for example, the first one occupies 374, the capacity is 385, the usage rate is 97.14% or greater, but the ID is still blank now)
Method 1: User exit)
1)CmodCreate a new project BW
2) Fill in the short text, save, and click enhancement assignments (enhanced allocation)
3) assign an enhancement "rsap0001 "(Note: This enhancement is fixed, and every system is the same.) Save and click the component.
4) Click to activate the component.
You can see that the export status of the four users has changed to green. Select the export status and click
001 data source used for transaction data
002 data source for primary data or text
003 can only be used for BW version 1.2b, and is replaced by 002 after 2.0a
004 hierarchical data sources
5) double-click a user exit to go to the function module interface.
6) in this FM, only a program is included. This program does not exist now. Double-click zxrsau01.
7) Ignore system warnings and press Enter.
8) Click Yes
The incluede program zxrsau01 is successfully created. You can perform Coding Based on the input parameters of FM.
*&------------------------------------------------------------------*
*&IncludingZxrsau01
*&------------------------------------------------------------------*
Field-Symbols: <S> like zoxhhd0148.
Data: Rate type P decimals 2.
*Judge data name
Case I _datasource.
When 'sflight '.
*Only the data source isSflithHour,To run the following code:
Loop at c_t_data assigning <S>.
Check <S>-seatsmax is not initial.
Clear rate.
*Calculate flight usage
Rate = <S>-seatsocc/<S>-seatsmax * 100.
If rate> = '90. 00 '.
<S>-flag = 'x '."Usage is greater90%,Mark
Endif.
Endloop.
Endcase.
Rsa3Test extraction:
Method 2: Badi
1)Se19
2) create an implementation Badi name: rsu5_sapi_badi
Implementation name: zrsu5_sapi_badi
Enter the description and click "Activate implementation ".
On the Interface Tab, the system automatically creates a class: zcl_im_rsu5_sapi_badi.
Double-click this class
Go to the class interface and you will see two methods:
Data_transform is used to enhance general data (transaction data, master data, and text)
Hier_transform is used to enhance Hierarchical Data
Double-click method to perform coding based on the method parameter.
For ease of ManagementCreate a method for each data source to be enhanced, and then dynamically call the method in data_transform and hier_transform.
Method if_ex_rsu5_sapi_badi ~ Data_transform.
Data: lv_method type seocmpname.
* Check if any data is extracted
Check c_t_data is not initial.
* Get method name for datasource
* Add one character as methods can't start with a number
Concatenate'm _ 'I _datasource into lv_method.
* Check whether method exist
Select single cmpname
Into lv_method
From seocompo
Where clsname = 'zcl _ im_rsu5_sapi_badi'
And cmpname = lv_method.
Check SY-SUBRC EQ 0.
* Check method is implemented
Call method (lv_method)
Exporting
I _updmode = I _updmode
I _t_select = I _t_select
I _t_fields = I _t_fields
Changing
C_t_data = c_t_data
C_t_messages = c_t_messages.
Endmethod.
Create a static method m_sflight (Note: here we use the'm _ '+ data source name as the name of the method, because some system data sources start with numbers, and the method cannot start with a number) click parameters.
Set the parameter (only one I _datasource is missing from the data_transform parameter) as follows:
After saving, return to the method Interface
Click code
Next, followCmodYou can perform coding.
Method sflight.
Field-Symbols: <S> type zoxhhd0148.
Data: Rate type P decimals 2.
* Map the data
Loop at c_t_data assigning <S>.
Check <S>-seatsmax is not initial.
Clear rate.
*Calculate flight usage
Rate = <S>-seatsocc/<S>-seatsmax * 100.
If rate> = '90. 00 '.
<S>-flag = 'x '."Usage is greater90%,Mark
Endif.
Endloop.
Endmethod.
Rsa3Test extraction:
Comparison: We recommend that you use the Badi method. The user exit method enhances rsap0001 to be included in only one project, while the Badi method can create multiple implementation for rsu5_sapi_badi, in this way, an implementation can be created for each module, and a method can be created for each data source to facilitate management.