abap development for sap netweaver bi - user exits and badis

29
Dirk Herzog ABAP Development for SAP ® NetWeaver BI: User Exits and BAdIs Bonn Boston

Upload: ronisantosbr

Post on 22-Oct-2014

495 views

Category:

Documents


25 download

TRANSCRIPT

Page 1: Abap Development for Sap Netweaver Bi - User Exits and Badis

Dirk Herzog

ABAP Development for SAP® NetWeaver BI: User Exits and BAdIs

Bonn � Boston

255_5274_Book.indb 3 1/5/09 3:30:50 PM

Page 2: Abap Development for Sap Netweaver Bi - User Exits and Badis

5

Contents

Preface to the 2nd Edition ......................................................................... 9

1 Introduction .............................................................................. 11

2 Performance .............................................................................. 15

2.1 Table Types in ABAP ................................................................... 152.2 Loops and Read Accesses to Tables ............................................. 182.3 Field Symbols ............................................................................. 202.4 Database Accesses and Cache ..................................................... 22

3 User Exits and BAdIs in the Extraction Process ....................... 25

3.1 Usage Options ............................................................................ 253.2 Generic Extractors ....................................................................... 263.3 User Exit RSAP0001 .................................................................... 31

3.3.1 How to Use the Exit ......................................................... 323.3.2 Structured Composition of the ZXRSAU01 Include ........... 343.3.3 Implementing the User Exit EXIT_SAPLRSAP_001 for

Currency Extraction .......................................................... 393.3.4 Using the Hierarchy Exit ................................................... 413.3.5 Surrogate for the Generic Hierarchy Extractor ................... 433.3.6 Transferring Parameters to the User Exit ............................ 44

3.4 BAdI RSU5_SAPI_BADI ............................................................... 453.4.1 Methods .......................................................................... 453.4.2 Advantages and Disadvantages ......................................... 46

4 User Exits in Data Import Processes ........................................ 49

4.1 Transformation ............................................................................ 494.1.1 Deriving Characteristics .................................................... 514.1.2 Deriving Key Figures ......................................................... 564.1.3 Start Routine in the Transformation .................................. 60

255_5274_Book.indb 5 1/5/09 3:30:50 PM

Page 3: Abap Development for Sap Netweaver Bi - User Exits and Badis

6

Contents

4.1.4 End Routine in the Transformation ................................... 644.1.5 Expert Routine in the Transformation ................................ 67

4.2 Routines in the Data Transfer Processes ...................................... 764.2.1 Selecting a File Name in the Data Transfer Process ............ 774.2.2 Determining a Characteristics Selection in the Data

Transfer Process ................................................................ 794.3 Importing a Hierarchy from an Unstructured Excel Sheet ............. 82

4.3.1 Creating the DataStore Object .......................................... 844.3.2 Creating the DataSource ................................................... 844.3.3 Creating the Transformation ............................................. 864.3.4 Creating the Start Routine ................................................ 884.3.5 Creating the End Routine .................................................. 894.3.6 Creating a Data Transfer Process ....................................... 984.3.7 Creating a Query .............................................................. 1004.3.8 Implementation in SAP BW 3.x ........................................ 100

4.4 Transfer Rules in SAP BW 3.x ...................................................... 1014.4.1 Start Routine in the Transfer Rule ..................................... 1024.4.2 Routine for InfoObject Derivation .................................... 1084.4.3 Implementing the InfoObject Derivation .......................... 114

4.5 Update Rules in SAP BW 3.x ....................................................... 1164.5.1 Start Routine ................................................................... 1184.5.2 Filling of Fields in a Data Structure ................................... 1214.5.3 Characteristic Calculation ................................................ 1224.5.4 Key Figure Derivation ....................................................... 1254.5.5 Unit Calculation ............................................................... 1264.5.6 Return Table ..................................................................... 129

5 User Exits and BAdls in Reporting ........................................... 131

5.1 Variable Exit RSR00001 .............................................................. 1315.1.1 Interface of Function Module EXIT_SAPLRSR0_001 .......... 1335.1.2 Implementation for I_STEP = 1 ......................................... 1375.1.3 Implementation for I_STEP = 2 ......................................... 1425.1.4 Implementation for I_STEP = 0 ......................................... 1455.1.5 Implementation for I_STEP = 3 ......................................... 1465.1.6 Validating an Individual Variable ....................................... 1485.1.7 Checking Characteristic Combinations in Step 3 ................ 150

5.2 Virtual Key Figures and Characteristics ........................................ 1535.2.1 Advantages and Disadvantages ......................................... 154

255_5274_Book.indb 6 1/5/09 3:30:50 PM

Page 4: Abap Development for Sap Netweaver Bi - User Exits and Badis

7

Contents

5.2.2 Implementation ................................................................ 1555.2.3 Other Useful Information .................................................. 1665.2.4 Transferring Variable Values to the BAdI ........................... 166

5.3 VirtualProviders .......................................................................... 1685.3.1 Creating a VirtualProvider ................................................. 1685.3.2 Do’s and Don’ts for the Implementation of the Service ..... 173

5.4 BAdI SMOD_RSR00004 .............................................................. 1775.5 Implementing Own Read Routines for Master Data .................... 181

5.5.1 Creating a Master Data Read Class .................................... 1825.5.2 Sample Implementation of a Master Data Read Class ........ 1895.5.3 Entering the Class in the InfoObject ................................. 196

6 User Exits in Planning ............................................................... 199

6.1 Variables in Planning ................................................................... 1996.1.1 Variables in SAP BW-BPS .................................................. 2006.1.2 Variables in SAP NetWeaver BI Integrated Planning .......... 208

6.2 Characteristic Value Derivations .................................................. 2116.2.1 Characteristic Value Derivations in SAP BW-BPS ............... 2116.2.2 Characteristic Value Derivations in SAP NetWeaver

BI Integrated Planning ...................................................... 2206.3 Exit Functions in Planning ........................................................... 229

6.3.1 Exit Functions in SAP BW-BPS .......................................... 2306.3.2 Exit Functions in SAP NetWeaver BI Integrated Planning ... 238

6.4 Conclusion .................................................................................. 246

7 Summary ................................................................................... 247

Appendices

A Additional Extension Options ............................................................... 251A.1 Other BAdIs and User Exits in SAP NetWeaver BI ........................ 251

