Você está na página 1de 14

ABAP Programming in BW

ABAP Programming in BW

ACS/Ver 1.0

Page 1 of 8

ABAP Programming in BW

Table of Contents
Purpose..........................................................................................................3 Objective........................................................................................................3 Scope............................................................................................................3 Common Implementation scenarios of ABAP Programming in BW..........................4 Using Field Symbols in Routines......................................................................10 Differences between Transfer/Update Rules and Transformations .......................10 List of useful SAP Standard Programs/Function Modules/Classes..........................11 Optimization considerations............................................................................14 Tips for code changes.....................................................................................14 Variants........................................................................................................14

ACS/Ver 1.0

Page 2 of 8

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 BEx User Exit Description 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. 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. Transformation routines are part of transformation rules 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. Start routines in BW Transformations are used to manage whole subsets of source data before Transformation rules are triggered. End routines in BW Transformations are used to manage whole subsets of resulting data from Start routine and Transformation Rules. 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. DTP Routines are used to do some filtering and calculations on the selection screen fields depending on the business requirement.

R/3 User Exit

BW Transformation Routines

BW Start Routines

BW End Routines

BW Expert Routines

BW DTP Routines

ACS/Ver 1.0

Page 3 of 8

ABAP Programming in BW BW Infopackage Routines Infopackage level routines are used to in scenarios like if 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.

ACS/Ver 1.0

Page 4 of 8

ABAP Programming in BW

2. Start Routines

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

ACS/Ver 1.0

Page 5 of 8

ABAP Programming in BW

4. End Routine
End Routine is processed after transformation, actually for data cleansing.

5. Expert Routine

ACS/Ver 1.0

Page 6 of 8

ABAP Programming in BW 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: LINE_CUSTOMER_DATA TYPE CUSTOMER_DATA,

ACS/Ver 1.0

Page 7 of 8

ABAP Programming in BW 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. *make direct assignments for Result Fields:

ACS/Ver 1.0

Page 8 of 8

ABAP Programming in BW 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. RESULT_FIELDS-SALES_GRP = LINE_DATA_PACKAGE-SALES_GRP.

ACS/Ver 1.0

Page 9 of 8

ABAP Programming in BW 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 Internal Table DATA: BEGIN OF INT_EBELN OCCURS 0, OI_EBELN LIKE /BI0/POI_EBELN-OI_EBELN, /BIC/ZMEXPDGRP LIKE /BI0/POI_EBELN-/BIC/ZMEX PDGRP, /BIC/ZMPOVERNO LIKE /BI0/POI_EBELN-/BIC/ZMPO VERNO, /BIC/ZMPURSTAT LIKE /BI0/POI_EBELN-/BIC/ZMPU RSTAT, /BIC/ZMPORLSON LIKE /BI0/POI_EBELN-/BIC/ZMPO RLSON, /BIC/ZMVALD_PO LIKE /BI0/POI_EBELN-/BIC/ZMVA BI 7.0 It's 2 step process in BI 7.0. 1st step declare the structure and in 2nd step declare Internal table referring to the above structure TYPES: BEGIN OF INT_EBELN_STRU, OI_EBELN TYPE /BI0/POI_EBELN-OI_EBELN, /BIC/ZMEXPDGRP TYPE /BI0/POI_EBELN-/BIC/ZMEXPDGRP, /BIC/ZMPOVERNO TYPE /BI0/POI_EBELN-/BIC/ZMPOVERNO, /BIC/ZMPURSTAT TYPE /BI0/POI_EBELN-/BIC/ZMPURSTAT, /BIC/ZMPORLSON TYPE /BI0/POI_EBELN-/BIC/ZMPORLSON, /BIC/ZMVALD_PO TYPE /BI0/POI_EBELN-/BIC/ZMVALD_PO, END OF INT_EBELN_STRU.

ACS/Ver 1.0

Page 10 of 8

ABAP Programming in BW

LD_PO, END OF INT_EBELN. Reading data from READ TABLE INT_EBELN Internal Table INTO WA_PO WITH KEY OI_EBELN = DATA_PACKAGE-OI_EBELN BINARY SEARCH. IF SY-SUBRC = 0. DATA_PACKAGE-/BIC/ZMVAL D_PO = WA_PO-/BIC/ZMVALD_PO. DATA_PACKAGE-/BIC/ZMEXP DGRP = WA_PO-/BIC/ZMEXPDGRP. DATA_PACKAGE-/BIC/ZMPOR LSON = WA_PO-/BIC/ZMPORLSON. DATA_PACKAGE-/BIC/ZMPUR STAT = WA_PO-/BIC/ZMPURSTAT. Data Package

DATA: INT_EBELN TYPE TABLE OF INT_EBELN_STRU.


1st define a Work area and read from there. WA_PO LIKE LINE OF INT_EBELN Work Area READ TABLE INT_EBELN INTO WA_PO WITH KEY OI_EBELN = WA_DATA_PACKAGEOI_EBELN BINARY SEARCH. IF SY-SUBRC = 0. WA_DATA_PACKAGE-/BIC/ZMVALD_PO = WA_PO-/BIC/ZMVALD_PO. WA_DATA_PACKAGE-/BIC/ZMEXPDGRP = WA_PO-/BIC/ZMEXPDGRP. WA_DATA_PACKAGE-/BIC/ZMPORLSO N = WA_PO-/BIC/ZMPORLSON. WA_DATA_PACKAGE-/BIC/ZMPURSTA T = WA_PO-/BIC/ZMPURSTAT.

Data: DATA_PACKAGE type table of _ty_s_SC_1, WA_DATA_PACKAGE LIKE LINE OF DATA_PACKAGE.


LOOP AT DATA_PACKAGE. LOOP AT DATA_PACKAGE INTO WA_DATA_PACKAGE

Loop Statement

List of useful SAP Standard Programs/Function Modules/Classes


Description Delete fact table rows where all Key Figure values are zero. See Note 619826.

Program name RSCDS_NULLELIM

RSDG_CUBE_ACTIVATE RSDG_CUBE_COPY RSDG_CUBE_DELETE RSDG_DODS_REPAIR

Activation of InfoCubes Make InfoCube Copies Delete InfoCubes Activation of all ODS Objects with Navigation Attributes

ACS/Ver 1.0

Page 11 of 8

ABAP Programming in BW

RSDG_ODSO_ACTIVATE RSDG_IOBJ_ACTIVATE RSDG_IOBJ_DELETE RSDG_IOBJ_REORG RSDG_IOBJ_REORG_TEXTS RSDG_MPRO_ACTIVATE RSDG_MPRO_COPY RSDG_MPRO_DELETE RS_COMSTRU_ACTIVATE_ALL RS_TRANSTRU_ACTIVATE_ALL RSAU_UPDR_REACTIVATE_ALL RRHI_HIERARCHY_ACTIVATE SAP_AGGREGATES_ACTIVATE_FI LL SAP_AGGREGATES_DEACTIVATE RS_PERS_ACTIVATE RSSM_SET_REPAIR_FULL_FLAG SAP_INFOCUBE_DESIGNS SAP_ANALYZE_ALL_INFOCUBES SAP_CREATE_E_FACTTABLES

Activation of all ODS Objects Activation of all InfoObjects Deletion of InfoObjects Repair InfoObjects Reorganization of Texts for InfoObjects Activating Multiproviders Make Multiprovider Copies Deleting Multiproviders Activate all inactive Communication Structures Activate Transfer Structure Activate Update Rules Activate Hierarchies Activating and Filling the Aggregates of an InfoCube

Deactivating the Aggregates of an InfoCube Activating Personalization in Bex(Inactive are highlighted) Convert Full Requests to Repair Full Requests Print a List of Cubes in The System and Their Layouts Create DB Statistics for all InfoCubes 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 SAP_RSADMIN_MAINTAIN CUBE_SAMPLE_CREATE Remove Temporary Database Objects Add, change, delete RSADMIN table entries 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 RRMX_WORKBOOK_DELETE RRMX_WORKBOOK_LIST_GET

Description (Function Group RRMX) Delete BW Workbooks permanently from Roles & Favorites Get list of all Workbooks

ACS/Ver 1.0

Page 12 of 8

ABAP Programming in BW

RRMX_WORKBOOK_QUERIES_GET RRMX_QUERY_WHERE_USED_GET RRMX_JUMP_TARGET_GET RRMX_JUMP_TARGET_DELETE MONI_TIME_CONVERT CONVERT_TO_LOCAL_CURRENCY CONVERT_TO_FOREIGN_CURRENCY TERM_TRANSLATE_TO_UPPER_CASE UNIT_CONVERSION_SIMPLE TZ_GLOBAL_TO_LOCAL FISCPER_FROM_CALMONTH_CALC RSAX_BIW_GET_DATA_SIMPLE RSAU_READ_MASTER_DATA

Get list of queries in a workbook Lists where a query has been used Get list of all Jump Targets Delete Jump Targets Used for Time Conversions. Convert Foreign Currency to Local Currency. Convert Local Currency to Foreign Currency. Used to convert all texts to UPPERCASE Used to convert any unit to another unit. (Ref. table : T006) Used to convert timestamp to local time Convert 0CALMONTH or 0CALDAY to Financial Year or Period Generic Extraction via Function Module Used in Data Transformations to read master data InfoObjects

RSDRI_INFOPROV_READ RSDRI_INFOPROV_READ_DEMO RSDRI_INFOPROV_READ_RFC DATE_COMPUTE_DAY DATE_TO_DAY DATE_GET_WEEK RP_CALC_DATE_IN_INTERVAL RP_LAST_DAY_OF_THE_MONTHS SLS_MISC_GET_LAST_DAY_OF_MONT H RSARCH_DATE_CONVERT

Used to read Infocube or ODS data through RFC

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

Will return a week that the day is in. Add/Subtract Years/Months/Days from a Date. Determine Last Day of the Month.

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_OUTPUT RSPC_PROCESS_FINISH Conversion exit ALPHA, external->internal Conversion exit ALPHA, internal->external Finish a process (of a process chain)

ACS/Ver 1.0

Page 13 of 8

ABAP Programming in BW

RSAOS_METADATA_UPLOAD RSDMD_DEL_MASTER_DATA RSPC_CHAIN_ACTIVATE_REMOTE

Upload of meta data from R/3 Deletion of master data To activate a process chain after transport

Class CL_RSTRAN_STAT DELETE_VERSION_FROM_DB (Static Method)

Description For deleting a transformations rule version from database, helpful if the 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, its 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.

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.

ACS/Ver 1.0

Page 14 of 8

Você também pode gostar