Sie sind auf Seite 1von 15

ABAP Programming in BW

ABAP Programming in BW
ABAP Programming in BW

Table of Contents

1.0 Purpose & Objective 3


2.0 Scope 3
3.0 Common Implementation scenarios of ABAP Programming in BW 4
4.0 Using Field Symbols in Routines 9
5.0 Difference between Transfer/Update Rules and Transformations 10
6.0 List of SAP Standard Programs/Function Modules/Classes 11
7.0 Optimisation considerations 14
8.0 Tips for code changes 15
9.0 Variants 15
ABAP Programming in BW

Purpose
 The purpose of this document is to outline and define concepts and strategies that
constitute best practices regarding the use of ABAP programming in BW.
 It is strongly suggested that all staff (both senior and new hires) follow this
document closely.

Objective
 Objective of this document is to develop programming process guidelines and
development standards considering the possibilities exist for using ABAP to
customize the BW environment to transform the data as requirements dictate, as
well as provide additional processing during extraction and updates.

Scope
ABAP Programming Scope in BW and R/3 extractors

Technical Area Description


BEx User Exit Allows the creation and population of variables and
calculations for key figures and variables on a runtime basis.
This user exit is called each time BEx is executed.
R/3 User Exit This user exit is found in R/3 under CMOD and contains
additional programming that is needed to fill field additions to
extract structures. We can also create additional business
logic against data prior to its transfer to BW.
BW Transformation Transformation routines are part of transformation rules
Routines which are invoked as data is transferred from R/3 to BW
Data targets, or from within BW from one infoprovider to
another. Transformation rules are each infoobject specific.
BW Start Routines Start routines in BW Transformations are used to manage
whole subsets of source data before Transformation rules are
triggered.
BW End Routines End routines in BW Transformations are used to manage whole
subsets of resulting data from Start routine and
Transformation Rules.
BW Expert Routines Expert Routine is a new feature in BI 7.0 which enables user
can define exactly how the Transformation works. Expert
routines are used only in special scenarios. When an expert
routine is created then all transformations rules along with
start and end routines will get deleted. Some times exert
routines improves the performance of data load even further.
BW DTP Routines DTP Routines are used to do some filtering and calculations on
the selection screen fields depending on the business
requirement.
ABAP Programming in BW

BW Infopackage Infopackage level routines are used to in scenarios like if


Routines source system need to be selected dynamically, selecting file
name dynamilcally and filtering data coming from source flat
file.

Common Implementation scenarios of ABAP Programming in BW

For BI 7.0, in data staging, there are many aspects that we can write abap
code to deal with data.

1. InfoPackage Routine

The infopackage routine given below is an example to create dynamic file name.

2. Start Routines
ABAP Programming in BW

Start routines are processed:

---After the data in written into the PSA

---Before the transformation is processed

Actually, we write ABAP code here is for data cleansing or data consolidation.

3. Transformation Rules

It is processed in the transformation and actually this routine is written for some
particular fields.

In the transformation, select the particular field and right click the rule detail, in the
rule type, choose 'Routine'.
ABAP Programming in BW

4. End Routine
End Routine is processed after transformation, actually for data cleansing.
ABAP Programming in BW

5. Expert Routine
This type of routine is only intended for use in special cases. You can use the expert routine
if there are not sufficient functions to perform a transformation. The expert routine
should be used as an interim solution until the necessary functions are available in the
standard routine.

While writing routines, in order to dramatically improve performance, the following steps
should be taken:

 Use Internal Tables of Master Data (instead of direct read of physical P-Tables)

 Make minimum Select and Read statements.

 Necessary Select and Read statements should be executed efficiently by using


(Sort & Binary Search).

Example for the Expert Routine

*Global Section

TYPES:

BEGIN OF CUSTOMER_DATA,

CUSTOMER LIKE /BI0/PCUSTOMER-CUSTOMER,

CUST_CLAS LIKE /BI0/PCUSTOMER-CUST_CLAS,

SALES_OFF LIKE /BI0/0CUSTOMER-SALES_OFF,

END OF CUSTOMER_DATA.TYPES:

BEGIN OF ZCUSTSALES_DATA,

ZCUSTSALES LIKE /BIC/PZCUSTSALE-ZCUSTSALE,

DISTR_CHAN LIKE /BIC/PZCUSTSALE-DISTR_CHAN,

SALES_GRP LIKE /BIC/PZCUSTSALE-SALES_GRP,

END OF CUSTOMER_DATA.

DATA:
ABAP Programming in BW

LINE_CUSTOMER_DATA TYPE CUSTOMER_DATA,

LINE_ZCUSTSALE_DATA TYPE ZCUSTSALE_DATA,

ITAB_CUSTOMER_DATA LIKE SORTED TABLE OF LINE_CUSTOMER_DATA,