A.1.1 BAdIs ............................................................................... 251A.1.2 Exits ................................................................................. 252

A.2 Generated Tables and Objects in SAP NetWeaver BI ................... 252A.2.1 Tables in InfoCubes ........................................................... 253A.2.2 Tables in DataStore Objects .............................................. 254

255_5274_Book.indb 7 1/5/09 3:30:50 PM

Page 5: Abap Development for Sap Netweaver Bi - User Exits and Badis

8

Contents

A.2.3 Tables in InfoObjects ........................................................ 254A.2.4 Data Structures in the Dataflow ........................................ 255A.2.5 Generated Objects in SAP NetWeaver BI .......................... 255

B The Author ................................................................................. 257

Index ........................................................................................................... 259

255_5274_Book.indb 8 1/5/09 3:30:50 PM

Page 6: Abap Development for Sap Netweaver Bi - User Exits and Badis

49

User Exits in Data Import Processes4

Whereas the adjustment of extractor results predominantly occurs only with selected DataSources, most data import processes in SAP NetWeaver Business Intelligence involve a user exit that is run through between the DataSource and the InfoProvider. This may be done for conversion purposes, for the derivation of new characteristics, or for data cleansing. Because the entire logic of SAP NetWeaver BI has been changed significantly in SAP NetWeaver 7.0, Section 4.1, Transformation, provides a detailed description of the transformation options that have been newly implemented. Com-pared to the options available in the transfer and update rules, the transformation options have been extended substantially and provide new features.

The only “disadvantage” is that methods are generated instead of form routines, which is why the code of the exit itself is checked for the more rigid syntax of ABAP Objects. However, those of you who want to become more engaged in this subject matter will probably consider this an advantage because it enables you to employ a clean and consistent way of programming. And those of you who don’t want to be involved still have the chance to call a function module and return to the good old ABAP syntax.

Transformation4.1

The method of transformation newly introduced for SAP NetWeaver 7.0 standard-izes the transfer and update rules taken from SAP BW 3.x. Although the transfer rules were only applied between DataSources and InfoSources and the update rules only between InfoSources and InfoProviders,1 the transformation can be used to link any DataSource to the data targets.

In addition, you have the option to display the rules graphically. Figure 4.1 shows the graphical display of the transformation in SAP NetWeaver 7.0. The DataSource

1 Technically speaking, an InfoSource is also included during a data update from a DataStore object into an InfoProvider. You can see that by displaying the generated objects in the Ad-ministrator Workbench.

255_5274_Book.indb 49 1/5/09 3:30:56 PM

Page 7: Abap Development for Sap Netweaver Bi - User Exits and Badis

50

UserExitsinDataImportProcesses4

and target are specifi ed in the header next to the name of the transformation. Below the header, the graphic displays a section of the DataSource structure, and the right-hand part of the graphic displays a section of a rule group. The rule group is a structure that corresponds to the structure of the data target. It’s supposed to enable you to derive several data records in the data target from one source record, as is possible in SAP BW 3.x. The arrows displayed in the graphic indicate which fi elds of the DataSource are transformed into the corresponding fi elds of the data target.

Graphical Display of a TransformationFigure 4.1

Along with the improved exit implementation options, you should use the trans-formation option for newly created objects in SAP NetWeaver 7.0. It depends on each individual case whether it’s worthwhile to convert the old data fl ows . In any event, you should consider when only InfoObject assignments are used in the update or transfer rules and when you can delete the InfoSource being used. In all other cases, it’s only worth the effort if you want to revise the rule completely anyway, you’ll benefi t from the advantages provided by the new routines, or if you have to standardize the routines to keep a clear overview of SAP NetWeaver BI. The last issue is especially necessary in enterprise data warehouses ; in fact,

255_5274_Book.indb 50 1/5/09 3:30:57 PM

Page 8: Abap Development for Sap Netweaver Bi - User Exits and Badis

51

Transformation 4.1

anyone who has carried out at least three different projects with three different project teams will likely agree that it’s absolutely necessary to implement a certain structure.

The transformation contains a total of five exits:

Exit for determining the key figures and data fieldsEE 2

Exit for determining the characteristics and key fieldsEE 3

Start routineEE

End routineEE

Expert routineEE

The expert routine completely replaces the graphical modeling process and enables you to convert each data package from the source into the target structure in a single rou-tine. In SAP NetWeaver 7.0, the end routine and the expert routine have been newly implemented in the transformation, whereas the transfer and update rules in SAP BW 3.x only contained the first three exits. In the following sections, you’ll see how much the end routine and the expert routine can improve your life as a programmer.

Deriving Characteristics4.1.1

The derivation of characteristics and key fields is certainly the simplest type of derivation in the context of BI exits because it contains the fewest variants. The characteristic derivation is required in many different scenarios, for instance, if fields from the source system aren’t delivered, if the fields in the source system have a different structure from those in SAP NetWeaver BI, if a conversion needs to be performed, or if time characteristics must be converted for which no stan-dard conversion has been implemented.

To create a routine for deriving characteristics:

Double-click on the characteristic for which you want to create the routine. This 1. takes you to the Rule Details dialog box.

2 If you update into an InfoCube, only the key figures are calculated, whereas if you update into a DataStore object (in a SAP BW 3.x: ODS object) all data fields are calculated. In an InfoObject, it’s the attributes and texts that are calculated.

3 Similarly, in this exit, the characteristics are determined in an InfoCube, and the key fields in a DataStore, while the value of an InfoObject and of compounded characteristics, if available, are determined in an InfoObject.

255_5274_Book.indb 51 1/5/09 3:30:57 PM

Page 9: Abap Development for Sap Netweaver Bi - User Exits and Badis

52

UserExitsinDataImportProcesses4

Here you must select the 2. Routine item in the Rule Type fi eld. Then you can create the routine by clicking on the Create button next to the fi eld (see Figure 4.2).

Creating a RoutineFigure 4.2

SAP NetWeaver BI then generates a main class that will contain only the imple-mentation. Listing 4.1 shows the generated code. The data input consists of the record number, the number of data records, the source structure of the current data record, and some information on the status of the data import process. The required output should contain the characteristic value and some status information.

PROGRAM trans_routine.*---------------------------------------** CLASS routine DEFINITION*---------------------------------------***---------------------------------------*CLASS routine DEFINITION. PUBLIC SECTION.

