Introduction
A lot has been written about Microsoft s new data access technology LINQ (Language Integrated Query) since the first preview
version has been published. But there are still some interesting aspects to LINQ and its extensibility. This article will
introduce a new provider called LINQ to SAP which offers an easy way to retrieve business data from SAP/R3 systems within
a .NET application.
With the introduction of the .NET framework 3.5 and the programming language extensions for C# and VB.NET Microsoft began
to redefine the way developers would implement data access. Nearly all applications today are querying data from different
data sources. Mainly those data sources are SQL databases, XML files or in-memory collections. LINQ offers an universal and
standardized approach to access all those data sources using special data providers. The LINQ language syntax strongly resembles
that of SQL. The following sample shows how to query data from a string array with LINQ:
string[] names = {"John",
"Patrick", "Bill", "Tom"}
var res = from n in names where n.Contains("o") select n;
foreach(var name in res)
Console.WriteLine(name);
This simple LINQ query based on an in-memory collection (array) selects all items in the array names that contain the letter
o. Console output: John, Tom . A LINQ introduction is beyond the scope of this article. A very good introduction article can
be found on CodeProject.com.
LINQ Providers
The .NET framework comes with built-in providers for collections and lists (LINQ to Objects), for Microsoft SQL Server
databases (LINQ to SQL), for XML files (LINQ to XML) and finally for DataSet object instances (LINQ to DataSet). Beside the
standard providers, developers can extend LINQ by creating custom providers to support special data sources. LINQ to LDAP
or LINQ to Amazon are examples of such custom providers.
To write a custom LINQ provider one must basically implement two interfaces: IQueryable and IQueryProvider. These interfaces
make objects queryable in LINQ expressions. Developing a LINQ provider can be a very complex task, but there a quite some
good blog entries on the net explaining the steps in detail.
This article will introduce a new provider called LINQ to SAP from Theobald Software which provides developers with a simple
way to access SAP/ R3 systems and their data objects. The software also provides a Visual Studio 2008 Designer to define SAP
objects interactively and integrate them in .NET applications.
SAP Background
This section will give you a short explanation and background of SAP objects that are queryable by LINQ to SAP. The most
important objects are Function Modules, Tables, BW Cubes and Queries.
A Function Module is basically similar to a normal procedure in conventional programming languages. Function Modules are
written in ABAP, the SAP programming language, and are accessible from any other programs within a SAP/ R3 system. They accept
import and export parameters as well as other kind of special parameters. The image below shows an example of a Function Module
named BAPI_EQUI_GETLIST within the SAP Workbench: