Abap For Bi
Abap For Bi
ABAP Programming in BW
ABAP Programming in BW
Table of Contents
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
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
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)
*Global Section
TYPES:
BEGIN OF CUSTOMER_DATA,
END OF CUSTOMER_DATA.TYPES:
BEGIN OF ZCUSTSALES_DATA,
END OF CUSTOMER_DATA.
DATA:
ABAP Programming in BW
FROM /BI0/PCUSTOMER
FROM /BI0/PZCUSTSALE
DATA:
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.
CUSTOMER = LINE_DATA_PACKAGE-CUSTOMER
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.
ZCUSTSALE = LINE_DATA_PACKAGE-ZCUSTSALE
RESULT_FIELDS-DISTR_CHAN = LINE_DATA_PACKAGE-DISTR_CHAN.
ABAP Programming in BW
RESULT_FIELDS-SALES_GRP = LINE_DATA_PACKAGE-SALES_GRP.
ENDLOOP.
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.
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.
RSCDS_NULLELIM Delete fact table rows where all Key Figure values are zero. See Note
ABAP Programming in BW
619826.
SAP_CONVERT_NORMAL_TRANS Convert Basic Cube to Transactional Cube and the opposite way
around.
UNIT_CONVERSION_SIMPLE Used to convert any unit to another unit. (Ref. table : T006)
DATE_COMPUTE_DAY Returns a number what day of the week the date falls on.
DATE_TO_DAY
RSARCH_DATE_CONVERT Used for Date Conversions. We can use in Info Package routines.
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
Variants
The Developer is responsible for ensuring test variants are not transported to the
production instance.