Post on 24-Jul-2020
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 1
WDJ - Application to execute MDX query using the BI Java SDK
Applies to: This document and the presented code example rely upon SAP NWDS v 2.0.16 (Web Dynpro Java), SAP WAS 6.40 SP16, BI Java SDK SP15, BW 3.5.
Summary This document provides detailed instructions on how to use the BI Java SDK and its BI Java Connectors in a Web Dynpro Application. It contains step-by-step instructions for adding the required library references required to use the BI Java SDK, and for establishing a connection using the BI XMLA Connector in the Web Dynpro and J2EE environment (Managed environment of the J2EE Server). Author(s): Ashwin Bhat Company: L&T Infotech, Mumbai , India Created on: 16 March 2007
Author Bio Ashwin Bhat is a SAP technical consultant working with L&T Infotech, Mumbai, India. His SAP experience of over 2 and a half years spans various technologies such as BW, ABAP and Web Dynpro for Java.
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 2
Table of Contents Applies to: ........................................................................................................................................ 1 Summary.......................................................................................................................................... 1 Author Bio ........................................................................................................................................ 1 Introduction ...................................................................................................................................... 3 How to develop a Web Dynpro Application for use in a managed enviornment ............................. 5
Pre-Requisites:............................................................................................................................. 5 Step by Step Solution ...................................................................................................................... 6
Prepare the System ..................................................................................................................... 6 Create the Web Dynpro Application............................................................................................. 9
Add the BI Java SDK libraries for compilation: ...................................................................... 11 Add the library reference ........................................................................................................ 13 Add the sharing reference ...................................................................................................... 14 Application Layout and Implementation ................................................................................. 15
Related Content............................................................................................................................. 25 Disclaimer and Liability Notice....................................................................................................... 26
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 3
Introduction This document provides detailed instructions on how to use the BI Java SDK and its BI Java Connectors in a Web Dynpro Application. It contains step-by-step instructions for adding the required library references required to use the BI Java SDK, and for establishing a connection using one of the BI Java Connectors (BI XMLA Connector) in the Web Dynpro and J2EE environment (Managed environment of the J2EE Server). This Web Dynpro application can be used to execute MDX queries against the SAP BW System. BI Java SDK 1
With the BI Java SDK, you can build analytical applications that access, manipulate, and display both multidimensional (Online Analytical Processing, or OLAP) and tabular (relational) data. The BI Java SDK consists of a Java application programming interface (API) in Java class libraries, documentation, and examples. The applications you create can access, manipulate, and display OLAP and relational data from diverse data sources. BI Java Connectors 2
The BI Java Connectors are a group of four JCA (J2EE Connector Architecture)-compliant resource adapters that implement the BI Java SDK's APIs and allow you to connect the applications you build with the SDK to heterogeneous data sources. They may be deployed onto SAP NetWeaver's J2EE Web Application Server. The BI Java SDK contains the JAR files you need to develop applications using any of the BI Java Connectors and to use them in an unmanaged scenario, but to use your application with a data source in the managed environment of the J2EE server, you need to deploy the appropriate BI Java Connector onto your WAS. Four connectors are available:
• BI JDBC Connector, for connecting to relational JDBC data sources. Implements the SDK’s relational APIs.
• BI ODBO Connector, for connecting to OLE DB for OLAP-compliant data sources. Implements the SDK’s OLAP APIs
• BI SAP Query Connector, for connecting to data from SAP operational applications. Implements the SDK’s relational APIs.
• BI XMLA Connector, for connecting to XMLA-compliant data providers such as SAP’s BW. Implements the SDK’s OLAP APIs.
To learn more about the BI Java Connectors refer to the following link. BI Java Connectors
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 4
MDX Query MDX (multi-dimensional expressions) is a language developed by Microsoft for queries using multi-dimensional data. MDX is to OLAP as SQL is to relational databases. Visit the following weblog on SDN for more information on MDX Queries. Quick help in creating MDX statement https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/1790 The transaction MDXTEST in the BW system can be used to generate/execute MDX queries against a data source. Note: Parts of this document have been compiled using the following sources:
• BI Java SDK Documentation Details on Documentation, Business scenario, Examples, Connectors, Installation, Release notes.
• How To Use the BI Java SDK in a Web Dynpro Application Available in the BI Java SDK Documentation as a “How-To” Guide.
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 5
How to develop a Web Dynpro Application for use in a managed enviornment We use the BI Java SDK to custom build the Web Dynpro application and establish the connection with the BI XMLA Connector. This example will demonstrate how to connect to a BW system using the BI XMLA Connector, execute an MDX Query input by the user and render the result set in a web page.
Pre-Requisites: • SAP NetWeaver Developer Studio (NWDS) installed on your system
• You have access to the SAP J2EE engine.
• BI Java SDK: Copy the following link into your browser to download the BI Java SDK available on SDN https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/downloads/evaluation software/SAP Business Intelligence Java Software Development Kit Download.abst
• BI XMLA Connector deployed on the WAS The BI XMLA Connector is deployed to the Web Application Server by default with the BW 3.5 installer. Refer to the following link if you have not selected this connector for installation or to manually deploy the resource adapter archive onto the Web Application Server. It contains details about system requirements, connection properties, deployment procedure etc. SAP BI XMLA Connector
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 6
Step by Step Solution
Prepare the System 3
To prepare the system, you first look up the JNDI name of your connector in the J2EE Visual Administrator, and then configure the connection properties. Use the J2EE Visual Administrator to determine the JNDI name of the BI XMLA connector: 1. Select <server node> Services JNDI Registry. On the Runtime tab, in the registry list, locate deployedAdapters SDK_XMLA shareable SDK_XMLA. This path, from the root to the SDK_XMLA leaf node, indicates the fully qualified JNDI name of the BI XMLA Connector, which is: deployedAdapters/SDK_XMLA/shareable/SDK_XMLA.
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 7
Configure the connection properties using the J2EE Visual Administrator:
2. Select the server node, and choose <server node> Services Connector Container. 3. Locate and double-click the entry for the BI XMLA Connector,
sap.com/com.sap.ip.bi.sdk.dac.connector.xmla.BI_SDK_XMLA, to open the connector definition.
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 8
4. Select Managed Connection Factory Properties, and set the required connection properties as shown below. Connection Properties
Property Name Description Examples
UserName Data source username (your username)
Password Data source password (your password)
Language Two-letter abbreviation of language. Determines logon language for BW systems, and specifies the language of exceptions evoked on the BI Java SDK layer. Optional.
EN = English
DE = German
URL Server URL BW XMLA provider -- http://[domain:port]/sap/bw/xml/soap/xmla
DataSource Server URL Local Analysis Server
Statefulness Statefulness support. Optional. Default is false
true or false
Statefulness = true works properly only in the J2EE engine version SP Stack 12 or greater.
* Note: To find the URL of a BW XMLA provider:
For a BW system, start transaction SE37 and execute the function module
RSBB_URL_PREFIX_GET.
Use the following values for the import parameters of the function module:
I_HANDLERCLASS = CL_RSR_MDX_SOAP_HANDLER
I_PROTOCOL = HTTP
I_MESSAGESERVER =
The URL takes the following form: */sap/bw/xml/soap/xmla.
5. Save the settings.
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 9
Create the Web Dynpro Application In the SAP NetWeaver Developer Studio, create a new Development Component (DC). Create an Application, Component, Window with a Viewset and 2 views in this DC. (Refer to SAP tutorials on how to create WD applications if required) We will develop the UI and implement the code later.
Component
Name BI_MDXComp
Views
Name SelectionView
OutBound plug ToResultOut
Name ResultView
Inbound Plug FromSelectionIn
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 10
Window
Name BI_MDXCompWindow
Viewset
Name BI_MDXViewset
Default true
Columns 1
Rows 2
Type Grid Layout
Applications
Name BI_MDXApp
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 11
To use the BI Java SDK to create a Web Dynpro application, you need to add the BI Java SDK libraries for compilation, library references and a sharing reference:
Add the BI Java SDK libraries for compilation:
To do this go to the DC in the ‘Web Dynpro Explorer’ view of the ‘Web Dynpro’ perspective and right click on the ‘Used DCs’ under <DC name> -> DC MetaData –> DC Definition as shown. In the context menu of Used DCs, select Add Used DC. In the dialog, expand Local Development, and from the contained Software components select each of the following components by highlighting and clicking finish:
From BI_UDI: bi/mmr/cwm_1.0_source bi/sdk/core bi/sdkresultset
From SAP-JEE: j2eeca
From SAP_JTECHS: tc/conn/connectorframework
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 12
The components will get added as shown.
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 13
Add the library reference In the Web Dynpro Explorer view of the Web Dynpro perspective, select your Web Dynpro DC, right-click, and choose Properties from the context menu.
To add the library references, select Web Dynpro References, and select the Library references tab. Add the libraries listed below:
• tc/conn/connectorframework
• com.sap.ip.bi.sdk
• bi~mmr~jmi
• bi~mmr~core
• bi~mmr~db
• bi~mmr~cwm_1.0_library
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 14
Add the sharing reference
To add the sharing reference to the BI XMLA Connector, select the Sharing references tab, and add the reference listed below:
• sap.com/com.sap.ip.bi.sdk.dac.connector.xmla
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 15
Application Layout and Implementation
1. Insert the SelectionView in row 1 and ResultView in row 2 of the BI_MDXViewset as shown.
Set the property ‘default’ of the SelectionView to true and that of ResultView to false.
2. In the Navigational Modeler, create the navigation link between the two views as shown.
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 16
3. Create the layout for the SelectionView as shown.
UI Elements:
Property Value
Tray
Id try_Selection
Layout FlowLayout
Design Transparent
Caption – Header text Selection Screen
Transparent Container
Id trc_Selection
Layout GridLayout
ColCount 1
Message Area
Id msg_Messages
PaddingBottom Medium
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 17
Property Value
Group
Id grp_Selection
Layout GridLayout
Design Primary Color
Caption – Header text Enter MDX Query
TextEdit
Id txe_MDXQ
Cols 100
Rows 10
Tooltip Enter the MDX Query
PaddingBottom Medium
ActionButton (Added using Apply template in the Outline view of the Layout)
Id btn_Display
Text Display
OnAction Display*
* Fire the outbound plug ‘ToResultOut’ in the eventHandler ‘onActionDisplay’ for this event.
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 18
4. Next, create a value attribute ‘MDXQ’ of type string in the Context Tab of the View ‘SelectionView’. In
the Layout tab, bind the property ‘value’ of the TextEdit element with the Context attribute ‘MDXQ’.
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 19
5. In the context of the View ‘ResultView ‘ create the following value attributes.
Context Attributes
Name Type
IFrameData String
MDXQ String (mapped from SelectionView via the Component Controller)
Result_Visibility com.sap.ide.webdynpro.uielementdefinitions.Visibility
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 20
6. Create the Layout for the View ‘ResultView as shown below.
Property Value
Transparent Container
Id trc_Result
Layout FlowLayout
Visible Result_Visibility
Group
Id grp_Result
Design primarycolor
Layout Grid Layout
Height 500px
Width 100%
Caption – Header Text Result
IFrame
Id Ifm_ResultFrame
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 21
Property Value
Height 100%
Width 100%
Scrolling Mode Auto
Source IframeData
vAlign bottom
7. Go to the Methods Tab and create a method called ‘getResult’ with no parameters and return type void.
8. Go to the Implementation tab and call the method ’getResult’ in the event handler
‘onPlugFromSelectionIn’.
9. Paste the following code in the method ‘getResult’.
//@@begin getResult() IConnectionFactory connectionFactory = null; IBIConnection connection = null; IBIDataSet dataset = null; // get the MDX statement entered by the User String mdxStatement = wdContext.currentContextElement().getMDXQ(); // Declare a stringbuffer to store the HTML Code StringBuffer l_strXmlFile = new StringBuffer(); try { // ******************************************************** // Connect to BW System // ******************************************************** Context initctx = new InitialContext(); // Perform JNDI lookup to obtain connection factory connectionFactory = (IConnectionFactory) initctx.lookup( "deployedAdapters/SDK_XMLA/shareable/SDK_XMLA"); // Establish connection using default connection properties connection = (IBIConnection) connectionFactory.getConnectionEx(null); IBIOlap olap = ((IBIConnection) connection).getOlap();
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 22
// ******************************************************** // Execute the MDX statement and retrieve the data set // using the execute method of the IBIOlap interface. // ******************************************************** dataset = olap.execute(mdxStatement); } catch (Exception e) { e.printStackTrace(); wdComponentAPI.getMessageManager().reportException( e.getLocalizedMessage(), true); } finally { try { connection.close(); } catch (ResourceException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } Ensure that dataset is not null // the if (dataset == null) { wdContext.currentContextElement().setResult_Visibility( WDVisibility.NONE); } else { wdContext.currentContextElement().setResult_Visibility( WDVisibility.VISIBLE); // ******************************************************** // Render the data set. // ******************************************************** l_strXmlFile .append("<html>") .append("<head></head>") .append("<body>"); // Display the MDX that has been executed. l_strXmlFile .append("<p><b>MDX Statement that was executed:</b><br> ") .append("<span class=\"code\">") .append(mdxStatement) .append("</span> </p>"); try { BIDataSetTableModel table = new BIDataSetTableModel(dataset, false); l_strXmlFile.append("<p>Result set:</p>"); l_strXmlFile.append( "<table width=700 border=1 cellpadding=0 cellspacing=0>"); int row = table.getRowCount(); int col = table.getColumnCount();
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 23
for (int i = 0; i < row; i++) { l_strXmlFile.append("<tr>"); for (int j = 0; j < col; j++) {
BITableItem item = (BITableItem) table.getValueAt(i, j);
l_strXmlFile.append("<td class=\"headCenter\">"); l_strXmlFile.append(Helpers.escape(item.toString()));
l_strXmlFile.append("</td>"); } l_strXmlFile.append("</tr>"); } l_strXmlFile.append("</table>");
l_strXmlFile.append("</body></html>"); } catch (BISQLException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } // read the stringbuffer into bytes byte[] l_byteData = null; try { l_byteData = l_strXmlFile.toString().getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { wdComponentAPI.getMessageManager().reportException( e.getLocalizedMessage(), false); } // Create a web resource and set the value of the // context variable "IFrameData" to it's URL IWDCachedWebResource l_File = WDWebResource.getWebResource( l_byteData, WDWebResourceType.HTML); try { wdContext.currentContextElement().setIFrameData( l_File.getURL()); } catch (WDURLException e1) { wdComponentAPI.getMessageManager().reportException( e1.getLocalizedMessage(), false); } } //@@end
NOTE: After copying this code into the method format the code by
Right click Code Format
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 24
10. Build, Deploy and Run
Build your DC and deploy it to the WAS. Run the application. Enter an MDX Query in the Text Edit and click Display to view the result.
Sample MDX query:SELECT [Measures].MEMBERS ON AXIS(0) , NON EMPTY [0VENDOR].MEMBERS ON AXIS(1) FROM [0PUR_C01/0PUR_C01_DB_Q04]
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 25
Related Content
• BI Java SDK Documentation
• How To Use the BI Java SDK in a Web Dynpro Application
• BI Java Connectors
• Quick help in creating MDX statement https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/1790
• “How –To” Document for the BI XMLA Connector
WDJ - Application to execute MDX query using the BI Java SDK
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 26
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.
1 Welcome to the BI Java Software Development Kit, “BI Java Software Development Kit”, SAP AG, http://help.sap.com/javadocs/NW04/current/bi/index.html 2 BI Java Connectors, “BI Java Software Development Kit” , SAP AG, http://help.sap.com/javadocs/NW04/current/bi/docs/connectors.html 3 “How To Use the BI Java SDK in a Web Dynpro Application”, ver. 1.01 July 2005, SAP AG http://help.sap.com/javadocs/NW04/current/bi/docs/howtos/How_To_BI_Java_SDK_WebDynpro_App.pdf