SQL2005 NET Data Provider for MySAP Business Suite

42
Microsoft .NET Data Provider for mySAP™ Business Suite with SQL Server Technical Article Writers: Amit Goyal, Christoph Schuler, Anjan Das Technical Reviewers: Nick Gattucio, Madhu Vadlapudi, Oleg Ovanesyan, Donald Farmer Published: November 7, 2005 Updated: November 7, 2005 Applies To: SQL Server 2005

Transcript of SQL2005 NET Data Provider for MySAP Business Suite

Page 1: SQL2005 NET Data Provider for MySAP Business Suite

Microsoft .NET Data Provider for mySAP™ Business Suite

with

SQL Server Technical Article

Writers: Amit Goyal, Christoph Schuler, Anjan Das

Technical Reviewers: Nick Gattucio, Madhu Vadlapudi, Oleg Ovanesyan, Donald Farmer

Published: November 7, 2005

Updated: November 7, 2005

Applies To: SQL Server 2005

Page 2: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc

Summary: This whitepaper describes the usage scenarios for the .Net Data Provider for mySAP™ Business Suite with Microsoft SQL Server™ 2005 Integration Services and Reporting Services.

Page 3: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc

This is a preliminary document and may be changed substantially prior to final commercial release of the

software described herein.

The information contained in this document represents the current view of Microsoft Corporation on the

issues discussed as of the date of publication. Because Microsoft must respond to changing market

conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot

guarantee the accuracy of any information presented after the date of publication.

This White Paper is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS,

IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT.

Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights

under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval

system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or

otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property

rights covering subject matter in this document. Except as expressly provided in any written license

agreement from Microsoft, the furnishing of this document does not give you any license to these patents,

trademarks, copyrights, or other intellectual property.

2005 Microsoft Corporation. All rights reserved.

Microsoft and Microsoft SQL Server 2005 are either registered trademarks or trademarks of Microsoft

Corporation in the United States and/or other countries.

The names of actual companies and products mentioned herein may be the trademarks of their respective

owners.

Page 4: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc

Table of Contents

OVERVIEW...............................................................................................1

INTRODUCTION..............................................................................................................1BUSINESS SCENARIOS....................................................................................................1AVAILABILITY................................................................................................................2

ARCHITECTURE AND FEATURES.................................................................3

OVERVIEW...................................................................................................................3BAPI EXECUTION..........................................................................................................4QUERY TABLES.............................................................................................................5

USER EXPERIENCE....................................................................................7

SQL SERVER INTEGRATION SERVICES (SSIS).....................................................................7Import / Export Wizard Example:.......................................................................................7DataReader Source:.........................................................................................................13Date/Time values in the DataReader Source:..................................................................16Script Component (Data Flow):........................................................................................18SSIS Business Usage Example:........................................................................................20

SQL SERVER REPORTING SERVICES (SSRS)....................................................................29Prerequisite.....................................................................................................................29Report Design..................................................................................................................30

.NET CODE...............................................................................................................32

Summary...................................................................................................................33

Page 5: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 1

Overview

Introduction

SAP is the market leader in Enterprise Resource Planning (ERP) software and offers a comprehensive family of business solutions with the mySAP™ Business Suite. Enterprises have a need to access business data stored in their mySAP™ Business Suite, to extract, transform and deliver it to their business users for analysis and reporting.

Microsoft SQL Server™ 2005 includes managed providers for SQL Server, Oracle, and ODBC; additionally, partners and third parties are expected to deliver more ADO .NET providers. SQL Server Integration Services (SSIS) and SQL Server Reporting Services (SSRS) can readily work with any ADO .NET provider.

With the .Net Data Provider for mySAP Business Suite and SQL Server 2005, the user will be able to apply the rich features in SSIS and SSRS on data coming directly from their mySAP Business Suite.

Business Scenarios

Connectivity to a mySAP Business Suite solution is essential for a variety of business and technical needs, like the following:

Extraction of business data into a flat file, Excel spreadsheet, or database

Bulk load of business data into a data warehouse

Joining of data from various sources, including a mySAP Business Suite solution

Real-time data warehouse update with data from your mySAP Business Suite solution

