Académique Documents
Professionnel Documents
Culture Documents
Dirk Herzog
Contents
www.sap-press.com 1
Contents
Whereas the adjustment of extractor results predomi- In addition, you have the option to display the rules
nantly occurs only with selected DataSources, most data graphically. Figure 4.1 shows the graphical display of the
import processes in SAP NetWeaver BI involve a user exit transformation in SAP NetWeaver 2004s. The data source
that is run through between the DataSource and the Info- and target are specified in the header next to the name
Provider. This may be done for conversion purposes, for of the transformation. Below the header, the graphic dis-
the derivation of new characteristics, or for data cleansing. plays a section of the data source structure, while the
Because the entire logic of SAP NetWeaver Business Intel- right-hand part of the graphic displays a section of a rule
ligence has been changed significantly in SAP NetWeaver group. The rule group is a structure that corresponds to
2004s, Section 4.1 provides a detailed description of the structure of the data target. It is supposed to enable
the transformation options that have been newly imple- you to derive several data records in the data target from
mented. Compared to the options available in the transfer one source record, as is possible in SAP BW 3.x. The
and update rules, the transformation options have been arrows displayed in the graphic indicate which fields of
extended substantially and provide new features. the data source are transformed into the corresponding
The only “disadvantage” is that methods are generated fields of the data target.
instead of form routines, which is why the code of the Along with the improved exit implementation options,
exit itself is checked for the more rigid syntax of ABAP you should also use the transformation option for newly
Objects. However, those of you who want to become created objects in SAP NetWeaver 2004s. It depends on
more engaged in this subject matter will probably con- each individual case whether it is worthwhile to convert
sider this an advantage, as it enables you to employ a the old data flows. In any event, you should consider this
clean and consistent way of programming. And those of in cases where only InfoObject assignments are used in
you who still don't want to be involved still have the the update or transfer rules and where you can delete the
chance to call a function module and thus return to the InfoSource being used. In all other cases, it is only worth
good old ABAP syntax. the effort if you want to revise the rule completely, ben-
efit from the advantages provided by the new routines,
or if you have to standardize the routines in order to keep
4.1 Transformation
a clear overview of SAP NetWeaver BI. The last issue is
The method of transformation was newly introduced for especially necessary in enterprise data warehouses, and
SAP NetWeaver 2004s. It standardizes the transfer and I'd say that anyone who has carried out at least three
update rules taken from SAP BW 3.x. While the transfer different projects with three different project teams will
rules were only applied between DataSources and Info- agree that it is absolutely necessary to implement a cer-
Sources and the update rules only between InfoSources tain structure.
and InfoProviders1, the transformation can be used to
link any data source to the data targets.
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 Admin-
istrator Workbench.
www.sap-press.com 25
4 User Exits in Data Import Processes
The transformation contains a total of five exits: following sections, you'll see how much the end routine
왘 Exit for determining the key figures and data fields2 and the expert routine can improve your life as a pro-
왘 Exit for determining the characteristics and key fields 3
grammer.
왘 Start routine
왘 End routine Deriving Characteristics
왘 Expert routine The derivation of characteristics and key fields is certainly
the simplest type of derivation in the context of BW exits
The expert routine completely replaces the graphical because it contains the fewest variants. The characteris-
modeling process and enables you to convert each data tic derivation is required in many different scenarios: for
package from the source into the target structure in a instance, if fields from the source system are not deliv-
single routine. In SAP NetWeaver 2004s, the end routine ered, if the fields in the source system have a different
and the expert routine have been newly implemented in structure than those in SAP NetWeaver BI, if a conversion
the transformation, while the transfer and update rules needs to be performed, or if time characteristics must
in SAP BW 3.x only contained the first three exits. In the be converted for which no standard conversion has been
implemented.
2 If you update into an InfoCube, only the key figures are cal-
culated, whereas if you update into a DataStore object (in 1. To create a routine for deriving characteristics, dou-
SAP BW 3.x: ODS object) all data fields are calculated. In an ble-click on the characteristic for which you want to
InfoObject it is the attributes and texts that are calculated.
3 Similarly, in this exit the characteristics are determined in an create the routine. This takes you to the Rule Details
InfoCube, the key fields in a DataStore, while the value of an dialog.
InfoObject and of compounded characteristics, if available,
and are determined in an InfoObject.
2. Here you must select the item Routine in the Rule METHODS
Type field. Then you can create the routine by click- compute_0METYPE
ing on the Create button next to the field (see Figure IMPORTING
4.2). 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
Figure 4.2 Creating a Routine RAISING
cx_rsrout_abort
SAP NetWeaver BI then generates a main class that cx_rsrout_skip_record.
will contain only the implementation. Listing 4.1 ENDCLASS. "routine DEFINITION
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 * CLASS routine IMPLEMENTATION
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 IMPLEMENTATION.
*---------------------------------------*
* CLASS routine DEFINITION METHOD compute_0METYPE.
*---------------------------------------* DATA:
* MONITOR_REC TYPE rsmonitor.
*---------------------------------------* *$*$ begin of routine - insert your code
CLASS routine DEFINITION. * only below this line *-*
PUBLIC SECTION. ... "insert your code here
*-- fill table "MONITOR" with values of
TYPES: *- structure "MONITOR_REC"
BEGIN OF _ty_s_SC_1, *- to make monitor entries
* InfoObject: 0METYPE Key Figure Type. ... "to cancel the update process
METYPE TYPE /BI0/OIMETYPE, * raise exception type
END OF _ty_s_SC_1. * CX_RSROUT_ABORT.
TYPES: ... "to skip a record
BEGIN OF _ty_s_TG_1, * raise exception type
* InfoObject: 0METYPE Key Figure Type. * CX_RSROUT_SKIP_RECORD.
METYPE TYPE /BI0/OIMETYPE, * result value of the routine
END OF _ty_s_TG_1. RESULT = .
PRIVATE SECTION.
TYPE-POOLS: rsd, rstr. *$*$ end of routine - insert your code
*$*$ begin of global - insert your * only before this line *-*
* declaration only below this line *-* ENDMETHOD. "compute_0METYPE
... "insert your code here ENDCLASS. "routine IMPLEMENTATION
*$*$ end of global - insert your Listing 4.1 Generated Characteristic Derivation Method
* declaration only before this line *-*
www.sap-press.com 27
4 User Exits in Data Import Processes
If you are not yet familiar with object-oriented program- processing of the data package. The new development
ming, you shouldn't panic. Because the main class is pre- can be regarded as a significant step forward, given that
defined, you can focus entirely on implementing the logic the handling of the RETURNCODE parameter was not very
and don't need to bother about inheritance, interfaces, intuitive in SAP BW 3.x. It used to behave differently in
attributes, and so on. At this point that's much easier the transfer rules, where it didn't cause any error mes-
even than implementing a Business Add-In. sage, and in the update rules, where it actually did pro-
But let's take a detailed look at Listing 4.1. At the duce errors.
beginning, two types are defined: _ty_s_SC_1 and _ty_ Apart from that, the implementation is almost identi-
s_TG_1. The contents of both types depend on the fields cal to that of the transfer and update rules in SAP BW 3.x
you want to link to each other in the graphical model- despite the fact that some parameter names have been
ing process. In the most simple case, which is the one slightly changed. This means that you don't need to learn
described above, it is only the field 0METYPE of the data anything new and can simply copy the existing code in
source that is linked to the field 0METYPE of the data tar- almost all cases.
get. Therefore, both types obtain exactly this field. The only restriction is that the more rigid ABAP
In the subsequent section, you can define global data Objects syntax is checked here. But those of you who
objects. All data definitions that you make here occur in simply cannot do without the tables and headers and all
all routines created in this transformation so that you can those other precious gadgets in ABAP just need to call a
transfer data from one routine into another. function module at this point to have the entire range of
The next section of the listing contains the definition ABAP relics at your disposal again.
of the method. ABAP Objects distinguishes between the
definition and the implementation of the method, which Example: Removing Special Characters
is why the interface is first defined at this stage. In addition A typical problem that regularly occurs when importing
to the request and data-package numbers, the interface data from external systems is that input fields such as
contains the structure SOURCE_FIELDS as import param- family names and addresses can contain special char-
eter. The type of this structure is _ty_s_SC_1 defined acters, for instance in foreign addresses or incorrect
above and contains the selected fields of the source entries. The best way to catch them is to use a rou-
structure. The only available export parameters are the tine. In Listing 4.2, all special characters are replaced
RESULT field for the result and the MONITOR table for he by blank space characters in an InfoObject called NAME
error messages. The RETURNCODE and ABORT flags that are that has the type CHAR(60).
available in SAP BW 3.x are now replaced by correspond- Simple routines like this one significantly increase the
ing exceptions. To skip the data record, you should insert stability of the import processes and thus reduce the
the statement RAISE cx_rsrout_skip_record, whereas maintenance requirements.
RAISE cx_rsrout_abort enables you to abort the entire
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
Deriving Key Figures 1. You must select a key figure in your data target and
The derivation of key figures and data fields occurs almost double-click on it to open the Rule Details dialog
as often as the derivation of characteristics and key fields. you are already familiar with (see Figure 4.3).
For example, it is used for simple calculations (invoice 2. Then you can select the Routine with Unit entry
amount = catalog price + extras – discount). However, under the Rule Type item.
characteristics derivations do also occur here if the char- 3. Click on the Change button next to the rule type to
acteristics are contained in the data component of Data- open the ABAP Editor. The system then automatically
Store objects. generates the code shown in Listing 4.3.
The derivation of key figures and data fields in the
transformation can be as simple as the derivation of char- You can use the key figure calculation with unit output for
acteristics; it even uses exactly the same routine. There is two different types of units: quantity units and curren-
one little difference, and that's the calculation of units in cies. While you should calculate currencies using a cor-
the routine. Here is how that now works. responding currency conversion key, the above routine is
the only way to perform a quantity unit conversion.
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,
www.sap-press.com 29
4 User Exits in Data Import Processes
*$*$ 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
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.
*$*$ end of routine - insert your code only before this line *-*
ENDMETHOD. "compute_0AMOUNT
ENDCLASS. "routine IMPLEMENTATION
It can be necessary to convert currencies, as otherwise *-- fill table "MONITOR" with values of
the process terminates because data records are imported *- structure "MONITOR_REC"
that don't contain any information on the amount or *- to make monitor entries
source currency. In that case, you should perform the ... "to cancel the update process
currency conversion by yourself. Listing 4.4 shows you * raise exception type
how to do that. * CX_RSROUT_ABORT.
CLASS routine IMPLEMENTATION. ... "to skip a record
* raise exception type
METHOD compute_0AMOUNT. * CX_RSROUT_SKIP_RECORD.
* Here the provided currency is * result values of the routine
* converted into Euro. If no currency IF SOURCE_FIELDS-CURRENCY IS INITIAL.
* is delivered, 0 Euro is returned. RESULT = 0.
DATA: CURRENCY = 'EUR'.
MONITOR_REC TYPE rsmonitor. ELSE.
CALL FUNCTION
*$*$ begin of routine - insert your code 'CONVERT_TO_LOCAL_CURRENCY'
* only below this line *-* EXPORTING
... "insert your code here DATE = sy-date
www.sap-press.com 31
4 User Exits in Data Import Processes
PROGRAM trans_routine.
*---------------------------------------*
* CLASS routine DEFINITION
*---------------------------------------*
*
*---------------------------------------*
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.
*$*$ 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
*---------------------------------------*
*
*---------------------------------------*
CLASS routine IMPLEMENTATION.
*---------------------------------------*
* Method start_routine
*---------------------------------------*
www.sap-press.com 33
4 User Exits in Data Import Processes
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 thos lines that have an order as partner objects.
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>.
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'.
*$*$ end of routine - insert your code only before this line *-*
ENDMETHOD. "start_routine
ENDCLASS. "routine IMPLEMENTATION
The importing parameters of the start routine are the tant parameter, however, is the actual SOURCE_PACK-
request and the data package ID; its exporting parameter AGE table that contains the data records and is defined
is the table containing the error records. The most impor- as a changing parameter.
www.sap-press.com 109
Index