TYPES: BEGIN OF _ty_s_SC_1,* InfoObject: 0METYPE Key Figure Type. METYPE TYPE /BI0/OIMETYPE, END OF _ty_s_SC_1. TYPES: BEGIN OF _ty_s_TG_1,* InfoObject: 0METYPE Key Figure Type. METYPE TYPE /BI0/OIMETYPE, END OF _ty_s_TG_1. PRIVATE SECTION. TYPE-POOLS: rsd, rstr.*$*$ begin of global – * insert your declaration only below this line *-*... “insert your code here*$*$ end of global –

255_5274_Book.indb 52 1/5/09 3:30:57 PM

Page 10: Abap Development for Sap Netweaver Bi - User Exits and Badis

53

Transformation 4.1

* insert your declaration only before this line *-*

METHODS compute_0METYPE IMPORTING request TYPE rsrequest datapackid TYPE rsdatapid SOURCE_FIELDS TYPE _ty_s_SC_1 EXPORTING RESULT TYPE _ty_s_TG_1-METYPE monitor TYPE rstr_ty_t_monitor RAISING cx_rsrout_abort cx_rsrout_skip_record.ENDCLASS. “routine DEFINITION

*---------------------------------------** CLASS routine IMPLEMENTATION*---------------------------------------***---------------------------------------*CLASS routine IMPLEMENTATION.

METHOD compute_0METYPE. DATA: MONITOR_REC TYPE rsmonitor.*$*$ begin of routine – * insert your code only below this line *-*... “insert your code here*-- fill table “MONITOR” with values of structure *- “MONITOR_REC” to make monitor entries... “to cancel the update process* raise exception type CX_RSROUT_ABORT.... “to skip a record* raise exception type CX_RSROUT_SKIP_RECORD.

* result value of the routine RESULT = .*$*$ end of routine – * insert your code only before this line *-* ENDMETHOD. “compute_0METYPEENDCLASS. “routine IMPLEMENTATION

Generated Characteristic Derivation MethodListing 4.1

255_5274_Book.indb 53 1/5/09 3:30:57 PM

Page 11: Abap Development for Sap Netweaver Bi - User Exits and Badis

54

UserExitsinDataImportProcesses4

If you’re not yet familiar with object-oriented programming, don’t panic. Because the main class is predefined, you can focus entirely on implementing the logic and don’t need to bother about inheritance, interfaces, attributes, and so on. At this point, that’s much easier even than implementing a BAdI.

But let’s take a detailed look at Listing 4.1. At the beginning, two types are defined: _ty_s_SC_1 and _ty_s_TG_1. The contents of both types depend on the fields you want to link to each other in the graphical modeling process. In the simplest case, it’s only the field 0METYPE of the DataSource that is linked to the field 0METYPE of the data target. Therefore, both types obtain exactly this field.

In the subsequent section, you can define global data objects. All data definitions that you make here occur in all routines created in this transformation so that you can transfer data from one routine into another.

The next section of the listing contains the definition of the method. ABAP Objects distinguish between the definition and the implementation of the method, which is why the interface is first defined at this stage. In addition to the request and data package numbers, the interface contains the structure SOURCE_FIELDS as import parameter. The type of this structure is defined as _ty_s_SC_1 and contains the selected fields of the source structure. The only available export parameters are the RESULT field for the result and the MONITOR table for the error messages. The RETURNCODE and ABORT flags that are available in SAP BW 3.x are now replaced by corresponding exceptions. To skip the data record, you should insert the state-ment RAISE cx_rsrout_skip_record, whereas RAISE cx_rsrout_abort enables you to abort the entire processing of the data package. The new development can be regarded as a significant step forward, given that the handling of the RETURNCODE parameter wasn’t very intuitive in SAP BW 3.x. It used to behave differently in the transfer rules, where it didn’t cause any error message, and in the update rules, where it actually did produce errors.

Apart from that, the implementation is almost identical to that of the transfer and update rules in SAP BW 3.x, despite the fact that some parameter names have been slightly changed. This means that you don’t need to learn anything new and can simply copy the existing code in almost all cases.

The only restriction is that the more rigid ABAP Objects syntax is checked here. But those of you who simply can’t do without the tables and headers and all those other precious gadgets in ABAP just need to call a function module at this point to have the entire range of ABAP relics at your disposal again.

255_5274_Book.indb 54 1/5/09 3:30:57 PM

Page 12: Abap Development for Sap Netweaver Bi - User Exits and Badis

55

Transformation 4.1

Example: Removing Special Characters

A typical problem that regularly occurs when importing data from external systems is that input fields such as family names and addresses can contain special characters, for instance, in foreign addresses or incorrect entries. The best way to catch them is to use a routine. In Listing 4.2, all special characters are replaced by blank space characters in an InfoObject called NAME that has the type CHAR(60).

Simple routines such as this one significantly increase the stability of the import pro-cesses and reduce the maintenance requirements.

METHOD compute_NAME.

DATA:

MONITOR_REC TYPE rsmonitor.

*$*$ begin of routine –

* insert your code only below this line *-*

DATA: l_d_offset LIKE sy-index.

CONSTANTS: c_allowed(100) TYPE c

value ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_’.

RESULT = SOURCE_FIELDS-/BIC/NAME.

* Only capitals are permitted, hence convert to capitals.

TRANSLATE RESULT TO UPPER CASE.

DO 60 TIMES.

l_d_offset = sy-index – 1.

IF RESULT+l_d_offset(1) CO c_allowed.

* Character allowed, don’t do anything

ELSE.

* Character not allowed, replace with blank space character

RESULT+l_d_offset(1) = ‘ ‘.

ENDIF.

ENDDO.

*$*$ end of routine –

* insert your code only before this line *-*

ENDMETHOD. “compute_NAME

Method for Removing Special CharactersListing 4.2

255_5274_Book.indb 55 1/5/09 3:30:57 PM

Page 13: Abap Development for Sap Netweaver Bi - User Exits and Badis

56

UserExitsinDataImportProcesses4

Deriving Key Figures4.1.2

The derivation of key fi gures and data fi elds occurs almost as often as the deriva-tion of characteristics and key fi elds. For example, it’s used for simple calculations (invoice amount = catalog price + extras – discount). However, characteristics deri-vations also occur here if the characteristics are contained in the data component of DataStore objects.

