Sei sulla pagina 1di 29



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




Contents

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

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

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

2.1 Table Types in ABAP  .................................................................... 15


2.2 Loops and Read Accesses to Tables  .............................................. 18
2.3 Field Symbols  .............................................................................. 20
2.4 Database Accesses and Cache  ...................................................... 22

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

3.1 Usage Options  ............................................................................. 25


3.2 Generic Extractors  . ...................................................................... 26
3.3 User Exit RSAP0001  . ................................................................... 31
3.3.1 How to Use the Exit  .......................................................... 32
3.3.2 Structured Composition of the ZXRSAU01 Include  ............ 34
3.3.3 Implementing the User Exit EXIT_SAPLRSAP_001 for
Currency Extraction  ........................................................... 39
3.3.4 Using the Hierarchy Exit  .................................................... 41
3.3.5 Surrogate for the Generic Hierarchy Extractor  .................... 43
3.3.6 Transferring Parameters to the User Exit  ............................ 44
3.4 BAdI RSU5_SAPI_BADI  ................................................................ 45
3.4.1 Methods  ........................................................................... 45
3.4.2 Advantages and Disadvantages  . ........................................ 46

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

4.1 Transformation  . ........................................................................... 49


4.1.1 Deriving Characteristics  ..................................................... 51
4.1.2 Deriving Key Figures  . ........................................................ 56
4.1.3 Start Routine in the Transformation  ................................... 60

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


Contents

4.1.4 End Routine in the Transformation  .................................... 64


4.1.5 Expert Routine in the Transformation  ................................ 67
4.2 Routines in the Data Transfer Processes  ....................................... 76
4.2.1 Selecting a File Name in the Data Transfer Process  ............ 77
4.2.2 Determining a Characteristics Selection in the Data
Transfer Process  . ............................................................... 79
4.3 Importing a Hierarchy from an Unstructured Excel Sheet  . ............ 82
4.3.1 Creating the DataStore Object  . ......................................... 84
4.3.2 Creating the DataSource  . .................................................. 84
4.3.3 Creating the Transformation  .............................................. 86
4.3.4 Creating the Start Routine  ................................................. 88
4.3.5 Creating the End Routine  .................................................. 89
4.3.6 Creating a Data Transfer Process  ........................................ 98
4.3.7 Creating a Query  ............................................................... 100
4.3.8 Implementation in SAP BW 3.x  ......................................... 100
4.4 Transfer Rules in SAP BW 3.x  ....................................................... 101
4.4.1 Start Routine in the Transfer Rule  ...................................... 102
4.4.2 Routine for InfoObject Derivation  ..................................... 108
4.4.3 Implementing the InfoObject Derivation  ........................... 114
4.5 Update Rules in SAP BW 3.x  ........................................................ 116
4.5.1 Start Routine   .................................................................... 118
4.5.2 Filling of Fields in a Data Structure  .................................... 121
4.5.3 Characteristic Calculation   ................................................. 122
4.5.4 Key Figure Derivation  ........................................................ 125
4.5.5 Unit Calculation   ............................................................... 126
4.5.6 Return Table  . .................................................................... 129

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

5.1 Variable Exit RSR00001  ............................................................... 131


5.1.1 Interface of Function Module EXIT_SAPLRSR0_001  . ......... 133
5.1.2 Implementation for I_STEP = 1  .......................................... 137
5.1.3 Implementation for I_STEP = 2  .......................................... 142
5.1.4 Implementation for I_STEP = 0  .......................................... 145
5.1.5 Implementation for I_STEP = 3  .......................................... 146
5.1.6 Validating an Individual Variable  ....................................... 148
5.1.7 Checking Characteristic Combinations in Step 3  ................ 150
5.2 Virtual Key Figures and Characteristics  ......................................... 153
5.2.1 Advantages and Disadvantages  . ........................................ 154

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


Contents

5.2.2 Implementation  . ............................................................... 155


5.2.3 Other Useful Information  .................................................. 166
5.2.4 Transferring Variable Values to the BAdI  ............................ 166
5.3 VirtualProviders  ........................................................................... 168
5.3.1 Creating a VirtualProvider  . ................................................ 168
5.3.2 Do’s and Don’ts for the Implementation of the Service  . .... 173
5.4 BAdI SMOD_RSR00004  . ............................................................. 177
5.5 Implementing Own Read Routines for Master Data  ..................... 181
5.5.1 Creating a Master Data Read Class  .................................... 182
5.5.2 Sample Implementation of a Master Data Read Class  ........ 189
5.5.3 Entering the Class in the InfoObject  .................................. 196

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

6.1 Variables in Planning  ................................................................... 199


6.1.1 Variables in SAP BW-BPS  . ................................................. 200
6.1.2 Variables in SAP NetWeaver BI Integrated Planning  . ......... 208
6.2 Characteristic Value Derivations  ................................................... 211
6.2.1 Characteristic Value Derivations in SAP BW-BPS  ................ 211
6.2.2 Characteristic Value Derivations in SAP NetWeaver
BI Integrated Planning  . ..................................................... 220
6.3 Exit Functions in Planning  . .......................................................... 229
6.3.1 Exit Functions in SAP BW-BPS  ........................................... 230
6.3.2 Exit Functions in SAP NetWeaver BI Integrated Planning  .... 238
6.4 Conclusion  . ................................................................................. 246

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

Appendices

A Additional Extension Options  . .............................................................. 251


A.1 Other BAdIs and User Exits in SAP NetWeaver BI  ........................ 251
A.1.1 BAdIs  ................................................................................ 251
A.1.2 Exits  .................................................................................. 252
A.2 Generated Tables and Objects in SAP NetWeaver BI  .................... 252
A.2.1 Tables in InfoCubes  ........................................................... 253
A.2.2 Tables in DataStore Objects  ............................................... 254

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


Contents

A.2.3 Tables in InfoObjects  ......................................................... 254


A.2.4 Data Structures in the Dataflow  . ....................................... 255
A.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


4 User Exits in Data Import Processes

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.

4.1 Transformation

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.

49

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


4 UserExitsinDataImportProcesses

and target are specified 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
fields of the DataSource are transformed into the corresponding fields of the data
target.

Figure 4.1 Graphical Display of a Transformation

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 flows. 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 benefit 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,

50

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


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:


EE Exit for determining the key figures and data fields2
EE Exit for determining the characteristics and key fields3
EE Start routine
EE End routine
EE Expert routine

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.

4.1.1 Deriving Characteristics


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:

1. Double-click on the characteristic for which you want to create the routine. This
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.

51

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


4 UserExitsinDataImportProcesses

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

Figure 4.2 Creating a Routine

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 –

52

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


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_0METYPE
ENDCLASS.       “routine IMPLEMENTATION

Listing 4.1  Generated Characteristic Derivation Method

53

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


4 User Exits in Data Import Processes

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.

54

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


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
Listing 4.2  Method for Removing Special Characters

55

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


4 UserExitsinDataImportProcesses

4.1.2 Deriving Key Figures


The derivation of key figures and data fields occurs almost as often as the deriva-
tion of characteristics and key fields. 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 figures and data fields 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:

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

Figure 4.3 Creating a Routine with Unit Calculation

56

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


Transformation 4.1

2. Then you can select the Routine with Unit entry under the Rule Type item.
3. Click on the 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

57

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


4 User Exits in Data Import Processes

          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_0AMOUNT
ENDCLASS.    “routine IMPLEMENTATION

Listing 4.3  Key Figure Calculation with Unit Output

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

58

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


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’

59

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


4 User Exits in Data Import Processes

        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_0AMOUNT
ENDCLASS.    “routine IMPLEMENTATION

Listing 4.4  Currency Conversion in the Transformation

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.

4.1.3 Start Routine 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

60

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


Transformation 4.1

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

You can also efficiently 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 efficiently by using the DELETE SOURCE_PACKAGE WHERE ... statement.
Implementing an exception in the characteristic routine for the same purpose is
much less efficient because the data records first have to be specifically 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).

Figure 4.4 Button for Creating a Start Routine

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 defined as a changing parameter.

The annoying thing about the start routine in Release 3.x was that the fields 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 first 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.

61

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


4 User Exits in Data Import Processes

    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

62

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


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

63

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


4 User Exits in Data Import Processes

    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_routine
ENDCLASS.         “routine IMPLEMENTATION

Listing 4.5  Example of a Start Routine, Including Generated Method

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.

4.1.4 End Routine 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.

64

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


Index

0AMOUNT, 74 Business Consolidation, 173


