Use a dropdown box to set variable values

[Pages:10]How to...

Use a dropdown box to set variable values

BUSINESS INFORMATION WAREHOUSE

Applicable Releases: BW 3.0B / 3.x Content January 2004

SAP (SAP America, Inc. and SAP AG) assumes no responsibility for errors or omissions in these materials. 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. mySAP BI "How-To" papers 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 mySAP BI. Should you wish to receive additional information, clarification or support, please refer to SAP Professional Services (Consulting/Remote Consulting).

HOW TO ... USE A DROPDOWN BOX TO SET VARIABLE VALUES

1 Business Scenario

You want to set variable values via a dropdown box, rather than displaying the variable entry screen. Using a filter value is not an option since you are using a variable in the key figure structure. Please see the Help documentation for an example of using offset variables: .

2 Introduction

This scenario presents multiple challenges. While we can easily display characteristic values in a dropdown box, we need to maintain state in the web application in order to display the last choosen value in the dropdown box. Without state, the dropdown box would default to either `All' or the first sequential value each time the web application loads. We will maintain state via hidden text element.

Furthermore, we have to account for the internal and external representation of characteristic values. Internally, for example, 0CALMONTH is stored in the format YYYYMM, yet externally the representation depends on the user's preference setting and can thus be YYYY/MM, MM/YYYY or MM.YYYY. To complicate matters, variables values can only changed with external format. Hence, we will need JavaScript functions that can convert between the two formats.

The sequence of steps for this web application example is as follows: When the web application loads, retrieve the hidden text element value and set the corresponding value in the dropdown box to `selected'. When the user makes a change in the dropdown box, we retrieve the selected value form the dropdown box and call the WEB API to set the new variable value, after which the entire process repeats.

2004 SAP LABS, LLC AND SAP AG

1

HOW TO ... USE A DROPDOWN BOX TO SET VARIABLE VALUES

3 The Step-By-Step Solution

1. You have created a query that uses a variable in the key figure structure.

2.

You have created a query

that contains the characteristic of the

variable from step one ? in this case

0CALMONTH

2004 SAP LABS, LLC AND SAP AG

2

HOW TO ... USE A DROPDOWN BOX TO SET VARIABLE VALUES

3.

You have created a web

application that contains one each of the

following items: dropdown box , table,

and text elements.

Furthermore the template has two dataproviders (one for each of the queries discussed earlier), DP1 is assigned to the dropdown box, DP2 is assigned to the table and text element items.

4.

Change the following

properties for the dropdown box item:

? Uncheck `Generate Caption'

? Select `0CALMONTH' as the characteristic/structure

? Check `Display Only Values'

? Check `Do not display "All" value'

ITEM:

DROPDOWNBOX_1

5.

In order to avoid the "ALL"

option from appearing in the dropdown

box, filter infobject 0CALMONTH for DP1

by any valid value.

DATA_PROVIDER:

DP1

6.

Switch to the HTML view

and surround your dropdown box object

with a and a tag

within the form. Name the `form' as well

as the `select'. The `select' `onchange'

event will trigger a JavaScript function

which will be defined later.

Calendar month/year:

......

2004 SAP LABS, LLC AND SAP AG

3

HOW TO ... USE A DROPDOWN BOX TO SET VARIABLE VALUES

7.

Next, we will use the text

element item to capture the current value

of the ZMONTH variable.

To accomplish this, specify element type `Variable Value as key' (VARIABLE_KEY) and `ZMONTH' as the name of the variable in the `List of Text Elements' and check `Display Only Values'. Uncheck `Generate Caption'.

8.

Since this element value is

used only in the JavaScript code, we do

not want to display it to the user. Thus, we

will name the tag surrounding the

object and specify a style as well. By using

the `id' property we can later retrieve the

values of variable ZMONTH.

......

9.

Since we want to display

the last selected month in the dropdown

box when the web application loads, we

need to code and call a JavaScript function.

First, let's call it. The code needs to be placed after the tag of the text

element object, within the

section.

...

ITEM:

TEXTELEMENTS_1

10.

Coding the `set_dd_box'

function. After the tag but before

the section of your HTML code,

add the

tags and place all JavaScript

code within those tags. In short, we are

retrieving the variable value and using it

to set the corresponding value in the drop

down box. Please see the comments in the

code for more details.

function set_dd_box() { //retrieve the value of the text element ZMONTH ddvalue = document.getElementById('varvalue').innerHTML; // convert the external representation to the internal representation // needed for selecting a value in the dropdown box ddvalue_int = chavl_ext_to_int_convert(ddvalue,'0CALMONTH'); // using the document object model (DOM), get the number of values // in the dropdown box, loop through the entries and compare the retrieved // value against the dropdown box contents. If there is a match, set the value // as the 'selected' value for (i=0; i< document.frmState.calmonth.options.length; i++) {

if (document.frmState.calmonth.options[i].value == ddvalue_int) document.frmState.calmonth.selectedIndex = i;

} }