Write-backs to the mySAP Business Suite solution via supported interfaces (BAPIs)

Ad-hoc reporting

Viewing real-time data through portal sites (for example Microsoft Sharepoint®)

Constructing semantic models and metadata for applications and objects from the mySAP Business Suite solution

Delta extractions and change replication

Page 6: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 2

The initial release of the .NET Provider for mySAP Business Suite (hereafter referred to as the Provider) focuses on the following scenarios:

Using SSIS DataReader Source to extract data from the mySAP Business Suite solution directly into the data flow task

Using SQL Server Import / Export Wizard to extract data

Using SSRS to create reports on top of tables, views or BAPIs

Using SSIS Script Task or Script Component and code against the provider

Writing a .NET program against the provider directly

Availability

The Provider is available for SQL Server 2005 Enterprise and Developer Edition users. It can be downloaded from the Microsoft SQL Server 2005 download site.

The Provider download contains the following files:

1. DataProviderSAP.msi

2. This whitepaper

3. Readme.htm (Please follow instructions contained in the Readme file)

The Provider can be installed to work with any SAP® solution, including SAP® R/3®, mySAP™ ERP or SAP® Business Information Warehouse, because it communicates with the underlying SAP® Web Application Server. Please refer to the Readme file for installation requirements and supported releases of your SAP solution.

The Provider is available in all languages that are available for SQL Server 2005.

Page 7: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 3

Architecture and Features

Overview

The Provider works like any other managed provider. It implements the ADO .NET classes such as DbConnection and DbCommand. Currently with SQL Server 2005, it is a partial implementation due to limitations on features supported against SAP. For example, the Provider cannot browse the SAP database schema, unlike the Oracle or SQL Server providers.

SAP client tools (for example SAPGUI) rely on LIBRFC32.DLL to communicate with SAP application servers. The provider also relies on this DLL to be installed on the SQL Server machine to communicate with the SAP server.

Machine B

Custom RFCs (ABAP Code)

Machine A

Integration Services

Reporting Services

.NET Code

SAP .NET Connector 2.0

.NET Provider for SAP

SQL Server

SAP Server

Librfc32.dll(from SAPGUI)

.NET Provider formySAP Business Suite

Page 8: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 4

Your SAP Administrator needs to install two custom function modules (RFCs) on the mySAP Business Suite that you wish to access. Instructions are provided in the Readme file.

BAPI Execution

A popular way to get data from the mySAP Business Suite is to execute a Remote Function Module (RFM) or one of the Business APIs (BAPIs). RFMs are remotely callable function modules that can be called from external systems using a protocol called Remote Function Call (RFC). BAPIs are a subset of RFMs that enable software vendors to integrate their software with the mySAP Business Suite.

The Provider supports calling a RFC from a SAP system. The syntax for this feature is:

EXEC <RFC_NAME> @Param1 <param 1 value> … @ParamN <param_ N_value>

Depending on the BAPI, one or several result sets will be returned via the data provider. Tools in SSIS and SSRS, such as the Import/Export wizard currently only support a single result set. The tool will default to the first result set returned via the data provider.

If multiple result sets are expected or the BAPI has OUT parameters of type Table, the user can write .NET code against the provider and manipulate the multiple result sets on their own.

EXAMPLES:

BAPI Execution:

• Exec BAPI_CREDITCARD_CHECKNUMBER

@CREDITCARD_TYPE='VISA',

@CREDITCARD_NUMBER='4346764526349895’

RFC Call:

• Exec SD_RFC_CUSTOMER_GET @NAME1 ='*'

Page 9: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 5

Query Tables

SAP developers and administrators typically know the underlying database schema of their SAP system. This schema is comprised of transparent, cluster, and pool tables, many of which cannot be accessed using traditional database tools like SQL Server Workbench.

The Provider supports querying single tables and views to extract data with appropriate filters applied. The following specifies the grammar for SELECT statements:

SELECT [TOP n] {ColumnName [AS alias] | TableName.* | *}[1,..n]

[INTO FILE filename [DELIMITED]]

FROM TableName [AS alias]

[WHERE predicates] [OPTION '{no_conversion}'] [;]

