ABAP ON BW

Embed Size (px)

Citation preview

  • 7/30/2019 ABAP ON BW

    1/14

    ABAP Programming in BW

    ABAP Programming in BW

    ACS/Ver 1.0 Page 1 of 8

  • 7/30/2019 ABAP ON BW

    2/14

    ABAP Programming in BW

    Table of Contents

    Purpose..........................................................................................................3Objective........................................................................................................3

    Scope............................................................................................................3Common Implementation scenarios of ABAP Programming in BW..........................4

    Using Field Symbols in Routines......................................................................10Differences between Transfer/Update Rules and Transformations .......................10

    List of useful SAP Standard Programs/Function Modules/Classes..........................11Optimization considerations............................................................................14

    Tips for code changes.....................................................................................14

    Variants........................................................................................................14

    ACS/Ver 1.0 Page 2 of 8

  • 7/30/2019 ABAP ON BW

    3/14

    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 anddevelopment 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 andcalculations 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 toextract structures. We can also create additional business

    logic against data prior to its transfer to BW.

    BW TransformationRoutines

    Transformation routines are part of transformation ruleswhich are invoked as data is transferred from R/3 to BWData 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 aretriggered.

    BW End Routines End routines in BW Transformations are used to manage wholesubsets 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. Expertroutines 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.

    ACS/Ver 1.0 Page 3 of 8

  • 7/30/2019 ABAP ON BW

    4/14

    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

  • 7/30/2019 ABAP ON BW

    5/14

    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

  • 7/30/2019 ABAP ON BW

    6/14

    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

  • 7/30/2019 ABAP ON BW

    7/14

    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 routineshould 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 stepsshould 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

  • 7/30/2019 ABAP ON BW

    8/14

    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

  • 7/30/2019 ABAP ON BW

    9/14

    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

  • 7/30/2019 ABAP ON BW

    10/14

    ABAP Programming in BW

    APPEND RESULT_FIELDS TO RESULT_PACKAGE.

    ENDLOOP.

    Using Field Symbols in RoutinesField symbols are placeholders or symbolic names for other fields. They do notphysically 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 assignedto 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 differencein 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 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/ZMPURSTAT,

    /BIC/ZMPORLSON LIKE/BI0/POI_EBELN-/BIC/ZMPO

    RLSON,

    /BIC/ZMVALD_PO LIKE

    /BI0/POI_EBELN-/BIC/ZMVA

    It's 2 step process in BI 7.0. 1st step

    declare the structure and in 2nd stepdeclare Internal table referring to the

    above structureTYPES: 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

  • 7/30/2019 ABAP ON BW

    11/14

    ABAP Programming in BW

    LD_PO,

    END OF INT_EBELN.

    DATA: INT_EBELN TYPE TABLE OF

    INT_EBELN_STRU.

    Reading data from

    Internal Table

    READ TABLE INT_EBELN

    INTO WA_PO WITH KEYOI_EBELN =

    DATA_PACKAGE-OI_EBELNBINARY SEARCH.

    IF SY-SUBRC = 0.

    DATA_PACKAGE-/BIC/ZMVAL

    D_PO =

    WA_PO-/BIC/ZMVALD_PO.

    DATA_PACKAGE-/BIC/ZMEXPDGRP =

    WA_PO-/BIC/ZMEXPDGRP.

    DATA_PACKAGE-/BIC/ZMPORLSON =WA_PO-/BIC/ZMPORLSON.

    DATA_PACKAGE-/BIC/ZMPUR

    STAT =

    WA_PO-/BIC/ZMPURSTAT.

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

    OI_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/ZMPORLSON = WA_PO-/BIC/ZMPORLSON.

    WA_DATA_PACKAGE-/BIC/ZMPURSTA

    T = 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 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

    ACS/Ver 1.0 Page 11 of 8

  • 7/30/2019 ABAP ON BW

    12/14

    ABAP Programming in BW

    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_FI

    LL

    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

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

    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

    ACS/Ver 1.0 Page 12 of 8

  • 7/30/2019 ABAP ON BW

    13/14

    ABAP Programming in BW

    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

    RSDRI_INFOPROV_READ_DEMO

    RSDRI_INFOPROV_READ_RFC

    Used to read Infocube or ODS data through RFC

    DATE_COMPUTE_DAY

    DATE_TO_DAY

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

    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.

    RP_LAST_DAY_OF_THE_MONTHS

    SLS_MISC_GET_LAST_DAY_OF_MONT

    H

    Determine Last Day of the 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)

    ACS/Ver 1.0 Page 13 of 8

  • 7/30/2019 ABAP ON BW

    14/14

    ABAP Programming in BW

    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 Method)

    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 ifNOT all columns are required; only select the necessary columns.

    To reduce database access by repeated selections, its better to scan a table onceinto 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 criteriainto 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 ofchange, 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