The derivation of key fi gures and data fi elds in the transformation can be as simple as the derivation of characteristics; it even uses exactly the same routine. There is one little difference, and that’s the calculation of units in the routine.

Here is how that now works:

You must select a key fi gure in your data target and double-click on it to open 1. the Rule Details dialog box that you’re already familiar with (see Figure 4.3).

Creating a Routine with Unit CalculationFigure 4.3

255_5274_Book.indb 56 1/5/09 3:30:58 PM

Page 14: Abap Development for Sap Netweaver Bi - User Exits and Badis

57

Transformation 4.1

Then you can select the 2. Routine with Unit entry under the Rule Type item.

Click on the 3. Change button next to the rule type to open the ABAP Editor. The system then automatically generates the code shown in Listing 4.3.

PROGRAM trans_routine.

*---------------------------------------** CLASS routine DEFINITION*---------------------------------------***---------------------------------------*CLASS routine DEFINITION. PUBLIC SECTION. TYPES: BEGIN OF _ty_s_SC_1,* InfoObject: 0AMOUNT Amount. AMOUNT TYPE /BI0/OIAMOUNT,* InfoObject: 0CURRENCY Curr. Key. CURRENCY TYPE /BI0/OICURRENCY, END OF _ty_s_SC_1. TYPES: BEGIN OF _ty_s_TG_1,* InfoObject: 0AMOUNT Amount. AMOUNT TYPE /BI0/OIAMOUNT,* InfoObject: 0CURRENCY Curr. Key. CURRENCY TYPE /BI0/OICURRENCY, END OF _ty_s_TG_1. PRIVATE SECTION.

TYPE-POOLS: rsd, rstr.

*$*$ begin of global – * insert your declaration only below this line *-*... “insert your code here*$*$ end of global – * insert your declaration only before this line *-* METHODS compute_0AMOUNT IMPORTING request TYPE rsrequest datapackid TYPE rsdatapid SOURCE_FIELDS TYPE _ty_s_SC_1 EXPORTING

255_5274_Book.indb 57 1/5/09 3:30:58 PM

Page 15: Abap Development for Sap Netweaver Bi - User Exits and Badis

58

UserExitsinDataImportProcesses4

RESULT TYPE _ty_s_TG_1-AMOUNT CURRENCY TYPE _ty_s_TG_1-CURRENCY monitor TYPE rstr_ty_t_monitor RAISING cx_rsrout_abort cx_rsrout_skip_record.ENDCLASS. “routine DEFINITION

*---------------------------------------** CLASS routine IMPLEMENTATION*---------------------------------------***---------------------------------------*CLASS routine IMPLEMENTATION.

METHOD compute_0AMOUNT.

DATA: MONITOR_REC TYPE rsmonitor.

*$*$ begin of routine – * insert your code only below this line *-*... “insert your code here*-- fill table “MONITOR” with values of structure * “MONITOR_REC” to make monitor entries... “to cancel the update process* raise exception type CX_RSROUT_ABORT.... “to skip a record* raise exception type CX_RSROUT_SKIP_RECORD.

* result values of the routine RESULT = . CURRENCY = .

*$*$ end of routine – * insert your code only before this line *-* ENDMETHOD. “compute_0AMOUNTENDCLASS. “routine IMPLEMENTATION

Key Figure Calculation with Unit OutputListing 4.3

You can use the key figure calculation with unit output for two different types of units: quantity units and currencies. Although you should calculate currencies

255_5274_Book.indb 58 1/5/09 3:30:58 PM

Page 16: Abap Development for Sap Netweaver Bi - User Exits and Badis

59

Transformation 4.1

using a corresponding currency conversion key, the preceding routine is the only way to perform a quantity unit conversion.

You might need to convert currencies; otherwise, the process terminates because data records are imported that don’t contain any information on the amount or source currency. In that case, you should perform the currency conversion by yourself. Listing 4.4 shows you how to do that.

CLASS routine IMPLEMENTATION.

METHOD compute_0AMOUNT.* Here the provided currency is converted * into Euro.If no currency is delivered, * 0 Euro is returned.. DATA: MONITOR_REC TYPE rsmonitor.

*$*$ begin of routine – * insert your code only below this line *-*... “insert your code here*-- fill table “MONITOR” with values of structure *- “MONITOR_REC” to make monitor entries... “to cancel the update process* raise exception type * CX_RSROUT_ABORT.... “to skip a record* raise exception type * CX_RSROUT_SKIP_RECORD.* result values of the routine IF SOURCE_FIELDS-CURRENCY IS INITIAL. RESULT = 0. CURRENCY = ‘EUR’. ELSE. CALL FUNCTION ‘CONVERT_TO_LOCAL_CURRENCY’ EXPORTING DATE = sy-datum FOREIGN_AMOUNT = SOURCE_FIELDS-amount FOREIGN_CURRENCY = SOURCE_FIELDS-currency LOCAL_CURRENCY = ‘EUR’

255_5274_Book.indb 59 1/5/09 3:30:58 PM

Page 17: Abap Development for Sap Netweaver Bi - User Exits and Badis

60

UserExitsinDataImportProcesses4

TYPE_OF_RATE = ‘M’ IMPORTING LOCAL_AMOUNT = RESULT EXCEPTIONS OTHERS = 1. IF sy-subrc = 0. CURRENCY = ‘EUR’. ELSE. RESULT = SOURCE_FIELDS-amount. CURRENCY = SOURCE_FIELDS-currency. ENDIF.*$*$ end of routine – * insert your code only before this line *-* ENDMETHOD. “compute_0AMOUNTENDCLASS. “routine IMPLEMENTATION

Currency Conversion in the TransformationListing 4.4

A somewhat easier alternative is to set the currency 0CURRENCY to EUR in the start routine. However, if the currency is updated into an additional field, it can make an important difference if you update Euro or no-currency data.

The only routine that’s missing in the transformation compared to the old update rules is the routine containing the return table. In most cases, this routine can be replaced with the end routine described in Listing 4.5 in the next subsection, although in some rare cases, you have to revert to the expert routine. Even though this may require some additional work, the SAP decision to avoid the routine was certainly right. Regarding the return table, it was always unclear in which sequence the individual exits would be called, and this could be very confusing.

Start Routine4.1.3 in the Transformation

