Professional Documents
Culture Documents
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
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.
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
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.
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.
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.
Give the name of your Implementation. I have used the name ZVIR_CHAR_BADI.
Now from the interface tab, get into the Implementing Class
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.
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.
Now goto the Methods tab put the cursor on CHARACTERISTIC_CELL and select Redefine.
Now when you execute the report, you will get the following output as expected.
METHOD IF_EX_RSR_OLAP_BADI~COMPUTE .
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
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"'.
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.