0CURRENCY, 60 Business Explorer (BEx), 170, 199
0QUANTITY, 74 Business Planning and Simulation
(DTP), 76 (SAP BW-BPS), 199
_ty_s_SC_1, 54 BW_SCHEDULER, 251
_ty_s_TG_1, 54
_VALUES_GENERATE, 189, 192
C
A Cache, 22
CASE, 35
ABAP Objects, 47, 49, 54, 161 Characteristic, 176
ABAP query, 27 Virtual, 153
Account model, 74 Characteristic calculation, 122
Actual data, 199 Characteristic combination, 166, 242
ADD_NEW_BLOCKS, 242 Check, 150
Aggregation level, 228 Characteristic derivation, 51, 65, 199
ALV grid, 41 Characteristic relationship, 212
ANY TABLE, 36 Detail, 212
Application component, 27, 28 CHARACTERISTICS, 171
Hierarchy, 28 Characteristic value, 173, 211
Attribute derivation, 22, 213 Characteristic value combination
Authorization check, 26, 32 Check, 213
Create, 215
Characteristic value derivation, 211, 218
B Attribute derivation, 213
Hierarchical, 213
BAdI, 25, 45 SAP BW-BPS, 211
RSR_OLAP_BADI, 155, 156 SAP NetWeaver BI Integrated Planning,
RSU5_SAPI_BADI, 45, 46 220
SMOD_RSR00004, 177 Check
BAPI, 168 Characteristic combinations, 150
BAPI_INFOCUBE_READ_REMOTE_DATA, Class
170 CL_RSBM_LOG_CURSOR_STEP, 68
Structure, 172 CL_RSDRV_REMOTE_IPROV_SRV, 172
BAPI_INFOCUBE_READ_REMOTE_DATA, CL_RSMD_RS_GENERIC_DOMAIN, 181
171 CL_RSPLFC_BPS_EXITS, 246
Basic planning area, 211 Client, 182
BEx query, 210 CL_RSBM_LOG_CURSOR_STEP, 68
BI hierarchy, 83 CL_RSDRV_REMOTE_IPROV_SRV, 172
BPS0, 200 CL_RSMD_RS_GENERIC_DOMAIN, 181
Business Add-In (BAdI), 25 CL_RSPLFC_BPS_EXITS, 246

259

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


Index

CMOD, 32 Data record, 15


Code Sequence, 166
Dynamic, 20 Data selection, 171
Column DataSource, 26, 33, 45, 46, 49, 65, 84, 85,
Selection, 30 101, 168, 173
Combination check, 148, 213 Create, 85
Combination proposal, 213 Generic, 26, 29
Commitment data, 123 DataStore, 37, 174
Communication structure, 102, 107, 111, 118, Object, 84, 86, 133, 167
125, 129, 156, 157, 161 Data target, 74, 101
COMPUTE, 158, 161, 162, 163, 164, 165 Data target structure, 129
CONCATENATE, 79 Update, 23
CONSTRUCTOR, 165 Data transfer
Controlling area, 101 Logging, 105
Conversion, 32 Data transfer process (DTP), 76, 83, 98, 101
CONVERT_TO_FOREIGN_CURRENCY, 126 Characteristics selection, 79
CONVERT_TO_LOCAL_CURRENCY, 126 Selection of a file name, 77
Cost center category, 65 DATA_TRANSFORM, 45
CREATE, 183, 218 Data volume, 15
C_T_DATA, 36 Date-dependent default value assignment, 138
C_T_FOLDERT, 42 Default value, 114, 151
C_TH_DATA, 243 Default value assignment
C_T_HIENODE, 42 Date-dependent, 138
C_T_MESSAGES, 36 Table-dependent, 138
Currency conversion, 68 DEFINE, 158, 159, 161, 162
Customizing table, 108 Deletion
CX_RSROUT_ABORT, 54 Record, 61
CX_RSROUT_SKIP_RECORD, 54 Delta
Generic, 29
Delta upload, 29
D Derivation
Key figure, 56
DATA, 171 Distribution mechanism, 47
Database access, 22 DTP, 83
Database selection, 167
Data cleansing, 49, 61
Data enrichment, 18 E
Data flow, 50
Data mart interface, 174 Elimination of intercompany sales, 166
Data model, 101 End routine, 51, 60, 64, 65, 68, 83, 89, 97,
Data modeling, 41, 74, 116 100
Data owner, 31 Enterprise data warehouse, 50
Data package, 23, 30, 31, 34, 51, 105, 107, Error handling, 68, 120
121 SAP BW 3.x, 113
Data quality, 128 Table, 113

260

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


Index

Error message, 107, 149 Filter value, 133