The start routine is primarily used to format the source data. You should use the start routine whenever the source system delivers the data in a different form than is expected by SAP NetWeaver BI. For example, you should carry out conver-sions if cost types are delivered without alpha conversion or if the date format is 01.05.06. At this point, you can also already delete data records from the source system that aren’t needed in SAP NetWeaver BI. In general, it’s more efficient to carry out several data operations in the start routine instead of splitting them up

255_5274_Book.indb 60 1/5/09 3:30:59 PM

Page 18: Abap Development for Sap Netweaver Bi - User Exits and Badis

61

Transformation 4.1

into single routines, especially if those routines require the same intermediate results for their calculations.

You can also effi ciently scale down the data package in the start routine. Because the entire data package is contained in an internal table, you can reduce the data quantity effi ciently by using the DELETE SOURCE_PACKAGE WHERE ... statement. Implementing an exception in the characteristic routine for the same purpose is much less effi cient because the data records fi rst have to be specifi cally formatted for the characteristic calculation—a time-consuming task.

You can create the start routine either through the transformation menu by select-ing Insert • Create Start Routine or by clicking on the relevant button (see Fig-ure 4.4).

Button for Creating a Start RoutineFigure 4.4

The importing parameters of the start routine are the request as well as the data package ID; its exporting parameter is the table containing the error records. The most important parameter, however, is the actual SOURCE_PACKAGE table that con-tains the data records and is defi ned as a changing parameter.

The annoying thing about the start routine in Release 3.x was that the fi elds that were contained in the InfoCube often were actually missing in the start routine. This effect can almost be neglected because of the existence of the end routine. For this reason, you should mainly use the start routine for initializations , data cleansing , and deleting redundant data records.

In the example in Listing 4.5, we’ll fi rst delete invalid characters from the data package and then initialize a master data table.

PROGRAM trans_routine.

*---------------------------------------** CLASS routine DEFINITION*---------------------------------------***---------------------------------------*CLASS routine DEFINITION. PUBLIC SECTION.

255_5274_Book.indb 61 1/5/09 3:30:59 PM

Page 19: Abap Development for Sap Netweaver Bi - User Exits and Badis

62

UserExitsinDataImportProcesses4

TYPES: BEGIN OF _ty_s_SC_1,* InfoObject: 0CO_AREA Contr. area. CO_AREA TYPE /BI0/OICO_AREA,* InfoObject: 0CO_DOC_NO CO Doc.No. CO_DOC_NO TYPE /BI0/OICO_DOC_NO,* ... END OF _ty_s_SC_1. TYPES: _ty_t_SC_1 TYPE STANDARD TABLE OF _ty_s_SC_1 WITH NON-UNIQUE DEFAULT KEY. PRIVATE SECTION.

TYPE-POOLS: rsd, rstr.

*$*$ begin of global – * insert your declaration only below this line *-* DATA: g_t_costcenter TYPE /bi0/qcostcenter WITH UNIQUE KEY co_area costcenter objvers dateto.*$*$ end of global – * insert your declaration only before this line *-* METHODS start_routine IMPORTING request TYPE rsrequest datapackid TYPE rsdatapid EXPORTING monitor TYPE rstr_ty_t_monitors CHANGING SOURCE_PACKAGE TYPE _ty_t_SC_1 RAISING cx_rsrout_abort.ENDCLASS. “routine DEFINITION

*---------------------------------------** CLASS routine IMPLEMENTATION

255_5274_Book.indb 62 1/5/09 3:30:59 PM

Page 20: Abap Development for Sap Netweaver Bi - User Exits and Badis

63

Transformation 4.1

*---------------------------------------***---------------------------------------*CLASS routine IMPLEMENTATION.

*---------------------------------------** Method start_routine*---------------------------------------** Calculation of source package via* start routine*---------------------------------------** <-> source package*---------------------------------------* METHOD start_routine.*=== Segments ===

FIELD-SYMBOLS: <SOURCE_FIELDS> TYPE _ty_s_SC_1.

DATA: MONITOR_REC TYPE rstmonitor.

*$*$ begin of routine – * insert your code only below this line *-*... “insert your code here*-- fill table “MONITOR” with values of structure * “MONITOR_REC” to make monitor entries* First delete those lines that have an order * as partner projects. DELETE SOURCE_PACKAGE WHERE PIOBJSV = ‘0COR’. * Then initialize the cost center table.DATA: r_cctr TYPE RANGE OF /bi0/oicostcenter, “Ranges table for “cost centers w_cctr LIKE LINE OF r_cctr. “Header for r_cctr CLEAR w_cctr. w_cctr-sign = ‘I’. “Including selection w_cctr-option = ‘EQ’. “Query similarity* A ranges table containing all cost centers is built* up in the following loop. LOOP AT source_package ASSIGNING <SOURCE_FIELDS>.

255_5274_Book.indb 63 1/5/09 3:30:59 PM

Page 21: Abap Development for Sap Netweaver Bi - User Exits and Badis

64

UserExitsinDataImportProcesses4

w_cctr-low = <SOURCE_FIELDS>-costcenter. COLLECT w_cctr into r_cctr. ENDLOOP.* Then those cost centers are imported into the * global table that are also available in the * data package. SELECT * FROM /bi0/qcostcenter INTO TABLE g_t_costcenter WHERE costcenter IN r_cctr AND objvers = ‘A’. ... “to cancel the update process* raise exception type * CX_RSROUT_ABORT.

*$*$ end of routine – * insert your code only before this line *-* ENDMETHOD. “start_routineENDCLASS. “routine IMPLEMENTATION

Example of a Start Routine, Including Generated MethodListing 4.5

Both techniques described here are typical of start routines. When the start routine in SAP BW Release 3.x was the only routine in which the complete data package was calculated, it was often used for many different calculations. Logically speak-ing, however, this should be part of the end routine.

End Routine4.1.4 in the Transformation

The end routine in the transformation is predominantly used to post-edit the data. Here you should calculate new fields that aren’t delivered directly, determine addi-tional check sums that are to be updated in the data target, and adjust the data to the data target.

You also can use the end routines for validation purposes. For instance, you can first calculate the sales figures per customer and then delete all data records in the end routine in which the sales figures per customer are below $10,000. However, whether the calculation takes place in the start routine or end routine usually depends on other considerations, particularly whether the fields required for cal-culating the algorithms are actually updated into the data target.

255_5274_Book.indb 64 1/5/09 3:30:59 PM

