SAP NetWeaver
SAP
NetWeaver
How-To
Guide
How-To Guide
How To...Highlight Changed Cells in
SAP BusinessObjects Analysis for
Office
Applicable Releases:
SAP NetWeaver BW 7.00 and higher
SAP BusinessObjects Analysis for Microsoft Office 1.1 and higher
Topic Area:
Business Information Management
Version 1.4
September 2014
© Copyright 2014 SAP AG. All rights reserved.
No part of this publication may be reproduced or
transmitted in any form or for any purpose without the
express permission of SAP AG. The information contained
herein may be changed without prior notice.
Some software products marketed by SAP AG and its
distributors contain proprietary software components of
other software vendors.
Microsoft, Windows, Outlook, and PowerPoint are
registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, OS/2, Parallel
Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390,
OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP,
Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix,
i5/OS, POWER, POWER5, OpenPower and PowerPC are
trademarks or registered trademarks of IBM Corporation.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader
are either trademarks or registered trademarks of Adobe
Systems Incorporated in the United States and/or other
countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered
trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame,
WinFrame, VideoFrame, and MultiWin are trademarks or
registered trademarks of Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or
registered trademarks of W3C®, World Wide Web
Consortium, Massachusetts Institute of Technology.
Java is a registered trademark of Sun Microsystems, Inc.
JavaScript is a registered trademark of Sun Microsystems,
Inc., used under license for technology invented and
implemented by Netscape.
MaxDB is a trademark of MySQL AB, Sweden.
SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP
NetWeaver, and other SAP products and services
mentioned herein as well as their respective logos are
trademarks or registered trademarks of SAP AG in
Germany and in several other countries all over the world.
All other product and service names mentioned are the
trademarks of their respective companies. Data contained
in this document serves informational purposes only.
National product specifications may vary.
These materials are subject to change without notice.
These materials are provided by SAP AG and its affiliated
companies ("SAP Group") for informational purposes only,
without representation or warranty of any kind, and SAP
Group shall not be liable for errors or omissions with
respect to the materials. The only warranties for SAP
Group products and services are those that are set forth in
the express warranty statements accompanying such
products and services, if any. Nothing herein should be
construed as constituting an additional warranty.
These materials are provided “as is” without a warranty of
any kind, either express or implied, including but not
limited to, the implied warranties of merchantability,
fitness for a particular purpose, or non-infringement.
SAP shall not be liable for damages of any kind including
without limitation direct, special, indirect, or consequential
damages that may result from the use of these materials.
SAP does not warrant the accuracy or completeness of the
information, text, graphics, links or other items contained
within these materials. SAP has no control over the
information that you may access through the use of hot
links contained in these materials and does not endorse
your use of third party web pages nor provide any warranty
whatsoever relating to third party web pages.
SAP NetWeaver “How-to” Guides are intended to simplify
the product implementation. While specific product
features and procedures typically are explained in a
practical business context, it is not implied that those
features and procedures are the only approach in solving a
specific business problem using SAP NetWeaver. Should
you wish to receive additional information, clarification or
support, please refer to SAP Consulting.
Any software coding and/or code lines / strings (“Code”)
included in this documentation are only examples and are
not intended to be used in a productive system
environment. The Code is only intended better explain and
visualize the syntax and phrasing rules of certain coding.
SAP does not warrant the correctness and completeness of
the Code given herein, and SAP shall not be liable for
errors or damages caused by the usage of the Code, except
if such damages were caused by SAP intentionally or
grossly negligent.
Disclaimer
Some components of this product are based on Java™. Any
code change in these components may cause unpredictable
and severe malfunctions and is therefore expressively
prohibited, as is any decompilation of these components.
Any Java™ Source Code delivered with this product is only
to be used by SAP’s Support Services and may not be
modified or altered in any way.
Document History
Document Version
Description
1.00
First official release of this guide
1.10
Correction of error in sub createMapInitial
1.20
Correction of error when using queries on several worksheets
1.30
Correction of error when creating the cell key; changes in sub
updateMapAndCompare and createMapInitial
1.40
Correction of error when using crosstab with new lines in FillSelTabs,
createMapInitial, and updateMapAndCompare
Typographic Conventions
Icons
Type Style
Description
Icon
Example Text
Words or characters quoted
from the screen. These
include field names, screen
titles, pushbuttons labels,
menu names, menu paths,
and menu options.
Cross-references to other
documentation
Example text
Emphasized words or
phrases in body text, graphic
titles, and table titles
Example text
File and directory names and
their paths, messages,
names of variables and
parameters, source text, and
names of installation,
upgrade and database tools.
Example text
User entry texts. These are
words or characters that you
enter in the system exactly as
they appear in the
documentation.
<Example
text>
Variable user entry. Angle
brackets indicate that you
replace these words and
characters with appropriate
entries to make entries in the
system.
EXAMPLE TEXT
Keys on the keyboard, for
example, F2 or ENTER.
Description
Caution
Note or Important
Example
Recommendation or Tip
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
Table of Contents
1.
Scenario ................................................................................................................................ 2
2.
General Description of the Solution .................................................................................. 2
3.
Step by Step Solution.......................................................................................................... 2
4.
3.1
Create the Workbook with the Data Source ................................................................. 2
3.2
Create the Macros ........................................................................................................ 5
3.3
Enable the Highlighting Automatically .......................................................................... 7
3.4
Using Buttons to Enable the Highlighting ..................................................................... 8
3.5
Test your Workbook ..................................................................................................... 9
Appendix – Macro Coding ................................................................................................ 12
4.1
Coding in Module AO_TRACK_CHANGES ............................................................... 12
4.2
Coding in Second Module .......................................................................................... 17
4.3
Coding in ThisWorkbook ............................................................................................ 18
September 2014
1
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
1.
Scenario
In BW Integrated Planning as well as in the Planning Applications Kit key figure values can be either
changed manually or by executing planning functions. In addition cells within a query can
automatically change once other related cells in the query are changed (totals or subtotals, hierarchy
nodes, calculated key figures) or even when related cells in others queries within the workbook are
changed (e.g. two queries showing different aggregations of the same set of data). Thus for the end
user it is sometimes quite hard to notice which cells have changed after some round trip and which
once where untouched.
In this How to Paper we present a solution to this problem. We use a macro that highlights the
changes within a query after each round trip. We use two different colors – one for changed records
and one for records which are new within this query. Our solution also can highlight the changes in
several queries in a workbook at the same time.
Important
As Analysis for Office can be used for planning with BW Integrated Planning as well as
with the new in memory based Planning Applications Kit this how to paper can be used
for both planning solutions.
2.
General Description of the Solution
In this How to Paper we describe a set of macros that can be used for highlighting changed or new
cells within a query.
In the solution we describe here we automatically register the macro that highlights the changes for
the callback ‘AfterRedisplay’. We also provide services that the user can switch the highlighting on and
off by pressing some buttons.
3.
Step by Step Solution
We now create a new workbook containing our offline macro.
3.1
Create the Workbook with the Data Source
Open Analysis for Office and create a blank workbook. Please check that you have enabled the
planning features shipped with version 1.1. In order to do so go to the Analysis ribbon and choose
‘Settings’. Now check the setting ‘Show Planning Group in Ribbon Toolbar’ on the popup.
September 2014
2
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
Now insert a plan query. Choose ‘Insert’ from the Analysis ribbon and either choose a query from the
favorites or enter the name of a new query. Once you have completed this task please display the
design panel.
September 2014
3
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
In the design panel go to the components tab and click on the name of the cross tab. Please note the
‘Formula Alias’ (by default it is ‘Crosstab1’ for the first cross tab).
September 2014
4
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
3.2
Create the Macros
Now go to the developer ribbon in Excel there choose the entry ‘Visual Basic’.
First of all we will create the main macros for highlighting the cells. We will do this in an own module.
In order to do so call the context menu on the VBA project and choose ‘Insert->Module’. In the
properties change the mane of the module to ‘AO_TRACK_CHANGES’.
September 2014
5
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
Now go to the appendix, copy the macro coding from appendix 4.1 and insert it into the module.
September 2014
6
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
Now we create the coding used to trigger the above macros. Create a second module and copy and
paste the coding from appendix 4.2 into it.
This module contains three macros:
StartHighlighting: This macros switches the highlighting on.
StopHighlighting: This macro switches the highlighting off.
Callback_AfterRedisplay: This macro calls the highlighting feature for certain crosstabs. In the version
in our appendix we call the highlighting functionality for a crosstab with the formula alias ‘Crosstab1’
(see above). If you want to highlight changes in a crosstab with another name simply change the
coding.
Our coding also works for several queries and these queries do not need to be plan queries. If you
want to highlight additional queries just enter a new command into the macro and make sure the name
of the crosstab is correct. If you want to highlight changes in two queries with the formula alias’
‘Crosstab1’ and ‘Crosstab2’ then your macro ‘Callback_AfterRedisplay’ should look like this:
Sub Callback_AfterRedisplay()
Call AO_TRACK_CHANGES.updateMapAndCompare("Crosstab1")
Call AO_TRACK_CHANGES.updateMapAndCompare("Crosstab2")
End Sub
You now have different options for enabling the highlighting feature.
3.3
Enable the Highlighting Automatically
When using this option the highlighting will automatically be switched on when the workbook is
started.
In the VBA editor double-click on ‘ThisWorkbook’. Now copy and paste the coding from appendix 4.3.
September 2014
7
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
As a consequence the highlighting macro will be registered automatically as a callback after
redisplaying the data.
3.4
Using Buttons to Enable the Highlighting
You could also create an application where the end user can manually enable and disable the
highlighting.
Go to your workbook, choose ‘Insert’ from the developer’s ribbon, and insert a button. Excel will
automatically prompt you for the macro. From the list of macros choose ‘Start Highlighting’.
Now press ‘OK’. Rename the button accordingly.
September 2014
8
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
In the same way create a button for disabling the highlighting. Please use the macro ‘StopHighlighting’
for this button.
The two approaches described in 3.3 and 3.4 can also be combined.
3.5
Test your Workbook
You can now test your new workbook. Just enter some data and press ‘recalculate’. Changed records
will be marked in orange.
We open our workbook:
Now we enter some new data:
September 2014
9
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
After a refresh several cells are marked as changed:
The two cells we have entered are marked as well as the corresponding subtotal (on product group)
and the grand total.
If we change the drill down and receive NEW records then those records will be marked green.
Now our initial query is filtered by a product:
We remove the filter and see that the additional (new) lines which will be marked in green:
September 2014
10
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
Please note that the subtotal containing the original product and the grand total are marked in orange.
This is the case as they were visible in the initial state but were filtered to the single product. Thus
when changing the filter they are no new cells but changed cells.
If you do not like the colors we use for specifying changed or new cells please go to VBA editor and
open the module ‘AO_TRACK_CHANGES’. In the constants at the beginning you can change the
used style and thus the colors. Please not that we have used standard BW exception styles.
September 2014
11
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
4.
Appendix – Macro Coding
4.1
Coding in Module AO_TRACK_CHANGES
Option Explicit
Dim MapCollection As Object
Const C_STYLE_NEW = "SAPExceptionLevel1"
Const C_STYLE_CHANGED = "SAPExceptionLevel4"
Public Sub clearMapTable()
If Not MapCollection Is Nothing Then
Set MapCollection = Nothing
End If
End Sub
Public Sub updateMapAndCompare(CrossTabName As String)
' when called the first time, the before status must be kept - and no delta is possible
If MapCollection Is Nothing Then
Set MapCollection = CreateObject("Scripting.Dictionary")
End If
' do we have information about the current crosstab already?
Dim isNewMap As Boolean
isNewMap = Not MapCollection.exists(CrossTabName)
If isNewMap = True Then
Call createMapInitial(CrossTabName)
Exit Sub
End If
Dim isNewDataCell As Boolean
Dim isChangedDataCell As Boolean
Dim keyMap As String
Dim sel As Variant
September 2014
12
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
Dim map As Object
Dim newMap As Object
Set newMap = CreateObject("Scripting.Dictionary")
Dim Cell As Variant
Dim cross As Range
On Error GoTo RangeNotFound
Set cross = Range("SAP" + CrossTabName)
' get the correct comparison table
Set map = MapCollection.Item(CrossTabName)
Dim RowSel As Object
Dim ColSel As Object
Dim rowkey As Variant
Dim colkey As Variant
' delete the last selection tables
If Not RowSel Is Nothing Then
Set RowSel = Nothing
End If
If Not ColSel Is Nothing Then
Set ColSel = Nothing
End If
Set RowSel = CreateObject("Scripting.Dictionary")
Set ColSel = CreateObject("Scripting.Dictionary")
Call FillSelTabs(CrossTabName, RowSel, ColSel)
For Each Cell In cross
If isDataCell(Cell) = True Then
' task1: build up new before status - as reference for next comparison
rowkey = RowSel.Item(Cell.row)
colkey = ColSel.Item(Cell.column)
keyMap = rowkey & ";" & colkey
September 2014
13
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
If rowkey <> "" Then
Call newMap.Add(keyMap, Cell.Value)
End If
' task2: check if cell values has changed or newly occured
isNewDataCell = Not map.exists(keyMap)
If isNewDataCell = True Then
' we only mark new cells it they are not empty lines
If rowkey <> "" Then
Cell.Style = C_STYLE_NEW
End If
Else
isChangedDataCell = (map.Item(keyMap) <> Cell.Value)
If isChangedDataCell = True Then Cell.Style = C_STYLE_CHANGED
End If
End If
Next
' update the MapCollection
Set MapCollection(CrossTabName) = newMap
On Error GoTo 0
Exit Sub
RangeNotFound:
Dim text As String
text = "There is no named range for " + CrossTabName
Call Application.Run("SAPAddMessage", text)
On Error GoTo 0
End Sub
Sub createMapInitial(CrossTabName As String)
Dim map As Object
Dim cross As Range
Dim Cell As Variant
Set map = CreateObject("Scripting.Dictionary")
On Error GoTo RangeNotFound
September 2014
14
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
Set cross = Range("SAP" + CrossTabName)
Dim RowSel As Object
Dim ColSel As Object
Dim rowkey As Variant
Dim colkey As Variant
Dim keyMap As String
' delete the last selection tables
If Not RowSel Is Nothing Then
Set RowSel = Nothing
End If
If Not ColSel Is Nothing Then
Set ColSel = Nothing
End If
Set RowSel = CreateObject("Scripting.Dictionary")
Set ColSel = CreateObject("Scripting.Dictionary")
Call FillSelTabs(CrossTabName, RowSel, ColSel)
For Each Cell In cross
If isDataCell(Cell) = True Then
rowkey = RowSel.Item(Cell.row)
colkey = ColSel.Item(Cell.column)
keyMap = rowkey & ";" & colkey
If rowkey <> "" Then
Call map.Add(keyMap, Cell.Value)
End If
End If
Next
Call MapCollection.Add(CrossTabName, map)
On Error GoTo 0
Exit Sub
RangeNotFound:
Dim text As String
September 2014
15
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
text = "There is no named range for " + CrossTabName
Call Application.Run("SAPAddMessage", text)
On Error GoTo 0
End Sub
Private Function createKey(sel As Variant) As String
createKey = Join(WorksheetFunction.Transpose(WorksheetFunction.Index(sel, 0, 3)), ";")
End Function
Private Function isDataCell(Cell As Variant) As Boolean
isDataCell = (Left(Cell.Style.Name, 7) = "SAPData" Or Left(Cell.Style.Name, 7) = "SAPEdit" Or
Left(Cell.Style.Name, 7) = "SAPRead")
End Function
Private Function FillSelTabs(CrossTabName As String, RowSel As Object, ColSel As Object)
Dim cross As Range
Dim row As Integer
Dim column As Integer
Dim MinRow As Integer
Dim MinColumn As Integer
Dim i As Integer
Dim sel As Variant
Set cross = Range("SAP" + CrossTabName)
' get the first member row
Dim sheet As Object
Set sheet = Worksheets(cross.Worksheet.Index)
For i = cross.row To cross.row + cross.Rows.Count - 1
row = i
column = cross.column
If sheet.Cells(row, column).Style.Name <> "SAPDimensionCell" Then Exit For
Next
MinRow = row
' get the first member column
For i = cross.column To cross.column + cross.Columns.Count - 1
row = cross.row
column = i
If sheet.Cells(row, column).Style.Name <> "SAPDimensionCell" Then Exit For
Next
MinColumn = column
September 2014
16
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
' loop over the member rows and get the selection key
For i = MinRow To cross.row + cross.Rows.Count - 1
sel = Application.Run("SAPGetCellInfo", sheet.Cells(i, cross.column), "SELECTION")
If IsError(sel) = False Then
Call RowSel.Add(i, createKey(sel))
Else
' if the cell is not initial and still it has no selection then it is probably a total
If sheet.Cells(i, cross.column).Value <> "" Then Call RowSel.Add(i, "total")
End If
Next
' loop over the member columns and get the selection key
For i = MinColumn To cross.column + cross.Columns.Count - 1
sel = Application.Run("SAPGetCellInfo", sheet.Cells(cross.row, i), "SELECTION")
If IsError(sel) = False Then Call ColSel.Add(i, createKey(sel))
Next
End Function
4.2
Coding in Second Module
Option Explicit
Sub StartHighlighting()
Dim lResult
lResult = Application.Run("SAPExecuteCommand", "RegisterCallback", "AfterRedisplay",
"Callback_AfterRedisplay")
If lResult = 1 Then
Call Application.Run("SAPAddMessage", "Callback registered successfully")
Else
Call Application.Run("SAPAddMessage", "Callback registration failed!")
End If
Call Callback_AfterRedisplay
End Sub
Sub StopHighlighting()
Dim lResult
lResult = Application.Run("SAPExecuteCommand", "UnregisterCallback", "AfterRedisplay")
If lResult = 1 Then
September 2014
17
How To...Highlight Changed Cells in SAP BusinessObjects Analysis for Office
Call Application.Run("SAPAddMessage", "Callback un-registered successfully")
' we delete all existing mapping tables
Call AO_TRACK_CHANGES.clearMapTable
Else
Call Application.Run("SAPAddMessage", "Callback un-registration failed!")
End If
End Sub
Sub Callback_AfterRedisplay()
Call AO_TRACK_CHANGES.updateMapAndCompare("Crosstab1")
'Call AO_TRACK_CHANGES.updateMapAndCompare("Crosstab2")
End Sub
4.3
Coding in ThisWorkbook
Public Sub Workbook_SAP_Initialize()
' register callb
Call Application.Run("SAPExecuteCommand", "RegisterCallback", "AfterRedisplay",
"Callback_AfterRedisplay")
End Sub
September 2014
18
www.sdn.sap.com/irj/sdn/howtoguides
© Copyright 2026 Paperzz