Output, 128 Filter value determination, 82
Return, 152 FINISH_EXECUTION, 245
ET_MESG, 233 Fiscal year variant, 101, 182
ETO_CHAS, 233 Flat file, 26
EXECUTE, 243 FOX formula, 252
Exit function Full table scan, 19
SAP BW-BPS, 230 Full upload, 29
SAP NetWeaver BI Integrated Planning, Function
238 CREATE, 218
Exit function module, 233, 235 Specifically written, 199
EXIT_SAPLRRS0_001, 131, 163, 167 WS_UPLOAD, 230
EXIT_SAPLRSAP_001, 33, 34, 35 Function module, 32
EXIT_SAPLRSAP_002, 33 BAPI_INFOCUBE_READ_REMOTE_DATA,
EXIT_SAPLRSAP_003, 33 170, 171
EXIT_SAPLRSAP_004, 33, 43 Calculate data, 168
EXIT_SAPLRSBBS_001, 177, 178 CONVERT_TO_FOREIGN_CURRENCY, 126
EXIT_SAPLRSBBS_002, 177 CONVERT_TO_LOCAL_CURRENCY, 126
EXIT_SAPLRSR0_001, 133 Exit function module, 233, 235
Expert routine, 60, 65, 67, 68, 74, 76 EXIT_SAPLRRS0_001, 131
EXPERT_ROUTINE, 73 EXIT_SAPLRSAP_001, 33, 35
Export DataSource, 43 EXIT_SAPLRSAP_002, 33
Extraction, 25, 46 EXIT_SAPLRSAP_003, 33
SAP ERP, 38 EXIT_SAPLRSAP_004, 33, 43
Extractor, 34 EXIT_SAPLRSR0_001, 133
Add data records, 37 Fixed interface, 201
Generic, 25, 26, 29, 31, 43 Init function module, 232
Extractor checker, 30 RRMS_MESSAGE_HANDLING, 152, 153
Extract structure, 44 RSDRI_INFOPROV_READ, 174
Fill, 36 Z_VAR_CHECK_VALIDITY, 137, 148
Modify, 36

G
F
GET_ATTRIBUTES, 188, 193
Field GET_CAPABILITIES, 184
Change, 232 GET_REF_DATA_SEL, 240
Extension, 31 GET_TEXT, 187, 195
I_S_RKB1D-COMPID, 152 GET_VALUES, 185
Masking, 26 G_T_ERRORLOG, 113
Selection, 232
Symbol, 15, 20
FIELDNAME, 81 H
File name
Determine, 78 Hashed table, 17, 19, 22
File name selection, 77 HASHED TABLE, 17

261

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


Index

HAUPT_KST, 196 I_STEP, 132, 137, 142, 145, 146


Hierarchy, 26, 33, 41, 46, 82, 213 IT_EXITP, 233
Aggregation, 166 ITO_CHA, 233
BI hierarchy, 83 ITO_CHASEL, 233, 236
Exit, 43 ITO_KYF, 233
Extractor, 43 I_T_SELOPT, 185
Sorted, 82 I_TS_REQ_ATR, 186
HIER_TRANSFORM, 45, 46
History
Transformation, 68 K
KEYDATE, 170
I Key figure, 173, 176
Virtual, 153
IF_RSPLS_CR_METHODS~CHECK, 220 Key figure derivation, 56, 125
IF_RSPLS_CR_METHODS~CREATE, 224 Key figure model, 74
IF_RSPLS_CR_METHODS~DERIVE, 228 KEYFIGURES, 171
I_MAXROWS, 186
I message, 128
Implementation L
Logic, 54
Implementation name, 156 Line items report, 73
Import process, 55 Link node, 97
Include LISTCUBE, 176
ZXRSAU01, 34 Loading process, 15
ZXRSRU01, 131 Log, 76
Individual processing, 166 Logic
InfoCube, 61, 68, 128, 129, 166, 174, 177, Implementation, 54
232, 252 Loop, 18
Calculate result, 129 LOOP AT TABLE WHERE, 19
INFOCUBE, 170
InfoObject, 37, 97, 153, 196, 219, 241
Derivation, 108, 114
M
HAUPT_KST, 196
InfoPackage, 44, 78, 98, 99, 107, 118, 133 Mapping, 177
InfoProvider, 49, 67, 101, 102, 153, 155, 166, Mapping table, 37
167, 168, 176, 181, 199 Masking, 31
InfoSource, 50, 67, 101, 102, 120 Master data attribute, 17, 33
INIT_EXECUTION, 239 Master data read class, 196, 197
Init function module, 232 Create, 182
Initialization, 61 Implementation, 189
INITIALIZATION, 158, 161, 162 Master data read routine, 181
Instance attribute, 161 Master data table, 174
INVALID, 213 Master data text, 33
INVERSE_EXPERT_ROUTINE, 73 Message, 106
INVERSE_EXPERT_SELECTION, 73 Message class, 106