Page 22: Abap Development for Sap Netweaver Bi - User Exits and Badis

259

0AMOUNT, 740CURRENCY, 600QUANTITY, 74(DTP), 76_ty_s_SC_1, 54_ty_s_TG_1, 54_VALUES_GENERATE, 189, 192

A

ABAP Objects, 47, 49, 54, 161ABAP query, 27Account model, 74Actual data, 199ADD_NEW_BLOCKS, 242Aggregation level, 228ALV grid, 41ANY TABLE, 36Application component, 27, 28

Hierarchy, 28Attribute derivation, 22, 213Authorization check, 26, 32

B

BAdI, 25, 45RSR_OLAP_BADI, 155, 156RSU5_SAPI_BADI, 45, 46SMOD_RSR00004, 177

BAPI, 168BAPI_INFOCUBE_READ_REMOTE_DATA, 170Structure, 172

BAPI_INFOCUBE_READ_REMOTE_DATA, 171Basic planning area, 211BEx query, 210BI hierarchy, 83BPS0, 200Business Add-In (BAdI), 25

Business Consolidation, 173Business Explorer (BEx), 170, 199Business Planning and Simulation (SAP BW-BPS), 199BW_SCHEDULER, 251

C

Cache, 22CASE, 35Characteristic, 176

Virtual, 153Characteristic calculation, 122Characteristic combination, 166, 242

Check, 150Characteristic derivation, 51, 65, 199Characteristic relationship, 212

Detail, 212CHARACTERISTICS, 171Characteristic value, 173, 211Characteristic value combination

Check, 213Create, 215

Characteristic value derivation, 211, 218Attribute derivation, 213Hierarchical, 213SAP BW-BPS, 211SAP NetWeaver BI Integrated Planning, 220

CheckCharacteristic combinations, 150

ClassCL_RSBM_LOG_CURSOR_STEP, 68CL_RSDRV_REMOTE_IPROV_SRV, 172CL_RSMD_RS_GENERIC_DOMAIN, 181CL_RSPLFC_BPS_EXITS, 246

Client, 182CL_RSBM_LOG_CURSOR_STEP, 68CL_RSDRV_REMOTE_IPROV_SRV, 172CL_RSMD_RS_GENERIC_DOMAIN, 181CL_RSPLFC_BPS_EXITS, 246

Index

255_5274_Book.indb 259 1/5/09 3:31:35 PM

Page 23: Abap Development for Sap Netweaver Bi - User Exits and Badis

260

Index

CMOD, 32Code

Dynamic, 20Column

Selection, 30Combination check, 148, 213Combination proposal, 213Commitment data, 123Communication structure, 102, 107, 111, 118, 125, 129, 156, 157, 161COMPUTE, 158, 161, 162, 163, 164, 165CONCATENATE, 79CONSTRUCTOR, 165Controlling area, 101Conversion, 32CONVERT_TO_FOREIGN_CURRENCY, 126CONVERT_TO_LOCAL_CURRENCY, 126Cost center category, 65CREATE, 183, 218C_T_DATA, 36C_T_FOLDERT, 42C_TH_DATA, 243C_T_HIENODE, 42C_T_MESSAGES, 36Currency conversion, 68Customizing table, 108CX_RSROUT_ABORT, 54CX_RSROUT_SKIP_RECORD, 54

D

DATA, 171Database access, 22Database selection, 167Data cleansing, 49, 61Data enrichment, 18Data flow, 50Data mart interface, 174Data model, 101Data modeling, 41, 74, 116Data owner, 31Data package, 23, 30, 31, 34, 51, 105, 107, 121Data quality, 128

Data record, 15Sequence, 166

Data selection, 171DataSource, 26, 33, 45, 46, 49, 65, 84, 85, 101, 168, 173

Create, 85Generic, 26, 29

DataStore, 37, 174Object, 84, 86, 133, 167

Data target, 74, 101Data target structure, 129Update, 23

Data transferLogging, 105

Data transfer process (DTP), 76, 83, 98, 101Characteristics selection, 79Selection of a file name, 77

DATA_TRANSFORM, 45Data volume, 15Date-dependent default value assignment, 138Default value, 114, 151Default value assignment

Date-dependent, 138Table-dependent, 138

DEFINE, 158, 159, 161, 162Deletion

Record, 61Delta

Generic, 29Delta upload, 29Derivation

Key figure, 56Distribution mechanism, 47DTP, 83

E

Elimination of intercompany sales, 166End routine, 51, 60, 64, 65, 68, 83, 89, 97, 100Enterprise data warehouse, 50Error handling, 68, 120

SAP BW 3.x, 113Table, 113

255_5274_Book.indb 260 1/5/09 3:31:35 PM

Page 24: Abap Development for Sap Netweaver Bi - User Exits and Badis

261

Index

Error message, 107, 149Output, 128Return, 152

ET_MESG, 233ETO_CHAS, 233EXECUTE, 243Exit function

SAP BW-BPS, 230SAP NetWeaver BI Integrated Planning, 238

Exit function module, 233, 235EXIT_SAPLRRS0_001, 131, 163, 167EXIT_SAPLRSAP_001, 33, 34, 35EXIT_SAPLRSAP_002, 33EXIT_SAPLRSAP_003, 33EXIT_SAPLRSAP_004, 33, 43EXIT_SAPLRSBBS_001, 177, 178EXIT_SAPLRSBBS_002, 177EXIT_SAPLRSR0_001, 133Expert routine, 60, 65, 67, 68, 74, 76EXPERT_ROUTINE, 73Export DataSource, 43Extraction, 25, 46

SAP ERP, 38Extractor, 34

Add data records, 37Generic, 25, 26, 29, 31, 43

Extractor checker, 30Extract structure, 44

Fill, 36Modify, 36

F

FieldChange, 232Extension, 31I_S_RKB1D-COMPID, 152Masking, 26Selection, 232Symbol, 15, 20

FIELDNAME, 81File name

Determine, 78File name selection, 77

Filter value, 133Filter value determination, 82FINISH_EXECUTION, 245Fiscal year variant, 101, 182Flat file, 26FOX formula, 252Full table scan, 19Full upload, 29Function

CREATE, 218Specifically written, 199WS_UPLOAD, 230