2004 SAP LABS, LLC AND SAP AG

4

HOW TO ... USE A DROPDOWN BOX TO SET VARIABLE VALUES

11.

You will notice that

function `set_dd_box' calls function

chavl_ext_to_int_convert' which converts

the external representation to the internal

format. In order to do the conversion, we

need to now the external format which we

can obtain by looking at the web template

property DATE_FORMAT using the SAP

provided JavaScript function

`SAPBWGetProperty'. More information is

available here:



data/en/07/7f00d09a201f46b54036dfc348

3164/content.htm

function chavl_ext_to_int_convert(extformat, iobjnm) {

if (iobjnm== '0CALMONTH') { var date_format = SAPBWGetProperty('DATE_FORMAT'); // possible values DATE_FORMAT: Date format (1: DD.MM.YYYY,

2: MM/DD/YYYY, 3: MM-DD-YYYY, // 4: YYYY.MM.DD, 5: YYYY/MM/DD, 6: YYYY-MM-DD) if (date_format < '4') return extformat.substring(3,7) + extformat.substring(0,2); else return extformat.substring(0,4) + extformat.substring(5,7);

} }

12.

Next, we need a JavaScript

function that is invoked when the user

changes the month in the dropdown box.

This function needs to read the selected

value, convert the value to the

characteristic's internal representation and

open the newly build URL. In our case the

function is called `setVariable'.

Using the PROCESS_VARIABLES command we can specify an new value for our ZMONTH variable.

13.

Before we can use the value

from the dropdown box we need to

convert it to the external characteristic

representation using function

`chavl_int_to_ext_convert'. Again, we

need to determine the user's date format

in order to correctly build the external

value.

function setVariable(value) { // ignore the '#' and "!ALL" values if (value == '000000' || value == '!ALL')

alert("Please select a valid month."); else {

url = SAP_BW_URL_Get() + "&CMD=PROCESS_VARIABLES&SUBCMD=VAR_SUBMIT&VAR_NAME _1=ZMONTH&VAR_VALUE_EXT_1=" ;

url = url + chavl_int_to_ext_convert(value,'0CALMONTH'); SAPBWOpenURL(url); } }

function chavl_int_to_ext_convert(intformat, iobjnm)

{ if (iobjnm== '0CALMONTH') { var date_format = SAPBWGetProperty('DATE_FORMAT'); switch (date_format) { case 1: return intformat.substring(4,6) + '.' + intformat.substring(0,4); case 2: return intformat.substring(4,6) + '/' + intformat.substring(0,4); case 3: return intformat.substring(4,6) + '-' + intformat.substring(0,4); case 4: return intformat.substring(0,4) + '.' + intformat.substring(4,6); case 5: return intformat.substring(0,4) + '/' + intformat.substring(4,6); case 6: return intformat.substring(0,4) + '-' + intformat.substring(4,6); }

} }

2004 SAP LABS, LLC AND SAP AG

5

HOW TO ... USE A DROPDOWN BOX TO SET VARIABLE VALUES

14.

Your results should look

similar to the screen capture to the right.

2004 SAP LABS, LLC AND SAP AG

6

HOW TO ... USE A DROPDOWN BOX TO SET VARIABLE VALUES

Appendix

Web application source code:

DATA_PROVIDER:

DP2

DATA_PROVIDER:

DP1

TEMPLATE PROPERTIES

function chavl_int_to_ext_convert(intformat, iobjnm) {

if (iobjnm== '0CALMONTH') { var date_format = SAPBWGetProperty('DATE_FORMAT'); switch (date_format) { case 1: return intformat.substring(4,6) + '.' + intformat.substring(0,4); case 2: return intformat.substring(4,6) + '/' + intformat.substring(0,4); case 3: return intformat.substring(4,6) + '-' + intformat.substring(0,4); case 4: return intformat.substring(0,4) + '.' + intformat.substring(4,6); case 5: return intformat.substring(0,4) + '/' + intformat.substring(4,6); case 6: return intformat.substring(0,4) + '-' + intformat.substring(4,6); }

} } function setVariable(value) { // ignore the '#' and "!ALL" values if (value == '000000' || value == '!ALL')

alert("Please select a valid month."); else {

url = SAP_BW_URL_Get() + "&CMD=PROCESS_VARIABLES&SUBCMD=VAR_SUBMIT&VAR_NAME_1=ZMONTH&VAR_VALUE_EXT_1=" ;

url = url + chavl_int_to_ext_convert(value,'0CALMONTH'); SAPBWOpenURL(url); } }

2004 SAP LABS, LLC AND SAP AG

7

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download