+ All Categories
Home > Documents > Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Date post: 22-Oct-2014
Category:
Upload: sai-chand-solleti
View: 31 times
Download: 2 times
Share this document with a friend
Popular Tags:
16
Enhancing DataSources with BAdI RSU5_SAPI_BADI SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 1 Enhancing DataSources with BAdI RSU5_SAPI_BADI Applies to: As of SAP_BASIS 6.20 and PI_BASIS 2004_1 (R/3 Release 4.6C). 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 exit’s EXIT_SAPLRSAP_00X. Author(s): Flávio Peres Company: NetSoft Sistemas Created on: 02 febuary 2007 Author Bio Flávio Peres is a SAP-BW Senior Consultant in NetSoft, São Paulo, Brasil.
Transcript
Page 1: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 1

Enhancing DataSources with BAdI RSU5_SAPI_BADI

Applies to: As of SAP_BASIS 6.20 and PI_BASIS 2004_1 (R/3 Release 4.6C).

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 exit’s EXIT_SAPLRSAP_00X. Author(s): Flávio Peres Company: NetSoft Sistemas Created on: 02 febuary 2007

Author Bio Flávio Peres is a SAP-BW Senior Consultant in NetSoft, São Paulo, Brasil.

Page 2: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 2

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

Page 3: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 3

Enhancing DataSources with BAdI RSU5_SAPI_BADI

As of SAP_BASIS 6.20 and PI_BASIS 2004_1 (R/3 Release 4.6C) is available a more efficient way to enhance SAP standard content, using Business Add-Ins (BAdIs) rather than user exits.

The technical name of this BAdI is RSU5_SAPI_BADI, detailed on the SAP Note 691154.

Each enhancement will be implemented in a separated method of the BABI class, then the code will be more organized and clear.

Below, I describe in details, how it can be done, just following a simple few steps. Before we begin, there are some pre conditions, that must be filled:

• SAP_BASIS 6.20 and PI_BASIS 2004_1 must be installed on your system.

• The BADI-definition RSU5_SAPI_BADI (SE18) must exists in your system.

Once the pre conditions ware verified, it’s 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.

Implementing the BADI. SAP make available the definition of the BADI, the implementation must be created for us, as follows:

On transaction SE19

• Type

• Click on

Page 4: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 4

Define a implementation name for your class.

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.

Page 5: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 5

Click on the TAB

Click on the link You go to the class builder

Page 6: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 6

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 TYPE rsaot_s_osource,

lv_data TYPE REF TO data,

lv_method TYPE seocmpname.

FIELD-SYMBOLS: <lt_data> TYPE STANDARD TABLE.

* check BW system

check _check_bw_system( ) = 'X'.

* check if any data is extracted

CHECK c_t_data IS NOT INITIAL.

CALL FUNCTION 'RSA1_SINGLE_OLTPSOURCE_GET'

EXPORTING

i_oltpsource = i_datasource

i_objvers = 'A'

IMPORTING

e_s_oltpsource = ls_oltpsource

EXCEPTIONS

no_authority = 1

not_exist = 2

inconsistent = 3

OTHERS = 4.

IF sy-subrc <> 0.

Page 7: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 7

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_updmode

i_t_select = i_t_select

i_t_fields = i_t_fields

CHANGING

c_t_data = <lt_data>

c_t_messages = c_t_messages.

endmethod.

Page 8: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 8

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 type hashed table of vbak

* with unique key vbeln,

* ls_vbak type vbak .

* FIELD-SYMBOLS: <L_S_DATA> TYPE <Extract structure name>.

* 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.

Define the properties of this method as static and public

Page 9: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 9

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.

Page 10: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 10

Creating a enhancemente of a datasource. I will assume that you have enhanced the structure of the data source, and need to code to populate the enhanced fields of the structure. Copy the method _TEMPLATE_DATASOURCE and rename it, with the same name of the datasource you want to enhance. In case of standard datasource, omit the first character of the name (‘0’ or ‘2’). ie. DataSource 2LIS_18_IOTASK Method name: LIS_18_IOTASK

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.

Page 11: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 11

Declare:

FIELD-SYMBOLS: <l_s_data> TYPE 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> TYPE ZOXBND0152.

* 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.

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 TYPE jsto-stsma,

l_line TYPE bsvx-sttxt,

l_user_line TYPE bsvx-sttxt,

l_stonr TYPE tj30-stonr.

*************************************************************************

* FIELD-SYMBOLS *

*************************************************************************

Page 12: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 12

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 = sy-mandt

flg_user_stat = 'X'

objnr = <l_s_data>-objnr

only_active = 'X'

spras = c_spras

bypass_buffer = ' '

IMPORTING

anw_stat_existing = l_anw_stat_existing

e_stsma = l_e_stsma

line = l_line

user_line = l_user_line

stonr = l_stonr

EXCEPTIONS

object_not_found = 1

OTHERS = 2.

IF sy-subrc = 0.

<l_s_data>-zstssis = l_line.

<l_s_data>-ZSTSUSU = L_USER_LINE(4).

*** SEARCH THE STRING 'ANUL'

search l_user_line for 'ANUL'.

IF sy-subrc = 0.

<l_s_data>-zflanu = 'ANUL'.

ENDIF.

Page 13: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 13

ENDIF.

ENDLOOP.

ENDMETHOD.

Go to the transaction RSA3 and test your data source.

Page 14: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 14

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. Flávio A. Peres BW Senior Consultant. [email protected] [email protected]

Page 15: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 15

Related Content • Note 691154 - SAPI with BADI: User exits in SAPI with BADI-interfaces

• How to... Create a Generic Data Extractor

Page 16: Enhancing Data Sources With BAdI RSU5_SAPI_BADI

Enhancing DataSources with BAdI RSU5_SAPI_BADI

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 16

Disclaimer and Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade. SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.


Recommended