populating virtual characteristic

Upload: tellvijji

Post on 14-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 Populating Virtual Characteristic

    1/17

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

    2009 SAP AG 1

    Populating Virtual Characteristicand Highlighting the Values

    Applies to:

    SAP BW 3.5 and BI 7.0

    For more information, visit the Business Intelligence homepage.

    Summary

    There are client requirements where we have to display Characteristic value for a particular Key Figurevalue. For e.g. if the value is more than 10 then display it as GOOD and if less than 10 then display it as BADand also to highlight them. This article shows how this particular requirement could be achieved.

    Author: Rakesh Pattani

    Company: Patni Computer Systems Ltd

    Created on: 6 December 2009

    Author Bio

    Rakesh Pattani is currently working in Patni Computers Systems Ltd. He is working on SAPBW 3.5 and SAP BI 7.0 and is mainly involved in Development and Enhancement work.

  • 7/30/2019 Populating Virtual Characteristic

    2/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 2

    Table of Contents

    Introduction ......................................................................................................................................................... 3Prerequisites ....................................................................................................................................................... 3Creating Virtual Characteristic ............................................................................................................................ 4BADI to Populate Virtual Characteristic .............................................................................................................. 5Table Interface to Highlight Values ................................................................................................................... 10

    ABAP Code Used ............................................................................................................................................. 13Conclusion ........................................................................................................................................................ 16Related Content ................................................................................................................................................ 16Disclaimer and Liability Notice .......................................................................................................................... 17

  • 7/30/2019 Populating Virtual Characteristic

    3/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 3

    Introduction

    This article shows how to populate a characteristic value based on a Key Figure value.

    The reason for creating this article is due to many queries on SDN Forum on how to display Key Figure valueas Text value (e.g. if the Key Fig value is more than 10 then it should be displayed as GOOD or else itshould be displayed as BAD). The answer to this question is No. It is not possible to directly display KeyFigure value as a Text value because Key Figures can only hold numerical values and cannot hold text. Sothere are two approaches for getting this done.

    Delete all the data from the data target. Add a characteristic to the data target. Write routines so thatthis field gets populated based on key figure value during the data loading. Reload the data again.This would surely be a good solution if the quantity of data is less but is not true in many cases. So iflarge amount of data is there in the data target then best approach will be to go with following option.

    Create a virtual characteristic. Populate this field in the report during run time through BADI. Makeuse of table Interface for highlighting the Characteristic values.

    Prerequisites

    You need a report displaying characteristic and key figure values. In my example I will be using a SalesQuery created in BI 2004S and executed from WAD 3.5. The report displays the Quantity and Price of aproduct purchased on a particular day by a customer. The output of a report can be viewed as shown in first

    figure. When we use the exception in a query, the Key figures can be highlighted as shown in the secondfigure.

    Now my requirement is to display BAD if a customer has purchased only 1 product, GOOD if a customerpurchases 2 products and Excellent if a customer purchases 3 products. Also to highlight the characteristicvalue similar to Key Figure.

  • 7/30/2019 Populating Virtual Characteristic

    4/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 4

    Creating Virtual Characteristic

    Create a characteristic Performance as shown below.

    Include the characteristic in the Cube as shown below and activate the cube.

    Also include the characteristic in the query as shown below and activate it.

  • 7/30/2019 Populating Virtual Characteristic

    5/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 5

    When you check the data in the Cube, you can see that the field for Performance is blank as this will bepopulated in the report directly during run time.

    BADI to Populate Virtual Characteristic

    Now goto transaction SE19. In Create Implementation, put RSR_OLAP_BADI as shown below.

  • 7/30/2019 Populating Virtual Characteristic

    6/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 6

    Give the name of your Implementation. I have used the name ZVIR_CHAR_BADI.

    Select your Cube name.

    Now from the interface tab, get into the Implementing Class

  • 7/30/2019 Populating Virtual Characteristic

    7/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 7

    Inside the Implementing Class, you need to give the Attributes name for all the characteristics and KeyFigures that you will be using in your report in the Attribute tab. The naming convention is important.P_CHA_ for characteristics and P_KYF_ for key figures.

    In the Methods tab, you need to define the Char/Key Fig which you would be using to read and write in theDefine Method.

    In the Compute Method, you need to put your calculations.

  • 7/30/2019 Populating Virtual Characteristic

    8/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 8

    Use the following codes in the Define Method.

  • 7/30/2019 Populating Virtual Characteristic

    9/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 9

    Use the following codes in the Compute Method.

    So now when you execute the WAD, you can see the characteristic values populated in the Performancecolumn according to the values in the Quantity column.

  • 7/30/2019 Populating Virtual Characteristic

    10/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 10

    Table Interface to Highlight Values

    Now to highlight these characteristic values, you need to use Table interface. Goto transaction SE24 andgive the name of a class. Here I am using ZCL_RSR_WWW_MODIFY_TABLE. Then click on create button.

    Select Class radio button.

    Now click on Create Inheritance.

  • 7/30/2019 Populating Virtual Characteristic

    11/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 11

    Now select the Superclass as CL_RSR_WWW_MODIFY_TABLE as shown below.

    Now goto the Methods tab put the cursor on CHARACTERISTIC_CELL and select Redefine.

  • 7/30/2019 Populating Virtual Characteristic

    12/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 12

    Add the following code in the CHARACTERISTIC_CELL Method.

    Now in the Web template, include the class name.

  • 7/30/2019 Populating Virtual Characteristic

    13/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 13

    Now when you execute the report, you will get the following output as expected.

    ABAP Code Used

    ABAP Code used in the Define Method of BADI (SE19)

    METHOD IF_EX_RSR_OLAP_BADI~DEFINE.DATA: L_S_CHANM TYPE RRKE_S_CHANM,

    L_S_CHANM_USED TYPE RSCHANM,

    L_KYFNM TYPE RSD_KYFNM.

    CASE I_S_RKB1D-INFOCUBE.

    WHEN'SALES_RP'.

    L_S_CHANM-CHANM = 'CUS_ID_RP'.

    L_S_CHANM-MODE = RRKE_C_MODE-READ.

    APPEND L_S_CHANM TO C_T_CHANM.

    L_S_CHANM-CHANM = 'PRD_ID_RP'.

    L_S_CHANM-MODE = RRKE_C_MODE-READ.

    APPEND L_S_CHANM TO C_T_CHANM.

    L_S_CHANM-CHANM = '0CALDAY'.

    L_S_CHANM-MODE = RRKE_C_MODE-READ.

    APPEND L_S_CHANM TO C_T_CHANM.

    APPEND'QNT_RP'TO C_T_KYFNM.

    APPEND'PRC_RP'TO C_T_KYFNM.

    L_S_CHANM-CHANM = 'PER_RP'.

    L_S_CHANM-MODE = RRKE_C_MODE-NO_SELECTION.

    APPEND L_S_CHANM TO C_T_CHANM.

    CLEAR L_S_CHANM.

    ENDCASE.

    ENDMETHOD.

  • 7/30/2019 Populating Virtual Characteristic

    14/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 14

    ABAP Code used in the Compute Method of BADI (SE19)

    METHOD IF_EX_RSR_OLAP_BADI~COMPUTE .

    FIELD-SYMBOLS TYPE /BIC/OICUS_ID_RP.

    FIELD-SYMBOLS TYPE /BIC/OIPRD_ID_RP.

    FIELD-SYMBOLS TYPE /BIC/OIPER_RP.FIELD-SYMBOLS TYPE /BI0/OICALDAY.

    FIELD-SYMBOLS TYPE /BIC/OIPRC_RP.

    FIELD-SYMBOLS TYPE /BIC/OIQNT_RP.

    IF P_CHA_CUS_ID_RP > 0.

    ASSIGNCOMPONENT P_CHA_CUS_ID_RP OFSTRUCTURE C_S_DATA TO .

    ENDIF.

    IF P_CHA_PRD_ID_RP > 0.

    ASSIGNCOMPONENT P_CHA_PRD_ID_RP OFSTRUCTURE C_S_DATA TO .

    ENDIF.

    IF P_CHA_0CALDAY > 0.

    ASSIGNCOMPONENT P_CHA_0CALDAY OFSTRUCTURE C_S_DATA TO .

    ENDIF.

    IF P_KYF_PRC_RP > 0.

    ASSIGNCOMPONENT P_KYF_PRC_RP OFSTRUCTURE C_S_DATA TO .

    ENDIF.

    IF P_KYF_QNT_RP > 0.

    ASSIGNCOMPONENT P_KYF_QNT_RP OFSTRUCTURE C_S_DATA TO .

    ENDIF.

    IFP_CHA_PER_RP >

    0.

    ASSIGNCOMPONENT P_CHA_PER_RP OFSTRUCTURE C_S_DATA TO .

    ENDIF.

    IF = 1.

    = 'BAD'.

    ENDIF.

    IF = 2.

    = 'GOOD'.

    ENDIF.

    IF = 3.

    = 'EXCELLENT'.ENDIF.

    ENDMETHOD. "IF_EX_RSR_OLAP_BADI~COMPUTE

  • 7/30/2019 Populating Virtual Characteristic

    15/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 15

    ABAP Code used in the CHARACTERISTIC_CELL method of Table interface (SE24)

    METHOD CHARACTERISTIC_CELL.

    *CALL METHOD SUPER->CHARACTERISTIC_CELL

    * EXPORTING

    * I_X =

    * I_Y =

    * I_IOBJNM =

    * I_AXIS =* I_CHAVL_EXT =

    * I_CHAVL =

    * I_NODE_IOBJNM =

    * I_TEXT =

    * I_HRY_ACTIVE =

    * I_DRILLSTATE =

    * I_DISPLAY_LEVEL =

    * I_USE_TEXT =

    * I_IS_SUM =

    * I_IS_REPETITION =

    ** I_FIRST_CELL = RS_C_FALSE

    ** I_LAST_CELL = RS_C_FALSE

    * I_CELLSPAN =

    * I_CELLSPAN_ORT =

    * CHANGING

    * C_CELL_ID =

    * C_CELL_CONTENT =

    * C_CELL_STYLE =

    * C_CELL_TD_EXTEND =

    * .

    IF I_CHAVL = 'GOOD'.

    C_CELL_TD_EXTEND = 'style="background:YELLOW"'.

    ENDIF.

    IFI_CHAVL =

    'BAD'.

    C_CELL_TD_EXTEND = 'style="background:RED"'.

    ENDIF.

    IF I_CHAVL = 'EXCELLENT'.

    C_CELL_TD_EXTEND = 'style="background:GREEN"'.

    ENDIF.

    ENDMETHOD.

  • 7/30/2019 Populating Virtual Characteristic

    16/17

    Populating Virtual Characteristic and Highlighting the Values

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

    2009 SAP AG 16

    Conclusion

    Following are the advantages of using the above functionality.

    1. No need of deleting the existing data and re-loading it after implementing the logic.

    2. No performance issue during the data loading as this field gets populated during runtime.

    3. Derive text value from a Key Figure value which is not possible directly using Query Designer. .

    Only disadvantage if this functionality is1. Performance issue during report execution as calculations are carried out during run time. But since thecomputing does not include complex logic, performance wont be that much impacted.

    Related Content

    Implementing BADI

    Table Interface

    For more information, visit the Business Intelligence homepage.

  • 7/30/2019 Populating Virtual Characteristic

    17/17

    Populating Virtual Characteristic and Highlighting the Values

    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.