You are on page 1of 10

Replacement Path Variables Replacement with Query They May Save You Some Time

Applies to:
SAP BW 3.5 to 7.3

Summary
Replacement path variables, replacement with query are often forgotten. For a quick example were going to demonstrate how to filter over an attribute that is not marked as navigational, off course you need the info object to be enabled for reporting. I recommend you to read this and then Im sure you will come with a lot of ideas for this very useful type of variables. Author: Miguel Peredo Zrcher

Company: Global IT Professional Services Created on: 15 October 2011

Author Bio
Miguel has worked for more than 8 years in ABAP and BW. Has experience in the backend and frontend of BW, he also holds certifications for BW, ABAP and Webdynpro.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 1

Replacement Path Variables - Replacement with Query They May Save You Some Time

Contents
Replacement Path Variables .............................................................................................................................. 3 Replacement with a Query .............................................................................................................................. 3 Lets create the example ................................................................................................................................. 4 How does this works ....................................................................................................................................... 8 Related Content .................................................................................................................................................. 9 Disclaimer and Liability Notice .......................................................................................................................... 10

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 2

Replacement Path Variables - Replacement with Query They May Save You Some Time

Replacement Path Variables


The idea behind replacement variables is simple, the value of a query variable will be replaced by some value that can be derived from other element. According to the type of variable, you can make different settings for the replacement path. 1. Text and formula variables with the processing type Replacement Path are replaced by a corresponding characteristic value. See Replacement Path: Replacement with a Characteristic Value. 2. Characteristic value variables with the processing type Replacement Path, are replaced by the results of a query. See Replacement Path: Replacement with a Query. In this article will focus on the number 2 type. Replacement with a Query One way of understanding this types of variables is comparing them to a nested SQL statement. For example you need to select total purchase for all vendors which attribute Y equals X. In the infoprovider where the sales are contained the attribute X is not marked as navigational. The infoobject is enabled for reporting, so you can solve your problem in two steps: Create a query that returns the list of all vendor for which attribute Y equals x. The list of vendors from the first query will determine which vendors will be used in the second query.

The first query is executed and the results (in this case a list of vendors) of that 1 query are stored in a variable; this variable is then used to filter the list of vendors in the second query. For this example only vendors V2 and V3 do have attribute Y = X.

st

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 3

Replacement Path Variables - Replacement with Query They May Save You Some Time

Lets create the example As mentioned in the summary, our goal is: We have an infoprovider I1 that contains characteristic 0VENDOR. 0VENDOR has an attribute called 0COUNTRY and this attribute is NOT marked as navigational on the infoprovider I1. We need to filter in a query based on I1, all vendors whose attribute 0COUNTRY is equal to = BO.

For this example we need 0VENDOR to be enabled as: Characteristic is InfoProvider, you can check for this on the Master Data/Texts tab of the characteristic maintenance screen:

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 4

Replacement Path Variables - Replacement with Query They May Save You Some Time

Now we are able to create a query that filter on any of the attribute of 0VENDOR, since 0VENDOR will be our Infoprovider. We filter the query by any of the attributes we want, in this case I chose Country = BO (Bolivia)

It is in important that the characteristic 0VENDOR itself is in the Rows or Columns of the query ,so this can be sent to the variable.

We call this query: Z_0VENDOR_ATTR When we run this query we see as result a list of vendors, only those whose country = BO. This list of vendor will be applied as a filter to the next query.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 5

Replacement Path Variables - Replacement with Query They May Save You Some Time

We create a new query based on any Infoprovider that has 0VENDOR. We drag 0VENDOR to the filter area, and create a new variable:

Then we chose Show: Variables and press the NEW button:

The new variable screen appears:

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 6

Replacement Path Variables - Replacement with Query They May Save You Some Time

Now switch to the Replacement Path Tab:

This is the important step as you can see; we are creating a link between the first query (Based on 0VENDOR) and our new variable. Then we filter 0VENDOR with the new variable we created:

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 7

Replacement Path Variables - Replacement with Query They May Save You Some Time

How does this works When you execute the second query which contains Replacement Path Replace by query variable, the following happens: The first query is executed, please note that if the first query has some Input Ready variables this variable screen will be shown. The results of this query are passed to the variable as multiple selections. The second query is executed.

Because of this you always have to take performance in account. In this case running one query means the execution of two queries. This is a very simple example of the use of these variables, there are a lot, please experiment.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 8

Replacement Path Variables - Replacement with Query They May Save You Some Time

Related Content
Replacement Path: Explained with an Illustrated Example (SDN) BW Text Variables of Type Replacement Path (SDN) Replacement Path (SAP HELP)

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 9

Replacement Path Variables - Replacement with Query They May Save You Some Time

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 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 10