ITAB_ZCUSTSALE_DATA LIKE SORTED TABLE OF LINE_ZCUSTSALE_DATA.

*Begin of Expert Routine:

*Make the proper Select Statements before(!) looping on the DataPackage

*fill 0CUSTOMER master data into Internal Table:

SELECT DISTINCT CUSTOMER CUST_CLAS SALES_OFF

FROM /BI0/PCUSTOMER

INTO CORRESPONDING FIELDS OF TABLE ITAB_CUSTOMER_DATA

WHERE OBJVERS EQ 'A'.

*fill ZCUSTSALE master data into Internal Table:

SELECT DISTINCT ZCUSTSALE DISTR_CHAN SALES_GRP

FROM /BI0/PZCUSTSALE

INTO CORRESPONDING FIELDS OF TABLE ITAB_ZCUSTSALE_DATA

WHERE OBJVERS EQ 'A'.

*Loop on Data Package to make proper assignments:

DATA:

LINE_DATA_PACKAGE LIKE LINE OF DATA_PACKAGE.

LOOP AT DATA_PACKAGE INTO LINE_DATA_PACKAGE.


ABAP Programming in BW

*make direct assignments for Result Fields:

RESULT_FIELDS-MATERIAL = LINE_DATA_PACKAGE-MATERIAL.

RESULT_FIELDS-CUSTOMER = LINE_DATA_PACKAGE-CUSTOMER.

RESULT_FIELDS-ZCUSTSALE = LINE_DATA_PACKAGE-ZCUSTSALE.

RESULT_FIELDS-CALMONTH = LINE_DATA_PACKAGE-CALMONTH.

*Read the proper CUSTOMER data from Internal Table using Binary Search.

CLEAR LINE_CUSTOMER_DATA.

READ ITAB_CUSTOMER_DATA WITH KEY

CUSTOMER = LINE_DATA_PACKAGE-CUSTOMER

INTO LINE_CUSTOMER_DATA BINARY SEARCH.

*Assign read values to Result Fields:

RESULT_FIELDS-CUST_CLAS = LINE_DATA_PACKAGE-CUST_CLAS.

RESULT_FIELDS-SALES_OFF = LINE_DATA_PACKAGE-SALES_OFF.

*Read the proper ZCUSTSALE data from Internal Table using Binary Search.

CLEAR LINE_ZCUSTSALE_DATA.

READ ITAB_ZCUSTSALE_DATA WITH KEY

ZCUSTSALE = LINE_DATA_PACKAGE-ZCUSTSALE

INTO LINE_ZCUSTSALE_DATA BINARY SEARCH.

*Assign read values to Result Fields:

RESULT_FIELDS-DISTR_CHAN = LINE_DATA_PACKAGE-DISTR_CHAN.
ABAP Programming in BW

RESULT_FIELDS-SALES_GRP = LINE_DATA_PACKAGE-SALES_GRP.

APPEND RESULT_FIELDS TO RESULT_PACKAGE.

ENDLOOP.

Using Field Symbols in Routines


Field symbols are placeholders or symbolic names for other fields. They do not
physically reserve space for a field, but point to its contents. A field symbol cam
point to any data object. The data object to which a field symbol points is assigned
to it after it has been declared in the program.

Whenever you address a field symbol in a program, you are addressing the field that
is assigned to the field symbol. After successful assignment, there is no difference
in ABAP whether you reference the field symbol or the field itself. You must assign
a field to a field symbol before you can address it in a program.

Example of using Field Symbols in Routines.

Differences between Transfer/Update Rules and Transformations


 In BI 7.0 environment, transformation (formerly called Update/Transfer rules)
requires object oriented ABAP and here are some difference worth noting down
between Object oriented ABAP and ABAP which would help you in working with BI
7.0.

BW 3.5 BI 7.0

Internal Table DATA: BEGIN OF It's 2 step process in BI 7.0. 1st step
INT_EBELN OCCURS 0, declare the structure and in 2nd step
OI_EBELN LIKE declare Internal table referring to the
/BI0/POI_EBELN- above structure
OI_EBELN, TYPES: BEGIN OF INT_EBELN_STRU,
/BIC/ZMEXPDGRP LIKE OI_EBELN TYPE
/BI0/POI_EBELN- /BI0/POI_EBELN-OI_EBELN,
/BIC/ZMEXPDGRP, /BIC/ZMEXPDGRP TYPE
/BIC/ZMPOVERNO LIKE /BI0/POI_EBELN-/BIC/ZMEXPDGRP,
/BI0/POI_EBELN- /BIC/ZMPOVERNO TYPE
/BIC/ZMPOVERNO, /BI0/POI_EBELN-/BIC/ZMPOVERNO,
/BIC/ZMPURSTAT LIKE /BIC/ZMPURSTAT TYPE
/BI0/POI_EBELN- /BI0/POI_EBELN-/BIC/ZMPURSTAT,
/BIC/ZMPURSTAT, /BIC/ZMPORLSON TYPE
/BIC/ZMPORLSON LIKE /BI0/POI_EBELN-/BIC/ZMPORLSON,
/BI0/POI_EBELN- /BIC/ZMVALD_PO TYPE
ABAP Programming in BW