Where

n specifies the number of rows to be extracted from the table/view.

alias specifies an abbreviated name for the column or table/view.

TableName specifies the SAP Table or View name.

filename specifies the name of the file into which extracted data is written while using flat file mode.

predicates are conditions used to limit the set of extracted data.

OPTION ‘no conversion’ specifies that no ABAP conversion exits will be applied during data extraction

Please note that this is not ANSI SQL. This is a subset of SQL to make it easier for developers to query data in a query language they are already familiar with.

Page 10: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 6

A single result set is returned as a result of this command and tools like SSIS and SSRS can use the results just like the result of a traditional SQL query.

EXAMPLES:

Transparent Table:

• select * from KNA1

• select * from /BI0/MD_MATERIAL

Cluster Table

• select top 1000 AUGDT as clearing_date, BELNR as document_number, KUNNR as customer_number, BUZEI as line_item, GJAHR as fiscal_year from BSEG

Pool Table:

• select BZIRK as ID, BZTXT as Name from T171T where SPRAS like 'E‘

Please note that the query support works against the majority of tables. However, some tables, like HR payroll clusters, are currently not accessible. Please refer to the Readme file for known limitations.

Page 11: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 7

User Experience

SQL Server Integration Services (SSIS)

SSIS can connect to ADO .NET providers in a variety of scenarios:

1. Using SQL Server Import / Export Wizard to extract data from a mySAP Business Suite solution.

2. Using SSIS DataReader Source to extract data directly into the data flow task.

3. Using SSIS Script Task or Script Component and code against the provider to get data from the mySAP Business Suite.

Import / Export Wizard Example:1. Launch the wizard:

Page 12: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 8

2. Select .NET Framework Data Provider for mySAP Business Suite as the source of data and specify SAP connection info:

Page 13: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 9

3. Select a destination, in this case, the local SQL Server database:

Page 14: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 10

4. By default, the query option is selected. Type your command in the next screen

5. Type the target table name:

Page 15: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 11

6. Click on the Next button to see column mapping info:

Note: For non-flat file targets (for example, database tables) there is a known issue that leaves the ‘Type’ column in the above illustration blank (unmapped), where the column data type in the source file is type date or time type. When this occurs, the user has to manually map them to appropriate data types in the target. This issue will be addressed in an upcoming release.

Page 16: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 12

7. You can click Preview to view the data coming from SAP:

8. Complete the remaining wizard screens.

Page 17: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 13

DataReader Source:

1. From within the Connection Manager in your SSIS project, create a new ADO .NET connection. Select .NET Data Provider for mySAP Business Suite from the drop down list and specify the connection information for your SAP server.

The following shows an example connection to an SAP R/3 server:

Page 18: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 14

2. Drag the DataReader Source component in the Data Flow tab and connect it to Transformation or Destination components, as appropriate, for your data flow. Double-click on the DataReader Source component and select the ADO .NET connection defined in Step 1 in the Connection Manager field. Click the Component Properties tab and type your query in the SqlCommand property.

Page 19: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 15

Using the example queries provided earlier, the data flow would look like the following:

Page 20: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 16

Page 21: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 17

Date/Time values in the DataReader Source:

The columns in the source SQL command that are of type date/time are converted to data type BIGINT in the DataReader output. This is because the SSIS DataReader component converts the .NET TIMESPAN data type to INTEGER (the provider maps date/time columns from the SAP system into TIMESPAN). A conversion from BIGINT back to DATETIME can be easily performed in the dataflow pipeline using the following steps:

1. Assume that the SQLCommand in the DataReader Source is

SELECT ERZET as Int from LIKP

We know ERZET is of type Datetime in SAP R/3. You will get the corresponding integer value in the DataReaderSource Output which you connect to a Derived Column component.

The Derived Column Component creates the following derived values:

