You are on page 1of 17

Populating Virtual Characteristic and 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 Figure value. For e.g. if the value is more than 10 then display it as GOOD and if less than 10 then display it as BAD and 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 SAP BW 3.5 and SAP BI 7.0 and is mainly involved in Development and Enhancement work.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 1

Populating Virtual Characteristic and Highlighting the Values

Table of Contents
Introduction ......................................................................................................................................................... 3 Prerequisites ....................................................................................................................................................... 3 Creating Virtual Characteristic ............................................................................................................................ 4 BADI to Populate Virtual Characteristic .............................................................................................................. 5 Table Interface to Highlight Values ................................................................................................................... 10 ABAP Code Used ............................................................................................................................................. 13 Conclusion ........................................................................................................................................................ 16 Related Content ................................................................................................................................................ 16 Disclaimer and Liability Notice .......................................................................................................................... 17

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 2

Populating Virtual Characteristic and Highlighting the Values

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 value as Text value (e.g. if the Key Fig value is more than 10 then it should be displayed as GOOD or else it should be displayed as BAD). The answer to this question is No. It is not possible to directly display Key Figure value as a Text value because Key Figures can only hold numerical values and cannot hold text. So there 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 that this 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 if large 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. Make use 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 Sales Query created in BI 2004S and executed from WAD 3.5. The report displays the Quantity and Price of a product 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 second figure.

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

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 3

Populating Virtual Characteristic and Highlighting the Values

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.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 4

Populating Virtual Characteristic and Highlighting the Values

When you check the data in the Cube, you can see that the field for Performance is blank as this will be populated 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.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 5

Populating Virtual Characteristic and Highlighting the Values

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

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 6

Populating Virtual Characteristic and Highlighting the Values

Inside the Implementing Class, you need to give the Attributes name for all the characteristics and Key Figures that you will be using in your report in the Attribute tab. The naming convention is important. P_CHA_<characteristic name> for characteristics and P_KYF_<key figure name> 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 the Define Method. In the Compute Method, you need to put your calculations.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 7

Populating Virtual Characteristic and Highlighting the Values

Use the following codes in the Define Method.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 8

Populating Virtual Characteristic and Highlighting the Values

Use the following codes in the Compute Method.

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

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 9

Populating Virtual Characteristic and Highlighting the Values

Table Interface to Highlight Values


Now to highlight these characteristic values, you need to use Table interface. Goto transaction SE24 and give 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.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 10

Populating Virtual Characteristic and Highlighting the Values

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.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 11

Populating Virtual Characteristic and Highlighting the Values

Add the following code in the CHARACTERISTIC_CELL Method.

Now in the Web template, include the class name.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 12

Populating Virtual Characteristic and Highlighting the Values

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.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 13

Populating Virtual Characteristic and Highlighting the Values

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

METHOD IF_EX_RSR_OLAP_BADI~COMPUTE .

FIELD-SYMBOLS FIELD-SYMBOLS FIELD-SYMBOLS FIELD-SYMBOLS FIELD-SYMBOLS FIELD-SYMBOLS

<FS_CUS_RP> <FS_PRD_RP> <FS_PER_RP> <FS_CAL_RP> <FS_PRC_RP> <FS_QNT_RP>

TYPE TYPE TYPE TYPE TYPE TYPE

/BIC/OICUS_ID_RP. /BIC/OIPRD_ID_RP. /BIC/OIPER_RP. /BI0/OICALDAY. /BIC/OIPRC_RP. /BIC/OIQNT_RP.

IF P_CHA_CUS_ID_RP > 0. ASSIGN COMPONENT P_CHA_CUS_ID_RP OF STRUCTURE C_S_DATA TO <FS_CUS_RP>. ENDIF. IF P_CHA_PRD_ID_RP > 0. ASSIGN COMPONENT P_CHA_PRD_ID_RP OF STRUCTURE C_S_DATA TO <FS_PRD_RP>. ENDIF. IF P_CHA_0CALDAY > 0. ASSIGN COMPONENT P_CHA_0CALDAY OF STRUCTURE C_S_DATA TO <FS_CAL_RP>. ENDIF. IF P_KYF_PRC_RP > 0. ASSIGN COMPONENT P_KYF_PRC_RP OF STRUCTURE C_S_DATA TO <FS_PRC_RP>. ENDIF. IF P_KYF_QNT_RP > 0. ASSIGN COMPONENT P_KYF_QNT_RP OF STRUCTURE C_S_DATA TO <FS_QNT_RP>. ENDIF. IF P_CHA_PER_RP > 0. ASSIGN COMPONENT P_CHA_PER_RP OF STRUCTURE C_S_DATA TO <FS_PER_RP>. ENDIF. IF <FS_QNT_RP> = 1. <FS_PER_RP> = 'BAD'. ENDIF. IF <FS_QNT_RP> = 2. <FS_PER_RP> = 'GOOD'. ENDIF. IF <FS_QNT_RP> = 3. <FS_PER_RP> = 'EXCELLENT'. ENDIF.

ENDMETHOD.

"IF_EX_RSR_OLAP_BADI~COMPUTE

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 14

Populating Virtual Characteristic and Highlighting the Values

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. IF I_CHAVL = 'BAD'.
C_CELL_TD_EXTEND = 'style="background:RED"'.

ENDIF. IF I_CHAVL = 'EXCELLENT'. C_CELL_TD_EXTEND = 'style="background:GREEN"'. ENDIF. ENDMETHOD.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 15

Populating Virtual Characteristic and Highlighting the Values

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 is 1. Performance issue during report execution as calculations are carried out during run time. But since the computing 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.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 16

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 not supported 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 or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 17

You might also like