/BIC/ZMPORLSON, /BI0/POI_EBELN-/BIC/ZMVALD_PO,
/BIC/ZMVALD_PO LIKE END OF INT_EBELN_STRU.
/BI0/POI_EBELN- DATA: INT_EBELN TYPE TABLE OF
/BIC/ZMVALD_PO, INT_EBELN_STRU.
END OF INT_EBELN.

Reading data READ TABLE INT_EBELN 1st define a Work area and read from
from Internal INTO WA_PO WITH KEY there.
Table OI_EBELN = WA_PO LIKE LINE OF INT_EBELN à
DATA_PACKAGE-OI_EBELN Work Area
BINARY SEARCH. READ TABLE INT_EBELN INTO
IF SY-SUBRC = 0. WA_PO WITH KEY
DATA_PACKAGE- OI_EBELN =
/BIC/ZMVALD_PO = WA_DATA_PACKAGE-OI_EBELN
WA_PO-/BIC/ZMVALD_PO. BINARY SEARCH.
DATA_PACKAGE- IF SY-SUBRC = 0.
/BIC/ZMEXPDGRP = WA_DATA_PACKAGE-
WA_PO-/BIC/ZMEXPDGRP. /BIC/ZMVALD_PO = WA_PO-
DATA_PACKAGE- /BIC/ZMVALD_PO.
/BIC/ZMPORLSON = WA_DATA_PACKAGE-
WA_PO-/BIC/ZMPORLSON. /BIC/ZMEXPDGRP = WA_PO-
DATA_PACKAGE- /BIC/ZMEXPDGRP.
/BIC/ZMPURSTAT = WA_DATA_PACKAGE-
WA_PO-/BIC/ZMPURSTAT. /BIC/ZMPORLSON = WA_PO-
/BIC/ZMPORLSON.
WA_DATA_PACKAGE-
/BIC/ZMPURSTAT = WA_PO-
/BIC/ZMPURSTAT.

Data Package Data: DATA_PACKAGE type table of


_ty_s_SC_1,
WA_DATA_PACKAGE LIKE LINE
OF DATA_PACKAGE.

Loop Statement LOOP AT DATA_PACKAGE. LOOP AT DATA_PACKAGE INTO


WA_DATA_PACKAGE

List of useful SAP Standard Programs/Function Modules/Classes

Program name Description

RSCDS_NULLELIM Delete fact table rows where all Key Figure values are zero. See Note
ABAP Programming in BW

619826.

RSDG_CUBE_ACTIVATE Activation of InfoCubes

RSDG_CUBE_COPY Make InfoCube Copies

RSDG_CUBE_DELETE Delete InfoCubes

RSDG_DODS_REPAIR Activation of all ODS Objects with Navigation Attributes

RSDG_ODSO_ACTIVATE Activation of all ODS Objects

RSDG_IOBJ_ACTIVATE Activation of all InfoObjects

RSDG_IOBJ_DELETE Deletion of InfoObjects

RSDG_IOBJ_REORG Repair InfoObjects

RSDG_IOBJ_REORG_TEXTS Reorganization of Texts for InfoObjects

RSDG_MPRO_ACTIVATE Activating Multiproviders

RSDG_MPRO_COPY Make Multiprovider Copies

RSDG_MPRO_DELETE Deleting Multiproviders

RS_COMSTRU_ACTIVATE_ALL Activate all inactive Communication Structures

RS_TRANSTRU_ACTIVATE_ALL Activate Transfer Structure

RSAU_UPDR_REACTIVATE_ALL Activate Update Rules

RRHI_HIERARCHY_ACTIVATE Activate Hierarchies

SAP_AGGREGATES_ACTIVATE_FILL Activating and Filling the Aggregates of an InfoCube

SAP_AGGREGATES_DEACTIVATE Deactivating the Aggregates of an InfoCube

RS_PERS_ACTIVATE Activating Personalization in Bex(Inactive are highlighted)

RSSM_SET_REPAIR_FULL_FLAG Convert Full Requests to Repair Full Requests

SAP_INFOCUBE_DESIGNS Print a List of Cubes in The System and Their Layouts

SAP_ANALYZE_ALL_INFOCUBES Create DB Statistics for all InfoCubes

SAP_CREATE_E_FACTTABLES Create Missing E-Fact Tables for InfoCubes and Aggregates