262

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


Index

Message collector, 152 O


Method
ADD_NEW_BLOCKS, 242 Object reference, 246
COMPUTE, 158, 161, 162, 163, 165 ODS object, 84
CONSTRUCTOR, 165 OLAP processor, 171
CREATE, 183 O notation, 20
DATA_TRANSFORM, 45 OPENHUB_TRANSFORM, 251
DEFINE, 158, 161, 162 Original object, 26
EXECUTE, 243
EXIT_SAPLRSBBS_001, 177, 178
EXIT_SAPLRSBBS_002, 177
P
EXPERT_ROUTINE, 73
FINISH_EXECUTION, 245 Parameter
GET_ATTRIBUTES, 188, 193 I_IOBJNM, 134
GET_CAPABILITIES, 184 I_MAXROWS, 186
GET_REF_DATA_SEL, 240 I_PERIV, 135
GET_TEXT, 187, 195 I_S_COB_PRO, 134
GET_VALUES, 185 I_S_RKB1D, 134
HIER_TRANSFORM, 46 I_STEP, 132, 135, 137, 142, 145, 146
IF_RSPLS_CR_METHODS~CHECK, 220 I_T_VAR_RANGE, 135
IF_RSPLS_CR_METHODS~CREATE, 224 I_VARTYP, 134
IF_RSPLS_CR_METHODS~DERIVE, 228 I_VNAM, 134
INIT_EXECUTION, 239 Parent ID, 97
INITIALIZATION, 158, 161, 162 Performance, 15, 16, 20, 68, 73, 112, 114,
INVERSE_EXPERT_ROUTINE, 73 116, 118, 154, 167
SET_KEY_DATE, 183 Per data record, 15
_VALUE_GENERATE, 189, 192 Period entries, 150
_VALUES_GENERATE, 189 Persistent staging area (PSA), 23, 120
Methode Planning function, 199, 204, 236
INVERSE_EXPERT_SELECTION, 73 Create, 230
Microsoft Excel Planning level, 200, 211
Table, 82 Plan version, 202
Modeling Position selection, 65
Graphical, 51 Pre-assignment, 204
MONITOR_RECNO, 120 Based on authorizations, 139
Multi-planning area, 211 Process chain, 252
MultiProvider, 154, 168, 177 Process types, 252
Program
Activated, 120
N PSA, 23, 31, 77, 120

Navigation attribute, 171, 196


Navigation block, 133
Q
Next ID, 98
Quantity unit
Conversion, 59

263

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


Index

Quarterly report, 149 RSOD_WWW_DOC_MAINT, 252


Query, 173 RSR00001, 131
Query creation, 208 RSR00002, 155
Query Designer, 145 RSR00004, 177
Query name, 181 RSRA_ALERT, 251
RSR_OLAP_AUTH_GEN, 251
RSR_OLAP_BADI, 155, 156
R RSU5_SAPI_BADI, 45, 46

RAISE EXCEPTION, 152


RANGES table, 206 S
Read access
Table, 18 SAP BW-BPS, 199, 252
Read routine Variable, 208
For master data, 181 Variable concept, 200
READ TABLE, 18 SAP ERP, 199
READ TABLE INDEX, 19 SAP NetWeaver 7.0, 49, 51, 67, 82, 83, 84,
READ TABLE WITH KEY, 19 85, 98, 100, 155, 166
READ TABLE WITH TABLE KEY, 19 SAP NetWeaver BI Integrated Planning, 199
Record Characteristic value derivation, 220
Delete, 61 Exit function, 238
Reference data, 239, 241, 244 Variable, 208
RemoteCube, 114, 168 SAP SEM-BCS, 173
Removal SBIW, 28
Special character, 55 SE19, 155
Report-report interface, 73, 177, 178 SE80, 182, 189, 220
RESULT_PACKAGE, 72 SE91, 153
RESULT_TABLE, 129 Selection, 30
RETURN, 170 SELECTION, 170
Return table, 101, 129 Selection condition, 228
RFC Packing, 169, 172 Selection field, 30, 44
Rounding difference, 168 Select, 30
Routine Selection option variable, 210
Create, 77 SEMBPS01, 252
Unit, 57 SEMBPS02, 252
RRMS_MESSAGE_HANDLING, 152, 153 SET_KEY_DATE, 183
RSA3, 30 SID Support, 169, 172
RSAP0001, 31, 32, 45 Single value, 203
RSAR_CONNECTOR, 251 Return, 201
RSBBS, 177 SMOD_RSR00004, 177
RSDBC_SQL_STATEMENT, 251 Sorted hierarachy, 82
RSDRI_INFOPROV_READ, 174 Sorted table, 16, 19
RSO2, 26, 27 SORTED TABLE, 16
RSOD_DOC_BADI, 252 Source characteristic, 219
RSOD_ITEM_DOC, 252 SOURCE_PACKAGE, 61
RSOD_ITEM_DOC_LIST, 252 Source structure, 76