Days:  Int / ((DT_I8)864000 * (DT_I8)1000000)Hours:  (Int % ((DT_I8)864000 * (DT_I8)1000000)) / ((DT_I8)36000 * (DT_I8)1000000)Minutes: ((Int % ((DT_I8)864000 * (DT_I8)1000000)) % ((DT_I8)36000 * (DT_I8)1000000)) / 600000000Seconds: (((Int % ((DT_I8)864000 * (DT_I8)1000000)) % ((DT_I8)36000 * (DT_I8)1000000)) % 600000000) / 10000000Fractions: ((((Int % ((DT_I8)864000 * (DT_I8)1000000)) % ((DT_I8)36000 * (DT_I8)1000000)) % 600000000) % 10000000) / 10000

Page 22: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 18

This is illustrated in the following diagram.

2. The second derived column takes the above values and calculates:

DATEADD("day",Days,DATEADD("hour",Hours,DATEADD("minute",Minutes,DATEADD("second",Seconds,DATEADD("millisecond",Fractions,(DT_DBTIMESTAMP)"1/1/1753")))))

3. The calculated output of the second derived column is in DT_DBTIMESTAMP format. The above steps could be used to convert any column of date/time format in SAP source tables to DATETIME format in the data flow.

Page 23: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 19

Script Component (Data Flow):1. Create an ADO .NET connection to your mySAP Business Suite solution using

the Provider shown in step 1 for the DataReader Source example.

2. In the Connection Manager properties of the Script component, choose the connection specified in step 1.

3. In the Script properties, click Design Script to launch the script editor and create VB .NET script code against the provider, The following is an example script that extracts Sales order item information from the SAP R/3 Table VBELN:

' Microsoft Data Transformation Services user script component' This is your new script component in Microsoft Visual Basic .NET' ScriptMain is the entrypoint class for DTS Script Components

Imports SystemImports System.DataImports System.MathImports System.XmlImports Microsoft.SqlServer.Dts.Pipeline.WrapperImports Microsoft.SqlServer.Dts.Runtime.Wrapper

Public Class ScriptMain Inherits UserComponent Public Overrides Sub CreateNewOutputRows()

' Add rows by calling AddRow method on member variable called "<Output Name>Buffer"' E.g., MyOutputBuffer.AddRow() if your output was named "My Output" Dim sapCmd As IDbCommand Dim sapRdr As IDataReader Dim sapConnection As IDbConnection sapConnection = CType(Connections.Connection.AcquireConnection(Nothing), IDbConnection) sapCmd = sapConnection.CreateCommand() sapCmd.CommandText = "Select VBELN as ID,POSNR as ItemID,MATNR as ProductID,ARKTX as Item,KMPMG as Quantity,NTGEW as Weight,VOLUM as Volume,NETWR as Value,NETPR as Price from VBAP" sapCmd.Prepare() sapRdr = sapCmd.ExecuteReader() While (sapRdr.Read()) Output0Buffer.AddRow() Output0Buffer.ID = sapRdr.GetString(0) Output0Buffer.ItemID = sapRdr.GetString(1) Output0Buffer.ProductID = sapRdr.GetString(2) Output0Buffer.Item = sapRdr.GetString(3) Output0Buffer.Quantity = sapRdr.GetDecimal(4) Output0Buffer.Weight = sapRdr.GetDecimal(5) Output0Buffer.Volume = sapRdr.GetDecimal(6) Output0Buffer.Value = sapRdr.GetDecimal(7) Output0Buffer.Price = sapRdr.GetDecimal(8)

Page 24: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 20

End While End Sub

End Class

Page 25: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 21

SSIS Business Usage Example:Create an ADO .NET connection to your mySAP Business Suite solution using the Provider shown in step 1 for DataReader Source example. Use any of the SSIS options discussed above to source data from the mySAP Business Suite solution – for example, DataReader Source. Add any number of transforms and destinations to meet your business needs.

The following is a business example using SSIS to extract customer, product and sales data from SAP R/3 and then building Analysis Services cubes and dimensions on top of that data for analysis:

1. Control Flow of SSIS package:

Page 26: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 22

Page 27: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 23

2. Extract Customer Info (Data Flow):

Page 28: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 24

3. Extract Products info (Data Flow):

Page 29: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 25

4. Extract Sales information and filter for data with appropriate customer and products information available for analysis (Data Flow):

Page 30: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 26