Function module, 32BAPI_INFOCUBE_READ_REMOTE_DATA, 170, 171Calculate data, 168CONVERT_TO_FOREIGN_CURRENCY, 126CONVERT_TO_LOCAL_CURRENCY, 126Exit function module, 233, 235EXIT_SAPLRRS0_001, 131EXIT_SAPLRSAP_001, 33, 35EXIT_SAPLRSAP_002, 33EXIT_SAPLRSAP_003, 33EXIT_SAPLRSAP_004, 33, 43EXIT_SAPLRSR0_001, 133Fixed interface, 201Init function module, 232RRMS_MESSAGE_HANDLING, 152, 153RSDRI_INFOPROV_READ, 174Z_VAR_CHECK_VALIDITY, 137, 148

G

GET_ATTRIBUTES, 188, 193GET_CAPABILITIES, 184GET_REF_DATA_SEL, 240GET_TEXT, 187, 195GET_VALUES, 185G_T_ERRORLOG, 113

H

Hashed table, 17, 19, 22HASHED TABLE, 17

255_5274_Book.indb 261 1/5/09 3:31:35 PM

Page 25: Abap Development for Sap Netweaver Bi - User Exits and Badis

262

Index

HAUPT_KST, 196Hierarchy, 26, 33, 41, 46, 82, 213

Aggregation, 166BI hierarchy, 83Exit, 43Extractor, 43Sorted, 82

HIER_TRANSFORM, 45, 46History

Transformation, 68

I

IF_RSPLS_CR_METHODS~CHECK, 220IF_RSPLS_CR_METHODS~CREATE, 224IF_RSPLS_CR_METHODS~DERIVE, 228I_MAXROWS, 186I message, 128Implementation

Logic, 54Implementation name, 156Import process, 55Include

ZXRSAU01, 34ZXRSRU01, 131

Individual processing, 166InfoCube, 61, 68, 128, 129, 166, 174, 177, 232, 252

Calculate result, 129INFOCUBE, 170InfoObject, 37, 97, 153, 196, 219, 241

Derivation, 108, 114HAUPT_KST, 196

InfoPackage, 44, 78, 98, 99, 107, 118, 133InfoProvider, 49, 67, 101, 102, 153, 155, 166, 167, 168, 176, 181, 199InfoSource, 50, 67, 101, 102, 120INIT_EXECUTION, 239Init function module, 232Initialization, 61INITIALIZATION, 158, 161, 162Instance attribute, 161INVALID, 213INVERSE_EXPERT_ROUTINE, 73INVERSE_EXPERT_SELECTION, 73

I_STEP, 132, 137, 142, 145, 146IT_EXITP, 233ITO_CHA, 233ITO_CHASEL, 233, 236ITO_KYF, 233I_T_SELOPT, 185I_TS_REQ_ATR, 186

K

KEYDATE, 170Key figure, 173, 176

Virtual, 153Key figure derivation, 56, 125Key figure model, 74KEYFIGURES, 171

L

Line items report, 73Link node, 97LISTCUBE, 176Loading process, 15Log, 76Logic

Implementation, 54Loop, 18LOOP AT TABLE WHERE, 19

M

Mapping, 177Mapping table, 37Masking, 31Master data attribute, 17, 33Master data read class, 196, 197

Create, 182Implementation, 189

Master data read routine, 181Master data table, 174Master data text, 33Message, 106Message class, 106

255_5274_Book.indb 262 1/5/09 3:31:35 PM

Page 26: Abap Development for Sap Netweaver Bi - User Exits and Badis

263

Index

Message collector, 152Method

ADD_NEW_BLOCKS, 242COMPUTE, 158, 161, 162, 163, 165CONSTRUCTOR, 165CREATE, 183DATA_TRANSFORM, 45DEFINE, 158, 161, 162EXECUTE, 243EXIT_SAPLRSBBS_001, 177, 178EXIT_SAPLRSBBS_002, 177EXPERT_ROUTINE, 73FINISH_EXECUTION, 245GET_ATTRIBUTES, 188, 193GET_CAPABILITIES, 184GET_REF_DATA_SEL, 240GET_TEXT, 187, 195GET_VALUES, 185HIER_TRANSFORM, 46IF_RSPLS_CR_METHODS~CHECK, 220IF_RSPLS_CR_METHODS~CREATE, 224IF_RSPLS_CR_METHODS~DERIVE, 228INIT_EXECUTION, 239INITIALIZATION, 158, 161, 162INVERSE_EXPERT_ROUTINE, 73SET_KEY_DATE, 183_VALUE_GENERATE, 189, 192_VALUES_GENERATE, 189

MethodeINVERSE_EXPERT_SELECTION, 73

Microsoft ExcelTable, 82

ModelingGraphical, 51

MONITOR_RECNO, 120Multi-planning area, 211MultiProvider, 154, 168, 177

N

Navigation attribute, 171, 196Navigation block, 133Next ID, 98

O

Object reference, 246ODS object, 84OLAP processor, 171O notation, 20OPENHUB_TRANSFORM, 251Original object, 26

P

ParameterI_IOBJNM, 134I_MAXROWS, 186I_PERIV, 135I_S_COB_PRO, 134I_S_RKB1D, 134I_STEP, 132, 135, 137, 142, 145, 146I_T_VAR_RANGE, 135I_VARTYP, 134I_VNAM, 134

Parent ID, 97Performance, 15, 16, 20, 68, 73, 112, 114, 116, 118, 154, 167

Per data record, 15Period entries, 150Persistent staging area (PSA), 23, 120Planning function, 199, 204, 236

Create, 230Planning level, 200, 211Plan version, 202Position selection, 65Pre-assignment, 204

Based on authorizations, 139Process chain, 252Process types, 252Program

Activated, 120PSA, 23, 31, 77, 120

Q

Quantity unitConversion, 59

255_5274_Book.indb 263 1/5/09 3:31:35 PM

Page 27: Abap Development for Sap Netweaver Bi - User Exits and Badis

264

Index

Quarterly report, 149Query, 173Query creation, 208Query Designer, 145Query name, 181

R

RAISE EXCEPTION, 152RANGES table, 206Read access

Table, 18Read routine

For master data, 181READ TABLE, 18READ TABLE INDEX, 19READ TABLE WITH KEY, 19READ TABLE WITH TABLE KEY, 19Record

Delete, 61Reference data, 239, 241, 244RemoteCube, 114, 168Removal