264

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


Index

Source system, 26, 73, 101, 113, 114 Table access, 18


Special character Table definition, 18
Removal, 55 Table-dependent default value assignment,
Standard deviations, 166 138
Standard extractor, 25, 31 Table entry
Enhancement, 25, 26 Read, 165
Standard table, 16, 19 Table type
STANDARD TABLE, 16 Programming example, 16
Start routine, 51, 60, 64, 65, 68, 83, 100, 102, Table types, 15, 16
104, 113, 118, 120, 129 Target structure, 76
Create, 88 TCURR, 26, 29, 40
Transfer rule, 31 Transaction
S_T_TCURF, 40 BPS0, 200
SY-DATE, 79 CMOD, 32
LISTCUBE, 176
RSA3, 30
T RSBBS, 177
RSO2, 26, 27
Table, 27 RSRT, 74
C_T_DATA, 36 SBIW, 28
C_T_FOLDERT, 42 SE19, 155
C_TH_DATA, 243 SE80, 182, 189, 220
C_T_HIENODE, 42 SE91, 106, 114, 153
C_T_MESSAGES, 36 Transaction data, 27, 33
Customizing table, 108 Transfer rule, 49, 100, 101, 102, 104, 113
ET_MESG, 233 Start routine, 31
ETO_CHAS, 233 Transfer structure, 105, 112, 113
E_T_RANGE, 135 Transformation, 49, 50, 60, 64, 82
G_T_ERRORLOG, 113 Graphical display, 49
Hashed table, 17, 19, 22, 104 History, 68
IT_EXITP, 233 Transport, 68
ITO_CHA, 233 Type
ITO_CHASEL, 233, 236 _ty_s_SC_1, 54
ITO_KYF, 233 _ty_s_TG_1, 54
I_T_SELOPT, 185
I_TS_REQ_ATR, 186
L_T_RANGE, 81 U
Mapping table, 37
MONITOR_RECNO, 120 Unit calculation, 56, 126
RESULT_PACKAGE, 72 Update rule, 22, 49, 60, 100, 101, 102, 113,
RESULT_TABLE, 129 116, 118, 120, 122, 125, 126, 129
Sorted table, 16, 19 Example, 117
Standard table, 16, 19 Upload, 17
S_T_TCURF, 40 Usage type, 25
TCURR, 26, 29, 40
XTH_DATA, 236

265

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


Index

User exit, 25, 32, 41, 44 Variable determination


EXIT_SAPLRRS0_001, 163, 167 Example, 144
Planning, 199 Variable exit, 131, 200
RSAP0001, 31, 32, 45 ZXRSRU01, 137
RSR00002, 155 Variable Exit
RSR00004, 177 RSR00001, 200
Variation, 166
View, 27
V Virtual characteristic, 153
Virtual key figure, 153
Validation, 132, 148 VirtualProvider, 73, 168, 174, 176, 177
Of an individual variable, 148 Implementation, 173
Value set
Return, 204, 206
Value type, 123 W
Variable, 131, 199
Central, 147 WS_UPLOAD, 230
Check, 147
Combination, 148
Derivation, 145 X
Handling, 147
Planning, 199 X message, 170
Project-specific, 147 XTH_DATA, 236
Read, 208
SAP BW-BPS, 200, 208
SAP NetWeaver BI Integrated Planning,
Z
208
Selection option variable, 210 Z_VAR_CHECK_VALIDITY, 137
Set, 201 ZXRSAU01, 34
Strategy, 148 ZXRSRU01, 131, 137
Transfer, 166, 210
Values, 166
Write, 210

266

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

Potrebbero piacerti anche