5. Once data is extracted from SAP into an operational data store, build Data Source View (DSV) on top:

Page 31: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 27

6. Build an Analysis Services cube over the DSV for Sales Order Items:

Page 32: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 28

7. Build Analysis Services dimension for product:

Page 33: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 29

8. Build Analysis Services dimension for Customer Geography:

Page 34: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 30

9. SAP R/3 Sales Line Item data can now be analyzed by Geography and Product type:

Page 35: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 31

SQL Server Reporting Services (SSRS)

PrerequisiteIn order to use the SSRS Report Designer and Report Server with the Microsoft .Net Data Provider for mySAP Business Suite, you need to update the Reporting Services configuration files, RsReportDesigner.config and RsReportServer.config

The configuration settings are commented out in each configuration file. You can remove the comments to enable the settings for your installation.

In the <Data> section in RsReportDesigner.config file, remove the comments from this entry:

<Extension Name="SAP" Type="Microsoft.Adapter.SAP.SAPConnection,Microsoft.Adapter.SAP.SAPProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

In the <Designer> section in RsReportDesigner.config file, remove comments from this entry:

<Extension Name="SAP" Type="Microsoft.Adapter.SAP.SAPConnection,Microsoft.Adapter.SAP.SAPProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

In the <Data> section in RsReportServer.config file, remove the comments from this entry:

<Extension Name="SAP" Type="Microsoft.Adapter.SAP.SAPConnection,Microsoft.Adapter.SAP.SAPProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

Page 36: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 32

Report Design

In your Report Server project, add a new Shared Data Source, select SAP as your Data Source Type, and then click Edit to configure your connection properties to the mySAP Business Suite solution.

Page 37: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 33

In the default query designer window, you can type in commands against the data provider. For example, here is a report that returns flight data with the query- Select * from SPFLI:

Page 38: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 34

.NET Code

The following is an example of .NET code that illustrates how to invoke a BAPI (in this example) and retrieve the results:

SAPConnection con = new SAPConnection("ASHOST=<SAPserver>; CLIENT=<client>;SYSNR=<sysnr>;USER=<user>;PASSWD=<password>;LANG=<logon language>");con.Open();SAPCommand cmd = new SAPCommand(con);cmd.CommandText = "EXEC BAPI_CUSTOMER_GETLIST @IDRANGE=@param OUTPUT";

SAPParameter param = new SAPParameter("@param", ParameterDirection.InputOutput);DataTable dt = new DataTable();dt.Columns.Add("SIGN");dt.Columns.Add("OPTION");dt.Columns.Add("LOW");dt.Columns.Add("HIGH");DataRow row = dt.NewRow();row["LOW"] = 1;row["HIGH"] = 1000;dt.Rows.Add(row);param.Value = dt;cmd.Parameters.Add(param);

SAPDataReader dr = cmd.ExecuteReader();          //retrieving returned datareaders   do     {      Console.WriteLine("value of returned datareader: " + dr.GetSchemaTable().TableName);        while (dr.Read())          {            string line = "";            for (int i = 0; i < dr.FieldCount; i++)            line = line + "| " + dr.GetValue(i).ToString();            Console.WriteLine(line);           }       }       while (dr.NextResult());       Console.WriteLine("Checking returned value of parameter @IDRANGE...");        DataTable dt1 = (DataTable)param.Value;            foreach (DataRow row1 in dt1.Rows)            {                string line = "";                for (int i = 0; i < dt1.Columns.Count; i++)                    line = line + "| " + row1[i].ToString();                Console.WriteLine(line);            }

Page 39: SQL2005 NET Data Provider for MySAP Business Suite

Filename: document.doc 35

Summary If you have an Enterprise license for SQL Server 2005 and you have a need to

integrate or report on data from your mySAP Business Suite, download the Microsoft .NET Data Provider for mySAP Business Suite from the Microsoft SQL Server 2005 download site.

Follow the steps in Readme file to configure the provider to work with SQL Server 2005.

Identify your data needs in terms of BAPI/RFC invocations or direct table data access.

Design your business scenarios against data from your mySAP Business Suite solution using the Provider and traditional features of SSIS, SSRS or custom .NET code.