routines in transformations in sap bi 7.0

Upload: pandian-cr

Post on 03-Apr-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    1/21

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 1

    Routines in Transformations in

    SAP BI 7.0

    Applies to:

    SAP BI 7.0. For more information, visit theEDW homepage.

    Summary

    This paper gives an overview about the different routines available in SAP BI 7.0 Transformation . Inparticular the paper highlights when and where an appropriate routine has to be used and shows how toimplement .The paper explains the concepts based on a simple scenario for all the routines. The paper alsogives the sample code and results at the end of each routine.

    Author: Ravindranath Reddy L

    Company: Accenture India Pvt Ltd.Created on: 20 October 2010

    Author Bio

    The author works for Accenture India Pvt Ltd. His expertise includes SAP BI

    https://www.sdn.sap.com/irj/sdn/nw-bihttps://www.sdn.sap.com/irj/sdn/nw-bihttps://www.sdn.sap.com/irj/sdn/nw-bihttps://www.sdn.sap.com/irj/sdn/nw-bi
  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    2/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 2

    Table of Content

    Introduction ......................................................................................................................................................... 3Scenario .......................................................................................................................................................... 3

    Characteristic or Field Routine ........................................................................................................................... 4Definition ......................................................................................................................................................... 4How to Implement ........................................................................................................................................... 4Sample Code .................................................................................................................................................. 6

    Start Routine ....................................................................................................................................................... 7Definition ......................................................................................................................................................... 7Approach to Scenario ...................................................................................................................................... 7How to Implement ........................................................................................................................................... 7Sample Code ................................................................................................................................................ 10

    End Routine ...................................................................................................................................................... 12Definition ....................................................................................................................................................... 12Approach to Scenario .................................................................................................................................... 12How to Implement ......................................................................................................................................... 12Sample Code ................................................................................................................................................ 14

    Expert Routine .................................................................................................................................................. 15Definition ....................................................................................................................................................... 15Approach to Scenario .................................................................................................................................... 15How to Implement ......................................................................................................................................... 15Sample Code ................................................................................................................................................ 18

    Related Content ................................................................................................................................................ 20Disclaimer and Liability Notice .......................................................................................................................... 21

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    3/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 3

    Introduction

    Routines are used to define complex transformation rules. In most of the cases data wont be coming directlyin desired form before sending to the target. In some cases output needs to be derived on some incomingdata. In such cases we need to go for writing of routines at the transformation level.

    There are four types of Routines availableCharacteristic or Field Routine

    Start Routine

    End RoutineExpert Routine

    The routine which we need to go for depends on when it needs to be executed. Suppose if some logic needsto be implemented before transformation then the start routine needs to be implemented.

    This Paper presents in detail about each of the above Routine.

    Scenario

    The Scenario is for each incoming record comes up with unique key job number with its Start and End Date.At the output there is one key figure Total no of days which is the difference of End and Start Dates andbased on the key figure value Total no of days.

    This same scenario is taken to explain each routine.

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    4/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 4

    Characteristic or Field Routine

    Definition

    It operates on a single record for a single characteristic or key figure. The value gets modified in the routinebased on one or more source fields before it is transferred to the target

    Approach to Scenario

    The Key figure total no of days needs to be populated using start and end dates.

    So to calculate total no of days we are going to write a field routine. But for that start and end date valuesneed to be mapped to the key figure.

    How to Implement

    In the above screen shot all the source fields are mapped one to one to the target.

    We have mapped start and end date to the key figure and now double click on the equal to symbol

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    5/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 5

    Once clicked u can see the source fields start and end dates because we have mapped them. Now chooseRule Type as Routine. Once clicked routine it will take to the editor

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    6/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 6

    We need to write the logic there. Once written it will take to the result which is nothing but total no of days.

    The logic is written it is end date minus start date. Syntax is checked it showed no errors. Save the Routineand activate the transformation.

    Sample Code

    RESULT = SOURCE_FIELDS-/BIC/RT_ENDT - SOURCE_FIELDS-/BIC/RT_SRTDT.

    Output

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    7/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 7

    Start Routine

    Definition

    The start routine is run at the start of the transformation. The start routine has a table in the format of thesource structure as input and output parameters. It is used to perform preliminary calculations and storethese in a global data structure or in a table. This structure or table can be accessed from other routines. Youcan modify or delete data in the source_package .

    Approach to ScenarioFor field routine it will act on each record but in start routine it will have all the data in source_package . InStart routine we will have the structure of the source fields. So in this scenario the key figure is not availablein source.

    So in Start routine we calculate the total no of days for each record with its unique key job number and storethem in an internal table.

    The internal table is global and it can be accessed every where. So we have to write a field routine for keyfigure total no of days mapped with job number. Using this job number we will read the value of key figuretotal no of days from internal table and update the result i.e. total no of days key figure.

    How to Implement

    Click on start routine and it will take to the editor. In the start routine there will be table source_packagewhich contains all the data and has the structure of source.

    Here we will read the job number from source_package and update it into internal table and total no of dayskey figure value into internal table using start and end dates.

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    8/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 8

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    9/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 9

    Once this is done the value of key figure is in internal table and from there we need to get into target . So forthat a field routine needs to be written to read from value from internal table. The key to internal table to getunique value is job number so job number is mapped to key figure.

    Here Job number is mapped to the key figure. And a field routine is written to read the total no of days usingthis job number.

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    10/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 10

    Sample Code

    Types: begin of itabtype,

    job_numb type /bic/oirt_jobno,

    stg_numb type /bic/oirt_stgno,

    profile type /bic/oirt_prfl,

    tot_days type /bic/oirt_wkydy1,

    end of itabtype.

    data : itab type standard table of itabtype

    with key job_numb,

    wa_itab like line of itab.

    Keep this part in global section because we have to read the internal table once it

    is populated and hence it should be visible every where.

    data : wa_source_package type _ty_s_SC_1.

    loop at source_package into wa_ source_package.

    move wa_ source_package -/BIC/RT_JOBNO to wa_itab-job_numb.

    move wa_ source_package -/BIC/RT_stgNO to wa_itab-stg_numb.

    wa_itab-tot_days = wa_ source_package -/BIC/RT_ENDT - wa_ source_package -

    /BIC/RT_SRTDT.

    if wa_itab-tot_days le 10 .

    wa_itab-profile = '(0-10)'.elseif wa_itab-tot_days gt 10 and wa_itab-tot_days le 20.

    wa_itab-profile = '(10-20)'.

    else.

    wa_itab-profile = '(20-NN)'.

    endif.

    append wa_itab to itab.

    endloop.

    By this code we has populated the internal table and we has to get the values for the age profile and total noof days for this by using the key for the table i.e. job number

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    11/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 11

    This is the code in the field routine which gets the value from the internal table and populates when the jobnumber in the internal table is same as the coming job number

    read table itab into wa_itab

    with key job_numb = SOURCE_FIELDS-/BIC/RT_JOBNO.

    if sy-subrc = 0.

    Result = wa_itab-profile.

    endif.

    Output

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    12/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 12

    End Routine

    Definition

    An end routine is a routine with a table in the target structure format as input and output parameters. You canuse an end routine to postprocess data after transformation on a package-by-package basis. Data is storedin result_package.

    Approach to ScenarioEnd Routine is processed after start routine, mappings, field routines and finally before the values istransferred to the output. End routine has the structure of the target and result_package contains the entiredata which finally is the output.

    For our scenario we have one to one mapping for all the fields except total no of days so in result_package itwill not have the value for each record.

    So in End Routine we will calculate the key figure value for each record and modify the result_package andthere by the output will also contain the key figure.

    How to Implement

    In transformation all are mapped one to one. Click End Routine at the top it will take to the editor. There we

    have to modify the result_package with the key figure value updated.

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    13/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 13

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    14/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 14

    In the end routine we will loop over the result_package and using the start and end dates of each record thekey figure value is calculated and updated again into the result_package. Check the routine and save theroutine and activate the transformation.

    Sample Code

    Data: wa_RESULT_PACKAGE type _ty_s_TG_1.

    Loop at RESULT_PACKAGE into wa_RESULT_PACKAGE.

    wa_RESULT_PACKAGE-/BIC/RT_WKYDY1 = wa_RESULT_PACKAGE-/BIC/RT_ENDT -wa_RESULT_PACKAGE-/BIC/RT_SRTDT.

    if wa_RESULT_PACKAGE-/BIC/RT_WKYDY1 le 10 .

    wa_RESULT_PACKAGE-/BIC/RT_PRFL = '(0-10)'.

    Else if wa_RESULT_PACKAGE-/BIC/RT_WKYDY1 gt 10 and

    wa_RESULT_PACKAGE-/BIC/RT_WKYDY1 le 20.

    wa_RESULT_PACKAGE-/BIC/RT_PRFL = '(10-20)'.

    else.

    wa_RESULT_PACKAGE-/BIC/RT_PRFL = '(20-NN)'.

    endif.

    modify RESULT_PACKAGE from wa_RESULT_PACKAGE.

    End loop.

    Output

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    15/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 15

    Expert Routine

    Definition

    An Expert routine is a routine with contains both the source and target structure. we can use Expert routine ifthere are not sufficient functions to perform transformation.

    Approach to Scenario

    For Expert Routine every things needs to be written using coding. In simple an expert routine performs all theactions of Start Routine, Mappings, Field and End Routines.

    In Expert Routine we will read from source_package which contains all the data and update intoresult_package which should be the output and when doing we will calculate the key figure total no of days.

    How to Implement

    Click Transformation and go to edit and click the expert routine.

    If clicked it asks to confirm the transformation mappings will be deleted and will be taken to coding parteditor.

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    16/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 16

    Click yes to continue

    Here we can see that both the source fields and result fields are available because the expert routine has totake care of every thing.

    It should cover the transformation mappings, start and end routine codes.

    The code given below is implemented in the editor of expert routine and shown in below screenshot.

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    17/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 17

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    18/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 18

    After check the consistency and save and activate as we do for start and end routine.

    Then the transformation will have only one mapping from source to target saying expert routine .See thatstart and end routine are also disabled. And activate the transformation.

    Sample Code

    Data : wa_SOURCE_PACKAGE type _ty_s_SC_1. * creating work areas*

    data : wa_RESULT_PACKAGE type _ty_s_TG_1.loop at SOURCE_PACKAGE into wa_SOURCE_PACKAGE .

    *transformation mappings mappings in code *

    move wa_SOURCE_PACKAGE -/BIC/RT_JOBNO to wa_RESULT_PACKAGE-/BIC/RT_JOBNO.

    move wa_SOURCE_PACKAGE -/BIC/RT_STGNO to wa_RESULT_PACKAGE-/BIC/RT_STGNO.

    move wa_SOURCE_PACKAGE -/BIC/RT_SRTDT to wa_RESULT_PACKAGE-C/RT_SRTDT.

    move wa_SOURCE_PACKAGE -/BIC/RT_ENDT to wa_RESULT_PACKAGE-/BIC/RT_ENDT.

    wa_RESULT_PACKAGE-/BIC/RT_WKYDY1 = wa_SOURCE_PACKAGE -/BIC/RT_ENDT -

    wa_SOURCE_PACKAGE -/BIC/RT_SRTDT.

    if wa_RESULT_PACKAGE-/BIC/RT_WKYDY1 le 10 .

    wa_RESULT_PACKAGE-/BIC/RT_PRFL = '(0-10)'.

    elseif wa_RESULT_PACKAGE-/BIC/RT_WKYDY1 gt 10 and

    wa_RESULT_PACKAGE-/BIC/RT_WKYDY1 le 20.

    wa_RESULT_PACKAGE-/BIC/RT_PRFL = '(10-20)'.else.

    wa_RESULT_PACKAGE-/BIC/RT_PRFL = '(20-NN)'.

    endif.

    append wa_RESULT_PACKAGE to RESULT_PACKAGE.

    endloop.

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    19/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 19

    1) In Expert Routine we will fetch the values from source_package into work area of source_package .

    2) Move this work area to the output work area i.e. to result_package (This step is nothing but transformationmapping in code)

    3) Append the work area to the result_package (which actually is the output).

    4) Continue Steps 1-3 until all the records are transferred from source to target. ( taken care by loopstatement)

    Output

  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    20/21

    Routines in Transformations in SAP BI 7.0

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 20

    Related Content

    For more information, visit theEDW homepage.

    https://www.sdn.sap.com/irj/sdn/nw-bihttps://www.sdn.sap.com/irj/sdn/nw-bihttps://www.sdn.sap.com/irj/sdn/nw-bihttps://www.sdn.sap.com/irj/sdn/nw-bi
  • 7/28/2019 Routines in Transformations in SAP BI 7.0

    21/21

    Routines in Transformations in SAP BI 7.0

    Disclaimer and Liability Notice

    This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is notsupported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.

    SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document,and anyone using these methods does so at his/her own risk.

    SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article orcode sample, including any liability resulting from incompatibility between the content within this document and the materials andservices offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of thisdocument.