SAP_DROP_EMPTY_FPARTITIONS Locate/Remove Unused or Empty partitions of F-Fact Table

SAP_DROP_TMPTABLES Remove Temporary Database Objects

SAP_RSADMIN_MAINTAIN Add, change, delete RSADMIN table entries


ABAP Programming in BW

CUBE_SAMPLE_CREATE A fast way to put some "sample" records in an InfoCube. No need to


use Flat files, just enter the value in an ALV-Grid or let fill the Cube
with random value.

SAP_CONVERT_NORMAL_TRANS Convert Basic Cube to Transactional Cube and the opposite way
around.

Function Module Description (Function Group RRMX)

RRMX_WORKBOOK_DELETE Delete BW Workbooks permanently from Roles & Favorites

RRMX_WORKBOOK_LIST_GET Get list of all Workbooks

RRMX_WORKBOOK_QUERIES_GET Get list of queries in a workbook

RRMX_QUERY_WHERE_USED_GET Lists where a query has been used

RRMX_JUMP_TARGET_GET Get list of all Jump Targets

RRMX_JUMP_TARGET_DELETE Delete Jump Targets

MONI_TIME_CONVERT Used for Time Conversions.

CONVERT_TO_LOCAL_CURRENCY Convert Foreign Currency to Local Currency.

CONVERT_TO_FOREIGN_CURRENCY Convert Local Currency to Foreign Currency.

TERM_TRANSLATE_TO_UPPER_CASE Used to convert all texts to UPPERCASE

UNIT_CONVERSION_SIMPLE Used to convert any unit to another unit. (Ref. table : T006)

TZ_GLOBAL_TO_LOCAL Used to convert timestamp to local time

FISCPER_FROM_CALMONTH_CALC Convert 0CALMONTH or 0CALDAY to Financial Year or Period

RSAX_BIW_GET_DATA_SIMPLE Generic Extraction via Function Module

RSAU_READ_MASTER_DATA Used in Data Transformations to read master data InfoObjects

RSDRI_INFOPROV_READ Used to read Infocube or ODS data through RFC


RSDRI_INFOPROV_READ_DEMO
RSDRI_INFOPROV_READ_RFC

DATE_COMPUTE_DAY Returns a number what day of the week the date falls on.
DATE_TO_DAY

DATE_GET_WEEK Will return a week that the day is in.

RP_CALC_DATE_IN_INTERVAL Add/Subtract Years/Months/Days from a Date.


ABAP Programming in BW

RP_LAST_DAY_OF_THE_MONTHS Determine Last Day of the Month.


SLS_MISC_GET_LAST_DAY_OF_MONTH

RSARCH_DATE_CONVERT Used for Date Conversions. We can use in Info Package routines.

RSPC_PROCESS_FINISH To trigger an event in process chain

DATE_CONVERT_TO_FACTORYDATE Returns factory calendar date for a date

CONVERSION_EXIT_PDATE_OUTPUT Conversion Exit for Domain GBDAT: YYYYMMDD -> DD/MM/YYYY

CONVERSION_EXIT_ALPHA_INPUT Conversion exit ALPHA, external->internal

CONVERSION_EXIT_ALPHA_OUTPUT Conversion exit ALPHA, internal->external

RSPC_PROCESS_FINISH Finish a process (of a process chain)

RSAOS_METADATA_UPLOAD Upload of meta data from R/3

RSDMD_DEL_MASTER_DATA Deletion of master data

RSPC_CHAIN_ACTIVATE_REMOTE To activate a process chain after transport

Class CL_RSTRAN_STAT Description

DELETE_VERSION_FROM_DB (Static For deleting a transformations rule version from database, helpful if the
Method) transformation metadata are corrupted.

Optimization considerations
 Use SELECT * with care. Do not use SELECT * when populating internal tables if
NOT all columns are required; only select the necessary columns.
 To reduce database access by repeated selections, it’s better to scan a table once
into the internal table and then read the internal table using statement
 READ TABLE … BINARY SEARCH. But be careful and consider resource issues when
selecting into an internal table – balance between optimization and memory
resources
 Avoid MOVE-CORRESPONDING statements. Instead use MOVE statement and
move fields individually.
 Structure of internal table should match the order the fields are returned from the
select statement when selecting into an internal table thereby avoiding usage of the
statement ‘into corresponding fields’.
 Avoid nested selects if possible.
 Be careful using ‘CHECK’ statements, consider to incorporate the selection criteria
into the select statement.
ABAP Programming in BW

Tips for code changes


 Remove obsolete commented out code as this will aid in program readability and
maintainability.
 Document any change in program code with details like reason of change, date of
change, person responsible and also mark the changed block with begin and end of
block tags.

Variants
 The Developer is responsible for ensuring test variants are not transported to the
production instance.

Das könnte Ihnen auch gefallen