Uploaded by Stefano Muscas

201306 How to Consume SAP HANA Models in SAP NetWeaver BW from Remote HANA Instances

advertisement
SAP How-to Guide
Database & Technology – SAP NetWeaver Business Warehouse
SAP HANA™ Appliance
How to Consume SAP HANA Models in SAP NetWeaver
BW from Remote HANA Instances
Applicable Releases:
SAP HANA 1.0 SPS 05
SAP NetWeaver Business Warehouse 7.3x
Version 1.0
June 2013
© Copyright 2013 SAP AG. All rights reserved.
All other product and service names mentioned are the trademarks of
No part of this publication may be reproduced or transmitted in any form
their respective companies. Data contained in this document serves
or for any purpose without the express permission of SAP AG. The
informational purposes only. National product specifications may vary.
information contained herein may be changed without prior notice.
The information in this document is proprietary to SAP. No part of this
Some software products marketed by SAP AG and its distributors
document may be reproduced, copied, or transmitted in any form or for
contain proprietary software components of other software vendors.
any purpose without the express prior written permission of SAP AG.
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered
This document is a preliminary version and not subject to your license
trademarks of Microsoft Corporation.
agreement or any other agreement with SAP. This document contains
IBM, DB2, DB2 Universal Database, System i, System i5, System p,
System p5, System x, System z, System z10, System z9, z10, z9, iSeries,
pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390,
OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power
Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER,
only intended strategies, developments, and functionalities of the SAP®
product and is not intended to be binding upon SAP to any particular
course of business, product strategy, and/or development. Please note
that this document is subject to change and may be changed by SAP at
any time without notice.
OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS,
SAP assumes no responsibility for errors or omissions in this document.
HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex,
SAP does not warrant the accuracy or completeness of the information,
MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and
text, graphics, links, or other items contained within this material. This
Informix are trademarks or registered trademarks of IBM Corporation.
document is provided without a warranty of any kind, either express or
Linux is the registered trademark of Linus Torvalds in the U.S. and other
countries.
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.
implied, including but not limited to the implied warranties of
merchantability, fitness for a particular purpose, or non-infringement.
SAP shall have no liability for damages of any kind including without
limitation direct, special, indirect, or consequential damages that may
result from the use of these materials. This limitation shall not apply in
cases of intent or gross negligence.
The statutory liability for personal injury and defective products is not
affected. 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 “How-to” Guides are intended to simplify the product implementtation. 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
Java is a registered trademark of Sun Microsystems, Inc.
business problem using SAP NetWeaver. Should you wish to receive
JavaScript is a registered trademark of Sun Microsystems, Inc., used
additional information, clarification or support, please refer to SAP
under license for technology invented and implemented by Netscape.
Consulting.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP
Any software coding and/or code lines / strings (“Code”) included in this
BusinessObjects Explorer, StreamWork, and other SAP products and
documentation are only examples and are not intended to be used in a
services mentioned herein as well as their respective logos are
productive system environment. The Code is only intended better explain
trademarks or registered trademarks of SAP AG in Germany and other
and visualize the syntax and phrasing rules of certain coding. SAP does
countries.
not warrant the correctness and completeness of the Code given herein,
Business Objects and the Business Objects logo, BusinessObjects,
and SAP shall not be liable for errors or damages caused by the usage of
Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other
the Code, except if such damages were caused by SAP intentionally or
Business Objects products and services mentioned herein as well as their
grossly negligent.
respective logos are trademarks or registered trademarks of Business
Disclaimer
Objects Software Ltd. Business Objects is an SAP company.
Some components of this product are based on Java™. Any code change
Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere,
in these components may cause unpredictable and severe malfunctions
and other Sybase products and services mentioned herein as well as their
and is therefore expressively prohibited, as is any decompilation of these
respective logos are trademarks or registered trademarks of Sybase, Inc.
components.
Sybase is an SAP company.
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
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
Table of Contents
1.
Business Scenario ............................................................................................................ 1
2.
Background Information.................................................................................................. 2
2.1
2.2
2.3
VirtualProvider based on DTP......................................................................................... 2
VirtualProvider with Function Module ............................................................................ 3
Considerations.................................................................................................................. 5
3.
Prerequisites ................................................................................................................... 6
4.
Scenarios for VirtualProvider ...........................................................................................7
4.1
4.2
4.3
4.4
5.
Data loading for HANA Views via Operational Data Providers ........................................ 14
5.1
5.2
6.
Create DBCON and Source System ............................................................................... 7
Scenario: VirtualProvider based on DTP ....................................................................... 7
4.2.1 Create Logical system for the DBCON entry ................................................... 7
4.2.2 Create DB Connect Source System .................................................................. 8
4.2.3 Create VirtualProvider based on DTP ............................................................... 8
4.2.4 Create DataSource for the HANA DB Connect source system...................... 8
4.2.5 Create Transformation and DTP for the VirtualProvider .............................. 10
Scenario: VirtualProvider with Function Module ........................................................ 10
4.3.1 Create Mapping Tables..................................................................................... 10
4.3.2 Create user-defined Function Module .............................................................12
4.3.3 Create VirtualProvider with FM ....................................................................... 13
Create Query................................................................................................................... 14
Create ODP Source system........................................................................................... 14
Create ODP DataSource on SAP HANA View...............................................................15
Appendix ........................................................................................................................ 18
How to consume Models in SAP NetWeaver BW from remote HANA instances
1.
Business Scenario
An important part of the whole BW-HANA interoperability is the option to create scenarios where
data owned and modeled within BW and data owned and modeled within native HANA data marts
interact. This is what we call mixed scenarios. The interaction can happen in both directions, from
HANA to BW and vice-versa, and there are options to physically move the data or to virtually
expose the data (see: http://www.saphana.com/docs/DOC-3151).
Leveraging the integration between BW and HANA is well described in the case when BW is actually
running on the SAP HANA database (SAP BW powered by SAP HANA). For details visit the online
documentation Virtual Data Mart Layer (TransientProviders and VirtualProviders on HANA model),
or the SAP HANA Developer Guide (section 7.6 for importing BW objects).
The following solutions are available for consuming data in BW from a remote HANA instance
(HANA DataMart / accelerator, Suite-on-HANA, BW-on-HANA, etc.):
Load the data into BW via DB Connect or Operational Data Provisioning (ODP), or
Access the data via VirtualProvider (direct access without loading data into BW)
In this paper we mainly focus on the use case when BW consumes the data/models of a remote
SAP HANA system without loading the data into BW (modeling options for direct access):
BW and HANA are two separate systems
It is not required for BW to run on HANA, could be any BW 7.x release with any DB
SAP HANA is typically a DataMart scenario with no ABAP stack (standalone/native HANA)
Consume the HANA data and models within BW via VirtualProvider
The data is stored and modeled in the remote HANA system and not loaded to BW
HANA models can be Analytic, Calculation or Attribute view.
The two solutions we will discuss in this paper are:
...
1. VirtualProvider based on Data Transfer Process (DTP)
2. VirtualProvider with Function Module
For general information please visit the online documentation: Modeling Direct Data Access (BW
VirtualProvider scenarios)
Recommendation
While BW on HANA is not required for the scenarios discussed in this paper, BW on
HANA offers many advantages and capabilities within the Real-time Data Platform
Real-time Data Warehousing with SAP LT Replication Server (SLT) for SAP NetWeaver
BW
Analytics Powered by SAP HANA and SAP NetWeaver BW
At the end we will briefly discuss the Operational Data Providers to load data to BW from HANA via
HANA modeling views.
June 2013
1
How to consume Models in SAP NetWeaver BW from remote HANA instances
2.
Background Information
Both VirtualProvider scenarios require the secondary DB connection to the “remote” SAP HANA
database. In order to use DB Connect the Database Shared Library (DBSL) - must be installed for
the corresponding source database management system on the BW application server (visit the
corresponding online documentation: Transferring Data Using DB Connect and Installing the
Database Shared Library (DBSL) )
For specifics and prerequisites visit SAP Note 1597627 - SAP HANA connection
The general DB Connect recommendations, prerequisites and restrictions apply as well:
Transferring Data Using DB Connect
CAUTION
Using HANA models (views) be aware of the definition of those models and the output
they provide – the design of the model (join definitions, filters, restrictions, calculated
measures / attributes / columns, variables, input parameters, etc. ) influence the
output and the performance. Please consider the recommendations and best
practices regarding modeling in SAP HANA.
2.1
VirtualProvider based on DTP
The solution is based on the standard DB Connect architecture and requires a DB Connect source
system to the remote HANA and a data source based on a table stored in HANA or a Calculation
view from the HANA system.
Important
HANA Analytic views are not supported for DB Connect – the standard DB
Connect data source does not assemble the required ‘GROUP BY’ for the SQL
statement, therefore HANA can’t process the SELECT statement.
The DB connect user needs to have appropriate access and privileges in HANA in
order to read the metadata and to process SQL
The following restrictions apply for the technical name of the HANA source
tables/views:
Only upper case letters, numbers, “_” (underscore) and “/” (slash)
Total length must not exceed 30 characters
SAP HANA does allow both upper/lower case letters in the technical
names of packages and models – these are not available for DB Connect
data source (e.g. package/CALC_VIEW is not possible, should be
PACKAGE/CALC_VIEW).
For details please visit the online documentation: Creating VirtualProviders Based on DTP
June 2013
2
How to consume Models in SAP NetWeaver BW from remote HANA instances
Note
DB Connect DataSource can be used for loading the data into BW – this option will not
be discussed in this paper.
2.2
VirtualProvider with Function Module
This solution offers more flexibility, but also requires a higher implementation effort. For general
information please visit the online documentation: Creating VirtualProviders with Function Modules
Note
The solution does NOT replace best practices for BI data modeling and provides
limited means for performance tuning (DB indexes). If you want to report on high data
volumes, the data should be loaded into standard InfoCubes or DataStore objects.
This solution is based on the function module RSDRI_VPROV_READ_TEMPLATE with the following
interface:
The documentation of the function module can be found in the BW system itself (SE24).
The general description of the interfaces can be found here: Description of the Interfaces
The user-defined function module leverages the ADBC (ABAP Database Connectivity) API
framework for HANA native SQL using the CL_SQL* service classes. In this example we do not use
the class CL_RSDRV_EXTERNAL_IPROV_SRV (it contains services for implementing a local
InfoProvider without SID support that is based on a database table) - see ABAP/HANA Connectivity
via Secondary Database Connection - ADBC is preferred over other options because of its flexibility
(e.g. package size) and error handling.
When the user-defined function module is called, the BW Data Manager passes down the required
parameters (list of characteristics, key figures, selections and restrictions).
June 2013
3
How to consume Models in SAP NetWeaver BW from remote HANA instances
The basic program logic:
assemble the SQL statement specifically required for HANA
create the field list for the SELECT from the I_TH_SFC
create the GROUP BY list from I_TH_SFC
create the aggregation fields from I_TH_SFK
create the WHERE clause from I_T_RANGE
assign DB Connection, e.g. cl_sql_connection=>get_connection()
create SQL statement, e.g. cl_sql_connection=>create_statement()
execute SQL statement, e.g. cl_sql_statement=>execute_query()
process the result set and pass the data to the interface (e_t_data)
pass the potential messages to e_t_msg
Two user-defined configuration tables need to be maintained in order to translate between BW and
HANA (via SM30).
Mapping: VirtualProvider to HANA Model/Table
Enter the HANA schema and model (or table) – please note that HANA model views are
stored under the _SYS_BIC schema. Select the View Type. For HANA tables leave the View
Type field blank.
June 2013
4
How to consume Models in SAP NetWeaver BW from remote HANA instances
Mapping: InfoObjects to HANA Model Fields
Maintain the mapping – the table allows global and InfoProvider specific mapping for each
InfoObject. In the function module the InfoProvider specific mapping overrides the generic
mapping. The table also allows entering constant value that can be used in case the return
value from HANA is blank (e.g. the table/model does not have the corresponding field.
2.3
Considerations
Both approaches enable the BW system to consume information models, tables from a remote SAP
HANA instance. The following considerations help to choose the right solution:
Performance: both solution is based on the DB Connect architecture, therefore offers
comparable performance. The performance depends on the complexity of the HANA model
(see best practices for HANA modeling).
The DB Connect Datasource and DTP allow accessing raw tables or calculation views only – no
GROUP BY is generated when the DB Connect generates the SQL statement, therefore no
Analytic views can be leveraged
Tip
Consider creating Calculation views on top of Analytic Views
VirtualProvider with function module requires more development effort and the maintenance of
the mappings, but provides a flexible solution with no restrictions of accessing the different
HANA information models, stored procedures.
June 2013
5
How to consume Models in SAP NetWeaver BW from remote HANA instances
VirtualProvider
Why would you choose it?
What to consider against it?
Based on DTP (DB Connect
datasource to HANA)
Simple, standard
development effort
Analytic views, stored
procedures not supported
Function Module
No restriction on
consumable HANA model
types
Development effort
Maintain mappings
Important
None of the solution is automatically synchronized with changes in HANA – changes
to HANA models need to be adopted manually in BW.
3.
Prerequisites
Software
SAP NetWeaver Business Warehouse 7.x (on any DB), latest SP recommended
SAP HANA 1.0, latest revision recommended
SAP HANA Client is installed on each ABAP Application Server. ABAP Application Server
Operating System must support the HANA Client (check Platform Availability Matrix for
supported operating systems).
SAP HANA DBSL is installed (this is the Database specific library which is part of the ABAP
Kernel)
The SAP HANA DBSL is only available for the ABAP Kernel 7.20 Kernel 7.20 is already the
kernel for NetWeaver 7.02, 7.03, 7.20, 7.30 and 7.31
Kernel 7.20 is backward compatible and can also be applied to NetWeaver 7.00, 7.01,
7.10, and 7.11
Your ABAP system must be Unicode or Single Code Page 1100 (Latin 1/ISO-8850-1) -See
SAP Note 1700052 for non-Unicode Support instructions
Relevant SAP Notes
SAP Note 1597627 - SAP HANA connection
Additional background/starting documentation (also provide a link)
Modeling Direct Data Access (BW VirtualProvider scenarios)
Required/recommended expertise or prior knowledge
SAP BW modeling with VirtualProviders
SAP HANA Modeling
June 2013
6
How to consume Models in SAP NetWeaver BW from remote HANA instances
4.
Scenarios for VirtualProvider
This section provides a high-level overview about the steps that need to be performed – the details
of how to create BW objects won’t be discussed here (see the online documentation for details).
As described above there are two options for direct access:
VirtualProvider based on Data Transfer Process (DTP)
VirtualProvider with Function Module
Both scenarios require the secondary database connection to the remote HANA system.
4.1
Create DBCON and Source System
Create/maintain the required DB connection parameters.
...
Transaction SM30 DBCON
Enter the parameters for the HANA DB connection:
DBCON can also be maintained via transaction DBACOCKPIT.
4.2
Scenario: VirtualProvider based on DTP
4.2.1
Create Logical system for the DBCON entry
June 2013
7
How to consume Models in SAP NetWeaver BW from remote HANA instances
4.2.2
Create DB Connect Source System
Transaction RSA1
Modeling/Source Systems
DB Connect.
Select the logical system above and maintain the connection parameters.
4.2.3
Create VirtualProvider based on DTP
Transaction RSA1
Modeling
InfoProvider
From the context menu of the selected InfoArea choose Create VirtualProvider …
Select the appropriate options according to the scenario and proceed with the standard steps and
activate the VirtualProvider.
VirtualProvider based on DTP:
...
4.2.4
Create DataSource for the HANA DB Connect source system
1. Transaction RSA1 Modeling/DataSources
Select the HANA DB Connect source system and create a DataSource
Select the appropriate type:
e.g. for HANA Attribute view choose Master data type.
2. On the Extraction tab
a. Enter the schema name in the DB User field
Important
Do not enter DB user here but the schema of the table or view! Note that HANA views
are under the ‘_SYS_BIC’ schema!
b. Enter the name of the source table or view. You can use the search help
June 2013
8
How to consume Models in SAP NetWeaver BW from remote HANA instances
From the list select the table or view.
c. Make sure you allow the Direct Access
3. On the Proposal tab
Review the fields and make your selection.
4. On the Fields tab
Finalize your settings and activate the DataSource.
June 2013
9
How to consume Models in SAP NetWeaver BW from remote HANA instances
5. Process to the Preview tab
Verify the DataSource by reading the data.
Tip
Keep the number of records low – this is not a performance test!
4.2.5
Create Transformation and DTP for the VirtualProvider
For the DTP scenario follow the standard steps: Creating VirtualProviders Based on Data Transfer
Processes :
...
1. Create the required Transformation
2. Create the DTP
3. Activate the Direct access
4.3
Scenario: VirtualProvider with Function Module
4.3.1
Create Mapping Tables
...
1. Create Mapping tables
Create the two mapping tables with the fields below – transaction SE11
June 2013
10
How to consume Models in SAP NetWeaver BW from remote HANA instances
Mapping table between VirtualProvider and HANA model or table
Mapping table between InfoObjects and fields of the HANA model or table
Settings for both tables:
In the Technical settings enter USER for data class for both tables:
June 2013
11
How to consume Models in SAP NetWeaver BW from remote HANA instances
Extras
Enhancement Category = Can be enhanced (deep)
2. Create Table Maintenance Dialog
Create a table maintenance dialog – transaction SE11:
Utilities Table Maintenance Generator.
4.3.2
Create user-defined Function Module
Implement the user-defined code (SE37) – you can take the code sample and create the function
module ( Appendix - Function Module sample ).
The sample code provide a general read of HANA-models (the type of the HANA model is not
considered (Calculation view vs. Analytic view, or raw table).
He program executes the SQL statement and fetches the result set from HANA in one step.
June 2013
12
How to consume Models in SAP NetWeaver BW from remote HANA instances
It is possible to extend the code to execute the COUNT to receive the number of records for the
SQL statement, and then build the data fetch according to the package size.
It is also possible to use the ADBC framework to receive result set from stored procedures in SAP
HANA.
4.3.3
Create VirtualProvider with FM
Transaction RSA1
Modeling
InfoProvider
From the context menu of the selected InfoArea choose Create VirtualProvider …
Select the appropriate options according to the scenario and proceed with the standard steps and
activate the VirtualProvider.
VirtualProvider with FM:
Select Details and create the VirtualProvider with the options below. Enter the user-defined
function module:
Proceed with the standard steps and activate the VirtualProvider
June 2013
13
How to consume Models in SAP NetWeaver BW from remote HANA instances
4.4
Create Query
Create BW query on top of the VirtualProvider and test the results. You can validate the results
against the source models/tables using e.g. SQL in the HANA Studio.
5.
Data loading for HANA Views via Operational
Data Providers
With the Operational Data Provisioning it is possible to load data into BW from remote HANA
system.
For details see the online documentations:
Transferring Data Using Operational Data Provisioning
Notes about transferring data from SAP HANA using ODP – note the specifics about the
restrictions regarding HANA models, naming conventions, length restrictions in technical names.
Note
Transferring data from the SAP HANA database with ODP is not supported for the
following:
Hierarchies in attribute views
VirtualProviders based on the data transfer process
Real-time data acquisition
Prerequisite:
You can use Operational Data Provisioning (ODP) to connect the SAP HANA database of an ABAP
system as the source system to the BW system. Communication is performed using RFC. With the
ODP context for SAP HANA (HANA), analytic views, calculation views and associated attribute
views are provided for replication into BW. This allows you to perform calculations in the SAP HANA
database on the views, before they are loaded into BW. These calculations could be currency
translations and restricted key figures or key figures calculated before aggregation for example, or
joins and unions.
Recommendation
For SAP HANA systems without ABAP stack use DB Connect for loading data into BW.
5.1
Create ODP Source system
...
1. Create RFC connection with the ABAP system running on SAP HANA.
2. RSA1
June 2013
Source Systems: create ODP source system from the ODP folder
14
How to consume Models in SAP NetWeaver BW from remote HANA instances
Choose RFC for communication channel:
Select HANA Context:
5.2
Create ODP DataSource on SAP HANA View
...
1. Create ODP DataSource on the ODP source system
RSA1 DataSources – choose the ODP source system
June 2013
15
How to consume Models in SAP NetWeaver BW from remote HANA instances
2. Create the DataSource by selecting the HANA model
3. Accept the proposed fields and activate the DataSource
June 2013
16
How to consume Models in SAP NetWeaver BW from remote HANA instances
4. Validate the data source
5. Create InfoPackage and test the data load to PSA
You can build dataflow to load the data into InfoProviders in BW.
A setting in the data transfer process allows you to load the data into the InfoProvider directly
without the need to load it into the PSA via an InfoPackage first: Loading Data Directly into an
InfoProvider from the ODP Source System.
June 2013
17
How to consume Models in SAP NetWeaver BW from remote HANA instances
6.
Appendix
Appendix A – Function Module
Function Module: Z_HANA_VPROV_READ
FUNCTION Z_HANA_VPROV_READ.
*"---------------------------------------------------------------------*"*"Local Interface:
*"
IMPORTING
*"
REFERENCE(I_INFOPROV) TYPE
*"
REFERENCE(I_TH_SFC) TYPE
RSDRI_TH_SFC
*"
REFERENCE(I_TH_SFK) TYPE
RSDRI_TH_SFK
*"
REFERENCE(I_T_RANGE) TYPE
*"
REFERENCE(I_TX_RANGETAB) TYPE
*"
REFERENCE(I_TSX_HIER) TYPE
*"
REFERENCE(I_FIRST_CALL) TYPE
*"
REFERENCE(I_PACKAGESIZE) TYPE
*"
REFERENCE(I_KEYDATE) TYPE
RRSRDATE DEFAULT SY-DATUM
*"
REFERENCE(I_MAXROWS) TYPE
I DEFAULT 2147483647
*"
REFERENCE(I_USE_AGGREGATION) TYPE
*"
REFERENCE(I_SHOW_STATEMENT) TYPE
*"
RSINFOPROV
RSDRI_T_RANGE OPTIONAL
RS_BOOL OPTIONAL
I DEFAULT 20000000
RS_BOOL DEFAULT RS_C_TRUE
RS_BOOL DEFAULT RS_C_FALSE
EXPORTING
*"
REFERENCE(E_T_DATA) TYPE
*"
REFERENCE(E_END_OF_DATA) TYPE
*"
REFERENCE(E_T_MSG) TYPE
*"
RSDRI_TX_RANGETAB OPTIONAL
RSDRI_TSX_HIER OPTIONAL
STANDARD TABLE
RS_BOOL
RS_T_MSG
EXCEPTIONS
*"
REMOTE_READ_FAILED
*"
X_MESSAGE
*"----------------------------------------------------------------------
* This is a template for a local virtual infoprovider without SID support RSDRI_VPROV_READ_TEMPLATE
* See the template function module documentation
DEFINE check_subrc.
if sy-subrc <> 0 or l_subrc <> 0.
message e301(dbman) with &1 &2 &3 &4 into l_message.
move-corresponding syst to l_s_msg.
append l_s_msg to e_t_msg.
raise remote_read_failed.
endif.
END-OF-DEFINITION. "check_subrc
* Set the DB Connect name for the HANA system
" alternatively could be an input in the mapping table in case there are multiple HANA DBconnections
CONSTANTS:
HDB_CON
TYPE dbcon_name VALUE 'HANAWR1'.
TYPES:
June 2013
18
How to consume Models in SAP NetWeaver BW from remote HANA instances
BEGIN OF y_s_mapping,
iobjnm
TYPE rsiobjnm,
hananm
TYPE rshdbattrnm,
chaconst
TYPE rschaconst,
END OF y_s_mapping,
y_th_mapping
TYPE HASHED TABLE OF y_s_mapping WITH UNIQUE KEY iobjnm.
TYPES:
BEGIN OF t_mapping,
iobjnm
TYPE rsiobjnm,
alias
TYPE rsalias,
hananm
TYPE rshdbattrnm,
END OF t_mapping.
STATICS:
s_th_mapping
TYPE y_th_mapping.
*-- ADBC Classes
DATA:
l_hdb_con
TYPE REF TO cl_sql_connection,
l_hdb_sql
TYPE REF TO cl_sql_statement,
l_hdb_rs
TYPE REF TO cl_sql_result_set,
l_hdb_md
TYPE REF TO cl_sql_metadata,
l_hdb_err
TYPE REF TO cx_sql_exception.
DATA:
l_s_sfc
TYPE rsdri_s_sfc,
l_s_sfk
TYPE rsdri_s_sfk,
l_s_range
TYPE rsdri_s_range,
l_t_range
TYPE rsdri_t_range,
l_t_range_hdb
TYPE rsdri_t_range,
l_message
TYPE string,
l_s_msg
TYPE rs_s_msg,
l_s_mapping
TYPE y_s_mapping,
l_t_model
TYPE STANDARD TABLE OF ZVPHANA_MODEL,
l_s_model
LIKE LINE OF l_t_model,
l_sql
TYPE string,
l_model
TYPE string,
l_schema
TYPE string,
l_from
TYPE string,
l_fieldlist
TYPE string,
l_aggregation
TYPE string,
l_group_by
TYPE string,
l_quoted_fieldnm
TYPE string,
l_where
TYPE string,
l_subrc
TYPE sy-subrc,
lt_mapping
TYPE STANDARD TABLE OF t_mapping,
ls_mapping
TYPE t_mapping,
l_row_cnt
TYPE i,
l_size
TYPE i.
June 2013
19
How to consume Models in SAP NetWeaver BW from remote HANA instances
*-- WHERE clause generation
DATA:
acc_gen_cp
TYPE rsmds_boolean,
l_r_universe
TYPE REF TO cl_rsmds_universe,
l_r_renderer
TYPE REF TO if_rsmds_condition_renderer,
l_r_set
TYPE REF TO cl_rsmds_set,
incl_null
TYPE rsmds_boolean,
rx_message
TYPE REF TO cx_rsmds_message,
wa_where
TYPE lvc_s_fcat,
it_where
TYPE lvc_t_fcat,
dyn_t_where
TYPE REF TO data.
*-- HANA Result set receiving area
DATA:
dyn_l_result
TYPE REF TO data,
hana_fields
TYPE adbc_rs_metadata_descr_tab,
hana_field
TYPE adbc_rs_metadata_descr,
hana_rs_md
TYPE REF TO data,
ls_hana
TYPE REF TO CL_ABAP_DATADESCR,
lt_hana
TYPE REF TO CL_ABAP_TABLEDESCR,
field1
TYPE string,
field2
TYPE string,
it_hana
TYPE REF TO data,
e_s_data
TYPE REF TO data.
FIELD-SYMBOLS:
<fs_where>
TYPE STANDARD TABLE,
<fs_t_result>
TYPE STANDARD TABLE,
<fs_l_result>,
<l_s_data>,
<e_s_data>,
<l_t_data>
TYPE STANDARD TABLE,
<l_s_fields>,
<l_s_mapping>,
<l_s_sfc>
TYPE rsdri_s_sfc,
<l_s_sfk>
TYPE rsdri_s_sfk,
<l_s_range>
TYPE rsdri_s_range,
<l_t_range>
TYPE rsdri_t_range,
<hana_field>
TYPE adbc_rs_metadata_descr.
**********************************************************************************************
**
IF i_first_call = rs_c_true.
*--------------------------------------------------------------------------------------------*
*-- Read Mapping tables
--*
*--------------------------------------------------------------------------------------------*
*-- HANA Model Name from table ZVPHANA_MODELtable ZVPHANA_MODEL
June 2013
20
How to consume Models in SAP NetWeaver BW from remote HANA instances
SELECT * FROM ZVPHANA_MODEL INTO CORRESPONDING FIELDS OF l_s_model WHERE infoprov EQ i_inf
oprov.
check_subrc 'No HANA Model for' i_infoprov 'in the mapping table' 'ZVPHANA_MODEL'.
l_schema = l_s_model-hdbschema.
l_model =
l_s_model-hdbmodnm.
CONCATENATE 'FROM "' l_schema '"."' l_model '"' INTO l_from.
ENDSELECT.
*-- InfoObject <-> Field of HANA Model from table ZVPHANA_FIELDS
**
Read "global" mapping first (not InfoProvider specific)
SELECT * FROM ZVPHANA_FIELDS INTO CORRESPONDING FIELDS OF TABLE s_th_mapping
WHERE infoprov = space.
**
Read InfoProvider specific mappings and overwrite "global"
SELECT * FROM ZVPHANA_FIELDS INTO CORRESPONDING FIELDS OF l_s_mapping
WHERE infoprov = i_infoprov.
DELETE s_th_mapping WHERE ( iobjnm = l_s_mapping-iobjnm ). "AND hananm = l_s_mapping-
hananm ).
INSERT l_s_mapping INTO TABLE s_th_mapping.
ENDSELECT.
*--------------------------------------------------------------------------------------------*
*-- Build SELECT List (Characteristics) & GROUP BY (All CHAs included in GROUP BY)
--*
*--------------------------------------------------------------------------------------------*
LOOP AT i_th_sfc ASSIGNING <l_s_sfc>.
READ TABLE s_th_mapping INTO l_s_mapping WITH TABLE KEY iobjnm = <l_s_sfc>-chanm.
CHECK sy-subrc EQ 0.
CONCATENATE '"' l_s_mapping-hananm '"' INTO l_quoted_fieldnm.
*-- begin -- Maintain Field Mappings
CLEAR: ls_mapping.
MOVE: <l_s_sfc>-CHANM
TO ls_mapping-iobjnm,
<l_s_sfc>-CHAALIAS
TO ls_mapping-alias,
l_s_mapping-HANANM
TO ls_mapping-hananm.
APPEND ls_mapping TO lt_mapping.
*-- end --
Maintain Field Mappings
IF l_fieldlist IS INITIAL.
l_fieldlist = l_quoted_fieldnm.
CONCATENATE 'GROUP BY' l_quoted_fieldnm INTO l_group_by SEPARATED BY space.
" Group B
y
ELSE.
CONCATENATE l_fieldlist ',' l_quoted_fieldnm INTO l_fieldlist.
" Field List
CONCATENATE l_group_by ',' l_quoted_fieldnm INTO l_group_by.
" Group By
ENDIF.
check_subrc 'No HANA Field for' <l_s_sfc>-chanm 'in the mapping table' 'ZVPHANA_FIELDS'.
ENDLOOP.
June 2013
21
How to consume Models in SAP NetWeaver BW from remote HANA instances
*--------------------------------------------------------------------------------------------*
*-- Build SELECT List (Key Figures + Aggregation Function)
*--------------------------------------------------------------------------------------------*
LOOP AT i_th_sfk ASSIGNING <l_s_sfk>.
READ TABLE s_th_mapping INTO l_s_mapping WITH TABLE KEY iobjnm = <l_s_sfk>-kyfnm.
IF sy-subrc EQ 0.
IF l_s_mapping-hananm IS INITIAL.
l_subrc = 4.
ENDIF.
*-- begin -- Maintain Field Mappings
CLEAR ls_mapping.
MOVE: <l_s_sfk>-KYFNM
TO ls_mapping-iobjnm,
<l_s_sfk>-KYFALIAS
TO ls_mapping-alias,
l_s_mapping-HANANM
TO ls_mapping-hananm.
APPEND ls_mapping TO lt_mapping.
*-- end --
Maintain Field Mappings
CONCATENATE '"' l_s_mapping-hananm '"' INTO l_quoted_fieldnm.
IF l_aggregation IS INITIAL.
CONCATENATE ',SUM(' l_quoted_fieldnm ')' INTO l_aggregation.
" Field List + Agg
regate
ELSE.
CONCATENATE l_aggregation ',' 'SUM(' l_quoted_fieldnm ')' INTO l_aggregation.
" Fie
ld List + Aggregate
ENDIF.
ENDIF.
check_subrc 'No HANA Field for' <l_s_sfk>-kyfnm 'in the mapping table' 'ZVPHANA_FIELDS'.
ENDLOOP.
*--------------------------------------------------------------------------------------------*
*-- Build WHERE Clause from I_T_RANGE
--*
*--------------------------------------------------------------------------------------------*
IF i_t_range IS NOT INITIAL.
"If no selection no need for WHERE Clause
* clean-up RANGE
l_t_range = i_t_range.
SORT l_t_range BY chanm sign DESCENDING low high.
DELETE ADJACENT DUPLICATES FROM l_t_range.
* Replace the IObj name with HANA name
LOOP AT l_t_range INTO l_s_range.
"ASSIGNING <l_s_range>.
AT NEW CHANM.
READ TABLE s_th_mapping INTO l_s_mapping WITH KEY iobjnm = l_s_range-chanm.
IF sy-subrc EQ 0.
"build field catalog for dynamic table
wa_where-fieldname = l_s_mapping-hananm.
wa_where-datatype
= 'CHAR'.
wa_where-OUTPUTLEN = '60'.
June 2013
22
How to consume Models in SAP NetWeaver BW from remote HANA instances
APPEND wa_where TO it_where.
ENDIF.
ENDAT.
l_s_range-chanm = l_s_mapping-hananm.
APPEND l_s_range TO l_t_range_hdb.
ENDLOOP.
**-- Create dynamic internal table and assign to Field-Symbol (WHERE)
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_where
IMPORTING
ep_table
= dyn_t_where.
ASSIGN dyn_t_where->* TO <fs_where>.
**-- Create WHERE Clause dynamically, per L_T_RANGE_HDB
l_r_universe
= cl_rsmds_abap_universe=>create_by_data( <fs_where> ).
TRY .
l_r_set = l_r_universe->create_set_from_ranges( i_t_ranges = l_t_range_hdb[]
i_fieldname_dimension = 'CHANM' ).
ENDTRY.
l_r_renderer
= cl_rsmds_native_sql_renderer=>get_condition_renderer( ).
l_where = l_r_set->to_string( i_r_renderer = l_r_renderer
i_use_alias
= rsmds_c_boolean-true ).
ENDIF.
**-- Complete WHERE Clause
IF l_where IS NOT INITIAL.
CONCATENATE 'WHERE' l_where INTO l_where SEPARATED BY space.
ENDIF.
*--------------------------------------------------------------------------------------------*
*-- Build SQL Statement
*--------------------------------------------------------------------------------------------*
CONCATENATE 'SELECT' ' ' l_fieldlist l_aggregation ' ' l_from ' ' l_where ' ' l_group_by I
NTO l_sql.
*--------------------------------------------------------------------------------------------*
*-- Create/Execute QUERY
*--------------------------------------------------------------------------------------------*
TRY .
*-- Open connection to HANA DB, SQL statement engine, HANA metadata
l_hdb_con = cl_sql_connection=>get_connection( con_name = 'HANAWR1' ).
l_hdb_sql = l_hdb_con->create_statement( ).
l_hdb_md
June 2013
= l_hdb_con->get_metadata( ).
23
How to consume Models in SAP NetWeaver BW from remote HANA instances
CATCH cx_sql_exception INTO l_hdb_err.
IF l_hdb_con IS NOT INITIAL.
TRY .
l_hdb_con->close( ).
CATCH cx_sql_exception INTO l_hdb_err.
PERFORM handle_sql_exception USING l_hdb_err E_T_MSG E_END_OF_DATA.
ENDTRY.
ENDIF.
ENDTRY.
TRY.
l_hdb_rs = l_hdb_sql->execute_query( statement = l_sql ).
CATCH cx_sql_exception INTO l_hdb_err.
PERFORM handle_sql_exception USING l_hdb_err E_T_MSG E_END_OF_DATA.
ENDTRY.
ENDIF.
"i_first_call = rs_c_true
*--------------------------------------------------------------------------------------------*
*-- Get the result data set back into ABAP internal table
*--------------------------------------------------------------------------------------------*
CHECK l_hdb_rs IS BOUND.
**-- Build receiving area from HANA metadata
hana_fields = l_hdb_rs->get_metadata( ).
"returns aggregation function!
LOOP AT hana_fields ASSIGNING <hana_field>.
field1 = <hana_field>-column_name.
IF field1+0(3) = 'SUM'.
SHIFT field1 LEFT DELETING LEADING 'SUM('.
SHIFT field1 RIGHT DELETING TRAILING ')'.
SHIFT field1 LEFT DELETING LEADING space.
<hana_field>-column_name = field1.
MODIFY hana_fields INDEX sy-tabix FROM <hana_field> TRANSPORTING column_name.
ENDIF.
ENDLOOP.
hana_rs_md = l_hdb_rs->get_struct_ref( hana_fields ).
ls_hana ?= cl_abap_structdescr=>describe_by_data_ref( hana_rs_md ).
lt_hana = cl_abap_tabledescr=>create( ls_hana ).
CREATE DATA it_hana TYPE HANDLE lt_hana.
l_hdb_rs->set_param_table( it_hana ).
ASSIGN it_hana->* TO <fs_t_result>.
* Create dynamic work area and assign to Field Symbol
CREATE DATA dyn_l_result LIKE LINE OF <fs_t_result>.
June 2013
24
How to consume Models in SAP NetWeaver BW from remote HANA instances
ASSIGN dyn_l_result->* TO <fs_l_result>.
** Read data in one step
l_row_cnt = l_hdb_rs->next_package( i_maxrows ).
E_END_OF_DATA = rs_c_true.
l_hdb_rs->close( ).
DATA: struct_descr
TYPE REF TO cl_abap_structdescr.
DATA
TYPE REF TO cl_abap_structdescr.
str_hana
FIELD-SYMBOLS: <components> LIKE LINE OF cl_abap_structdescr=>components,
<iobj_alias> TYPE any,
<hana_name>
TYPE any,
<comp1>
TYPE any,
<comp2>
TYPE any.
* Create dynamic work area and assign to Field Symbol
CREATE DATA e_s_data LIKE LINE OF e_t_data.
ASSIGN e_s_data->* TO <e_s_data>.
*--------------------------------------------------------------------------------------------*
*-- Map HANA result set to OLAP and return E_T_DATA
*--------------------------------------------------------------------------------------------*
TRY.
str_hana ?= cl_abap_typedescr=>describe_by_data( <fs_l_result> ).
CATCH cx_sy_move_cast_error.
RETURN.
ENDTRY.
LOOP AT <fs_t_result> ASSIGNING <fs_l_result>.
LOOP AT str_hana->components ASSIGNING <components>.
READ TABLE lt_mapping INTO ls_mapping WITH KEY hananm = <components>-name.
ASSIGN COMPONENT ls_mapping-alias OF STRUCTURE <e_s_data> to <iobj_alias>.
IF sy-subrc EQ 0.
ASSIGN COMPONENT sy-tabix OF STRUCTURE <fs_l_result> to <hana_name>.
<iobj_alias> = <hana_name>.
ENDIF.
ENDLOOP.
APPEND <e_s_data> to e_t_data.
ENDLOOP.
ENDFUNCTION.
*---------------------------------------------------------------------*
*
FORM handle_sql_exception
*---------------------------------------------------------------------*
*
Writes the SQL error code and error message to the output list.
*---------------------------------------------------------------------*
*
--> PX_SQLERR
the caught SQL exception
*---------------------------------------------------------------------*
June 2013
25
How to consume Models in SAP NetWeaver BW from remote HANA instances
FORM handle_sql_exception
USING px_sqlerr TYPE REF TO cx_sql_exception
E_MSG TYPE RS_T_MSG
E_END TYPE RS_BOOL.
DATA: lv_olen
ls_msg
TYPE i,
TYPE RS_S_MSG,
lv_msgtext TYPE CHAR255.
MOVE: px_sqlerr->sql_message TO lv_msgtext.
CONCATENATE: 'SQL Error: ' lv_msgtext INTO lv_msgtext RESPECTING BLANKS.
*-- Maximum Number of Message Variables - 4
DO 4 TIMES.
CASE sy-index.
WHEN 1.
MOVE: lv_msgtext
TO ls_msg-msgv1. " Length of Message Variable = 53 characters
WHEN 2.
MOVE: lv_msgtext+53
TO ls_msg-msgv2.
" Length of Message Variable = 53 characters
WHEN 3.
MOVE: lv_msgtext+106 TO ls_msg-msgv3. " Length of Message Variable = 53 characters
WHEN 4.
MOVE: lv_msgtext+159 TO ls_msg-msgv4. " Length of Message Variable = 53 characters
ENDCASE.
ENDDO.
*-Currently using Message Class SY, Message Number 499 as placeholder.
Will require 4 empty me
ssage variables, as we will populate dynamically, per error message
MOVE: 'E'
TO ls_msg-msgty, " Error Message
'499'
TO ls_msg-msgno, " <-- Create Custom Message Number
'SY'
TO ls_msg-MSGID. " <-- Create Custom Message Class
APPEND ls_msg TO E_MSG.
E_END = 'X'.
ENDFORM.
June 2013
"HANDLE_SQL_EXCEPTION
26
www.sap.com/contactsap
www.sdn.sap.com/irj/sdn/howtoguides
Download