macro in bex

Upload: saurabh840

Post on 14-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Macro in BEx

    1/7

    Embedding Macro in BEX Analyzer

    It often happens that while developing a workbook in analyzer, we

    come across a need from the user which can be easily dealt with by

    writing small macro codes in our workbook.

    In this document, I have mentioned the specific steps for creating and

    embedding a macro code in the workbook, I have illustrated this with

    the help of few scenarios.

    Scenario:

    The requirement is to develop a report which shows the forecastaccuracy of various products. The accuracy is calculated at different

    levels like plant level, national level, zone level etc.

    Why we needed macro:

    The BEX query has 31 selections in the key figure structure, each

    representing a date in a month.

    In analyzer, the output of this query will mapped to another locally

    created table which has to show rolling sum.

    This table will then be used to draw a graph representing daily sales.

  • 7/29/2019 Macro in BEx

    2/7

    Divisions Day1 Day2 Day2 Day3 Day4 Day5 Day6

    A 100 50 90 100 900 500 300

    B 200 300 300 500 100 200 400

    Table 2 is being filled up by table 1, which actually is BEX query. The

    excel formula to add up the previous cell has been applied to all the

    cells.

    This causes an issue; all the cells up to Day31 get filled up in table 2.

    Because of this, the graph which has been mapped to table 2 to show

    daily accumulated sales shows values till day 31. We want the graph to

    show the data till current day -1.

    This can be easily achieved using the macros. With a macro code well

    check the current date and then delete the values from all the cells

    which fall after the required day.

    Divisions Day1 Day2 Day2 Day3 Day4 Day5 Day6

    A 100 150 240 340 1240 1750 2050

    B 200 500 800 1300 1400 1600 2000

  • 7/29/2019 Macro in BEx

    3/7

    The tables created in Analyzer:

    The graph is mapped to table 2 and appears as following:

    Here we see that the lines appear till day 15, actually they should have

    appeared till current date only.

  • 7/29/2019 Macro in BEx

    4/7

    To view the VBA editor just go to the sheets and right click on them:

    A list of the options appears as shown in the above screenshot. Select

    the View code option to start the editor. The initial editor looks like

    the following:

    All the sheets present in the workbook are

    listed here. They are named as sheet1,

    sheet2 etc. In program that write, we

    always refer to them as sheet1, sheet2 etc

    and not by the description that we provide

    to the sheets.

    This shows the various properties of the

    sheet.

    This is the actual editor area where we write the code

  • 7/29/2019 Macro in BEx

    5/7

    In the present case, we want the code to be executed when the sheet is

    activated. So we select the Activate function.

    The code has been written to populate the table for the graph up to the

    current day only:

  • 7/29/2019 Macro in BEx

    6/7

    The table from which the graph draws its data appears as follows:

    The line in the graph appears till the current date only:

    This is a very simple situation which I have come across; there might

    be several situations where a simple VBA code can resolve a complex

    issue. Most of the time, BW consultants tend to overlook the

    usefulness of the power of excel that is inherently added to the

    analyzer along with the BEX.

  • 7/29/2019 Macro in BEx

    7/7

    Here are few links that will help you get started with the macro:

    1. http://www.few.vu.nl/~rbekker/VBA-intro.pdf2. http://www.staff.city.ac.uk/~fring/ExcelVBA/

    http://www.few.vu.nl/~rbekker/VBA-intro.pdfhttp://www.few.vu.nl/~rbekker/VBA-intro.pdfhttp://www.staff.city.ac.uk/~fring/ExcelVBA/http://www.staff.city.ac.uk/~fring/ExcelVBA/http://www.staff.city.ac.uk/~fring/ExcelVBA/http://www.few.vu.nl/~rbekker/VBA-intro.pdf