Professional Documents
Culture Documents
Enhancing DataSources With BAdI RSU5 - SAPI - BADI
Enhancing DataSources With BAdI RSU5 - SAPI - BADI
Summary
This white paper explains in details how to enhance DataSources with the new featured BAdI RSU5_SAPI_BADI. It is shown how to implement each enhancement on a separated method of the BABI class, making the code more organized and clear, then in the formerly user exits EXIT_SAPLRSAP_00X. Author(s): Flvio Peres Company: NetSoft Sistemas Created on: 02 febuary 2007
Author Bio
Flvio Peres is a SAP-BW Senior Consultant in NetSoft, So Paulo, Brasil.
Table of Contents
Enhancing DataSources with BAdI RSU5_SAPI_BADI .................................................................. 3 Implementing the BADI.................................................................................................................... 3 On transaction SE19 .................................................................................................................... 3 Define a implementation name for your class.............................................................................. 4 Then paste the following code: .................................................................................................... 6 Create a new method and name it: _TEMPLATE_DATASOURCE. ........................................... 8 Define the properties of this method as static and public ............................................................ 8 Creating a enhancemente of a datasource. .................................................................................. 10 Declare on the code the structure to populate........................................................................... 10 Bellow you have too examples of how to code your enhancement:.......................................... 11 Here a simple way to populate the fields of the structure straight from the select:................ 11 And here a slight more complex example, using some functions inside the code:................ 11 Conclusion: .................................................................................................................................... 14 Related Content............................................................................................................................. 15 Disclaimer and Liability Notice....................................................................................................... 16
Once the pre conditions ware verified, its time to go. I will assume that the process of creating and enhancing extraction structures of a given datasource is know by the reader. If you have doubts about the creation and enhancement of data sources, consult the documentation on SDN.
Click
to confirm.
Click on
to activate de implementation.
Result: You have created the implementation of the BADI, that will used to create the datasource enhancements.
On the class builder click on the method name: Then paste the following code:
method IF_EX_RSU5_SAPI_BADI~DATA_TRANSFORM. ********************************************************** * To implement an exit for a * datasource create your own method by copying the * method _TEMPLATE_DATASOURCE and rename it to the name * of your datasource. In case you enhance a Business * Content datasource skip the 0 at the beginning (e.g. * Datasource 0FI_AR_3 -> Method FI_AR_3 * The method is then called by the Exit Framework ********************************************************* DATA: ls_oltpsource lv_data lv_method TYPE rsaot_s_osource, TYPE REF TO data, TYPE seocmpname. TYPE STANDARD TABLE.
FIELD-SYMBOLS: <lt_data>
* check if any data is extracted CHECK c_t_data IS NOT INITIAL. CALL FUNCTION 'RSA1_SINGLE_OLTPSOURCE_GET' EXPORTING i_oltpsource i_objvers IMPORTING e_s_oltpsource = ls_oltpsource EXCEPTIONS no_authority not_exist inconsistent OTHERS IF sy-subrc <> 0. = 1 = 2 = 3 = 4. = i_datasource = 'A'
EXIT. ENDIF. * create data for Extract Structure CREATE DATA lv_data TYPE TABLE OF (ls_oltpsource-exstruct). ASSIGN lv_data->* TO <lt_data>. ASSIGN c_t_data TO <lt_data>. * get method name for datasource lv_method = i_datasource. IF lv_method(1) = '0' or lv_method(1) = '2'. * shift by one character as methods can't start with a number SHIFT lv_method. ENDIF. * check method is implemented CHECK _check_method_exists( lv_method ) = 'X'. CALL METHOD (lv_method) EXPORTING i_updmode i_t_select i_t_fields CHANGING c_t_data = <lt_data> c_t_messages = c_t_messages. endmethod. = i_updmode = i_t_select = i_t_fields
Create a new method and name it: _TEMPLATE_DATASOURCE. Then click over the name of the new method and paste the following code:
method _TEMPLATE_DATASOURCE. * Data Definition * DATA: lth_vbak * * ls_vbak type hashed table of vbak with unique key vbeln, type vbak .
* FIELD-SYMBOLS: <L_S_DATA>
* Init * Perform always a mass select into an internal table * SELECT * FROM VBAK INTO TABLE lth_vbak * * FOR ALL ENTRIES IN C_T_DATA WHERE VBELN = C_T_DATA_VBELN.
* map the data * LOOP AT C_T_DATA ASSIGNING <L_S_DATA>. * * * * READ TABLE lth_vbak into ls_vbak with table key vbeln = <L_S_DATA>-vbeln. if sy-subrc eq 0. <L_S_DATA>-VKORG = ls_vbak-vkorg.
* !!! No MODIFY necessary as the field is changed immediatly in the * internal table by using Field Symbols * endif. * ENDLOOP. endmethod.
At this point you have created the implementation class for the BADI RSU5_SAPI_BADI. That can be used for any extractor, standard or custom, to populate enhanced fields. And you have a template to build new enhancements for DataSources. Result: You have created the methods needed to make enhancements of the datasources.
ie.
Declare on the code the structure to populate. On the code, you have to declare the structure <L_S_DATA> of the type of the enhancement sctructure of your data source, ie: Trans: RSA6
As you see in the picture, the Extract Structure of the data source 2LIS_18_I0TASK is MC18I00TSK.
During the execution of the extraction process, when this method is called, the structure C_T_DATA will be populated with packages of 100 records each time. So a loop must be declared to process these data packages, as you see on the code examples bellow. Bellow you have too examples of how to code your enhancement: Here a simple way to populate the fields of the structure straight from the select:
method DS_FICA_VIEW_ZVDSFICACI. FIELD-SYMBOLS: <L_S_DATA> * map the data LOOP AT C_T_DATA ASSIGNING <L_S_DATA>. SELECT SINGLE BETRH BETRW INTO (<L_S_DATA>-BETRH, <L_S_DATA>-BETRW) FROM DFKKOP WHERE OPBEL = <L_S_DATA>-OPBEL AND OPUPW = <L_S_DATA>-OPUPW AND OPUPK = <L_S_DATA>-OPUPK AND OPUPZ = <L_S_DATA>-OPUPZ. ENDLOOP. endmethod. TYPE ZOXBND0152.
And here a slight more complex example, using some functions inside the code:
METHOD lis_18_i0task.
DATA: l_anw_stat_existing TYPE xfeld, l_e_stsma l_line l_user_line l_stonr TYPE jsto-stsma, TYPE bsvx-sttxt, TYPE bsvx-sttxt, TYPE tj30-stonr.
FIELD-SYMBOLS: <l_s_data>
TYPE MC18I00TSK .
************************************************************************* * CONSTANTS * ************************************************************************* CONSTANTS: C_SPRAS TYPE SY-LANGU VALUE 'PT'. *** Get the measures status, record by record *** The DataSource loads a package of 100 records each time, then *** we have to have a loop to process then. LOOP AT c_t_data ASSIGNING <l_s_data>. *** Function measure status CALL FUNCTION 'STATUS_TEXT_EDIT' EXPORTING client flg_user_stat objnr only_active spras bypass_buffer IMPORTING anw_stat_existing = l_anw_stat_existing e_stsma line user_line stonr EXCEPTIONS object_not_found OTHERS IF sy-subrc = 0. <l_s_data>-zstssis <l_s_data>-ZSTSUSU = l_line. = L_USER_LINE(4). = 1 = 2. = l_e_stsma = l_line = l_user_line = l_stonr = sy-mandt = 'X' = <l_s_data>-objnr = 'X' = c_spras = ' '
*** SEARCH THE STRING 'ANUL' search l_user_line for 'ANUL'. IF sy-subrc = 0. <l_s_data>-zflanu = 'ANUL'. ENDIF.
Conclusion:
With this new method of creating enhancements, SAP makes available a more clear and effitient way to enhance datasources. I hope this article be useful to help you to enhance standard, or develop this own datasources, using this new feature. Flvio A. Peres BW Senior Consultant. flavio.amoedo@gmail.com flavio_amoedo@yahoo.com.br
Related Content
Note 691154 - SAPI with BADI: User exits in SAPI with BADI-interfaces How to... Create a Generic Data Extractor