Special character, 55Report-report interface, 73, 177, 178RESULT_PACKAGE, 72RESULT_TABLE, 129RETURN, 170Return table, 101, 129RFC Packing, 169, 172Rounding difference, 168Routine

Create, 77Unit, 57

RRMS_MESSAGE_HANDLING, 152, 153RSA3, 30RSAP0001, 31, 32, 45RSAR_CONNECTOR, 251RSBBS, 177RSDBC_SQL_STATEMENT, 251RSDRI_INFOPROV_READ, 174RSO2, 26, 27RSOD_DOC_BADI, 252RSOD_ITEM_DOC, 252RSOD_ITEM_DOC_LIST, 252

RSOD_WWW_DOC_MAINT, 252RSR00001, 131RSR00002, 155RSR00004, 177RSRA_ALERT, 251RSR_OLAP_AUTH_GEN, 251RSR_OLAP_BADI, 155, 156RSU5_SAPI_BADI, 45, 46

S

SAP BW-BPS, 199, 252Variable, 208Variable concept, 200

SAP ERP, 199SAP NetWeaver 7.0, 49, 51, 67, 82, 83, 84, 85, 98, 100, 155, 166SAP NetWeaver BI Integrated Planning, 199

Characteristic value derivation, 220Exit function, 238Variable, 208

SAP SEM-BCS, 173SBIW, 28SE19, 155SE80, 182, 189, 220SE91, 153Selection, 30SELECTION, 170Selection condition, 228Selection field, 30, 44

Select, 30Selection option variable, 210SEMBPS01, 252SEMBPS02, 252SET_KEY_DATE, 183SID Support, 169, 172Single value, 203

Return, 201SMOD_RSR00004, 177Sorted hierarachy, 82Sorted table, 16, 19SORTED TABLE, 16Source characteristic, 219SOURCE_PACKAGE, 61Source structure, 76

255_5274_Book.indb 264 1/5/09 3:31:35 PM

Page 28: Abap Development for Sap Netweaver Bi - User Exits and Badis

265

Index

Source system, 26, 73, 101, 113, 114Special character

Removal, 55Standard deviations, 166Standard extractor, 25, 31

Enhancement, 25, 26Standard table, 16, 19STANDARD TABLE, 16Start routine, 51, 60, 64, 65, 68, 83, 100, 102, 104, 113, 118, 120, 129

Create, 88Transfer rule, 31

S_T_TCURF, 40SY-DATE, 79

T

Table, 27C_T_DATA, 36C_T_FOLDERT, 42C_TH_DATA, 243C_T_HIENODE, 42C_T_MESSAGES, 36Customizing table, 108ET_MESG, 233ETO_CHAS, 233E_T_RANGE, 135G_T_ERRORLOG, 113Hashed table, 17, 19, 22, 104IT_EXITP, 233ITO_CHA, 233ITO_CHASEL, 233, 236ITO_KYF, 233I_T_SELOPT, 185I_TS_REQ_ATR, 186L_T_RANGE, 81Mapping table, 37MONITOR_RECNO, 120RESULT_PACKAGE, 72RESULT_TABLE, 129Sorted table, 16, 19Standard table, 16, 19S_T_TCURF, 40TCURR, 26, 29, 40XTH_DATA, 236

Table access, 18Table definition, 18Table-dependent default value assignment, 138Table entry

Read, 165Table type

Programming example, 16Table types, 15, 16Target structure, 76TCURR, 26, 29, 40Transaction

BPS0, 200CMOD, 32LISTCUBE, 176RSA3, 30RSBBS, 177RSO2, 26, 27RSRT, 74SBIW, 28SE19, 155SE80, 182, 189, 220SE91, 106, 114, 153

Transaction data, 27, 33Transfer rule, 49, 100, 101, 102, 104, 113

Start routine, 31Transfer structure, 105, 112, 113Transformation, 49, 50, 60, 64, 82

Graphical display, 49History, 68

Transport, 68Type

_ty_s_SC_1, 54_ty_s_TG_1, 54

U

Unit calculation, 56, 126Update rule, 22, 49, 60, 100, 101, 102, 113, 116, 118, 120, 122, 125, 126, 129

Example, 117Upload, 17Usage type, 25

255_5274_Book.indb 265 1/5/09 3:31:36 PM

Page 29: Abap Development for Sap Netweaver Bi - User Exits and Badis

266

Index

User exit, 25, 32, 41, 44EXIT_SAPLRRS0_001, 163, 167Planning, 199RSAP0001, 31, 32, 45RSR00002, 155RSR00004, 177

V

Validation, 132, 148Of an individual variable, 148

Value setReturn, 204, 206

Value type, 123Variable, 131, 199

Central, 147Check, 147Combination, 148Derivation, 145Handling, 147Planning, 199Project-specific, 147Read, 208SAP BW-BPS, 200, 208SAP NetWeaver BI Integrated Planning, 208Selection option variable, 210Set, 201Strategy, 148Transfer, 166, 210Values, 166Write, 210

Variable determinationExample, 144

Variable exit, 131, 200ZXRSRU01, 137

Variable ExitRSR00001, 200

Variation, 166View, 27Virtual characteristic, 153Virtual key figure, 153VirtualProvider, 73, 168, 174, 176, 177

Implementation, 173

W

WS_UPLOAD, 230

X

X message, 170XTH_DATA, 236

Z

Z_VAR_CHECK_VALIDITY, 137ZXRSAU01, 34ZXRSRU01, 131, 137

René de Daniel, Hermann Steinrötter

Enterprise Integration Patternsfor SAP NetWeaver PISAP PRESS Essentials 35

Enterprise Integration Patterns (EIP) are design patterns that enablethe integration of enterprise applications. This practical workshopprovides SAP NetWeaver XI developers with the most importantpatterns, from Aggregator, to Content Filter and Guaranteed Delivery,to Request – Reply and Splitter. The book describes the function and structure of individual EIPs, applies them to specific real-life problems,and ultimately implements them in Java for SAP NetWeaver XI. It also includes download offerings for the individual patterns.

223 pp., 2009, 68,– Euro / US$ 85

ISBN 978-1-59229-175-5

>> www.sap-press.de/1644

Discover the twelve most important integration patterns and their modeling for SAP NetWeaver XI

Understand the integration patterns’ design and follow their practical implementation

Includes download offer for the completeJava files

www.sap-press.com

255_5274_Book.indb 266 1/5/09 3:31:36 PM