Click here to Skip to main content
12,627,190 members (32,515 online)
Click here to Skip to main content

Stats

144.3K views
1.2K downloads
20 bookmarked
Posted

How to Integrate SAP Business Data Into SharePoint 2010 Using Business Connectivity Services and LINQ to SAP

, 6 Nov 2010 CPOL
This article describes how to integrate SAP business data like customer data into SharePoint 2010 using Business Connectivity Services (BCS) and LINQ to SAP.

Editorial Note

This article appears in the Third Party Products and Tools section. Articles in this section are for the members only and must not be used to promote or advertise products in any way, shape or form. Please report any spam or advertising.

ERPConnectToBCS
ERPConnectToBCS
CustomerModel
CustomerModel.bdcm
CustomerModel.bdcm.diagram
SharePointProjectItem.spdata
ERPConnectToBCS.csproj.user
Features
Feature
Feature.feature
Key.snk
LINQtoERP1.erp
LINQtoERP1.erp.diagram
Package
Package.package
Properties
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Data;

using ERPConnect;
using ERPConnect.BW;
using ERPConnect.Idocs;
using ERPConnect.Linq;
using ERPConnect.Queries;

namespace ERPConnectToBCS
{
	public partial class SAPContext : ERPDataContext
	{
		public SAPContext()
		{
		}

		public SAPContext(string username, string password)
			: base(string.Format(@"USER=""{0}"" PASSWD=""{1}"" LANG=EN CLIENT=800 ASHOST=/H/lear.theobald-software.net/H/PTMALG SYSNR=05", username, password))
		{
		}

		public SAPContext(string connectionString)
			: base(connectionString)
		{
		}

		public SAPContext(string host, int system, string username, string password, string language, string client)
			: base(host, system, username, password, language, client)
		{
		}

		public SAPContext(string httpUrl, string username, string password, string language, string client)
			: base(httpUrl, username, password, language, client)
		{
		}

		public SAPContext(string messageServer, string SID, string logonGroup, string username, string password, string language, string client)
			: base(string.Format(@"MSHOST=""{0}"" R3NAME=""{1}"" GROUP=""{2}"" USER=""{3}"" PASSWD=""{4}"" LANG=""{5}"" CLIENT=""{6}""", messageServer, SID, logonGroup, username, password, language, client))
		{
		}

		public CUSTOMER_TTable SD_RFC_CUSTOMER_GET(string KUNNR, string NAME1)
		{
			if(!Connection.Ping()) Connection.Open();

			RFCFunction function = Connection.CreateFunction("SD_RFC_CUSTOMER_GET");

			function.Exports["KUNNR"].ParamValue = KUNNR;
			function.Exports["NAME1"].ParamValue = NAME1;

			CUSTOMER_TTable customer_ttable = new CUSTOMER_TTable();
			customer_ttable.Table.Name = "CUSTOMER_T";
			function.Tables["CUSTOMER_T"] = customer_ttable.Table;

			function.Execute();

			return customer_ttable;
		}
	}

	public class CUSTOMER_TTable : IEnumerable<Customer>, IListSource
	{
		RFCTable _table;

		public RFCTable Table
		{
			get { return _table; }
		}

		public int RowCount
		{
			get { return _table.RowCount; }
		}

		public CustomerCollection Rows
		{
			get { return new CustomerCollection(_table.Rows); }
		}

		public Customer this[int index]
		{
			get { return new Customer((RFCStructure)_table[index]); }
		}

		public CUSTOMER_TTable()
		{
			_table = new RFCTable();
			_table.Columns.Add("KUNNR", 20, 0, RFCTYPE.CHAR, 0);
			_table.Columns.Add("ANRED", 30, 0, RFCTYPE.CHAR, 20);
			_table.Columns.Add("NAME1", 70, 0, RFCTYPE.CHAR, 50);
			_table.Columns.Add("PFACH", 20, 0, RFCTYPE.CHAR, 120);
			_table.Columns.Add("STRAS", 70, 0, RFCTYPE.CHAR, 140);
			_table.Columns.Add("PSTLZ", 20, 0, RFCTYPE.CHAR, 210);
			_table.Columns.Add("ORT01", 70, 0, RFCTYPE.CHAR, 230);
			_table.Columns.Add("TELF1", 32, 0, RFCTYPE.CHAR, 300);
			_table.Columns.Add("TELFX", 62, 0, RFCTYPE.CHAR, 332);
			_table.Columns.FixedLength = 394;
		}

		public CUSTOMER_TTable(RFCTable table)
		{
			_table = table;
		}

		public Customer AddRow()
		{
			return new Customer(_table.AddRow());
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return Rows.GetEnumerator();
		}

		IEnumerator<Customer> IEnumerable<Customer>.GetEnumerator()
		{
			return (IEnumerator<Customer>)Rows.GetEnumerator();
		}

		#region IListSource Members

		public bool ContainsListCollection
		{
			get { return true; }
		}

		public IList GetList()
		{
			List<Customer> list = new List<Customer>();

			IEnumerator<Customer> e = (IEnumerator<Customer>)Rows.GetEnumerator();

			if (e != null)
			{
				while(e.MoveNext())
					list.Add(e.Current);
			}

			return list;
		}

		#endregion
	}

	public class Customer
	{
		RFCStructure _structure;

		[Browsable(false)]
		public RFCStructure Structure
		{
			get { return _structure; }
		}

		public string KUNNR
		{
			get { return (string)_structure["KUNNR"]; }
			set { _structure["KUNNR"] = value; }
		}

		public string ANRED
		{
			get { return (string)_structure["ANRED"]; }
			set { _structure["ANRED"] = value; }
		}

		public string NAME1
		{
			get { return (string)_structure["NAME1"]; }
			set { _structure["NAME1"] = value; }
		}

		public string PFACH
		{
			get { return (string)_structure["PFACH"]; }
			set { _structure["PFACH"] = value; }
		}

		public string STRAS
		{
			get { return (string)_structure["STRAS"]; }
			set { _structure["STRAS"] = value; }
		}

		public string PSTLZ
		{
			get { return (string)_structure["PSTLZ"]; }
			set { _structure["PSTLZ"] = value; }
		}

		public string ORT01
		{
			get { return (string)_structure["ORT01"]; }
			set { _structure["ORT01"] = value; }
		}

		public string TELF1
		{
			get { return (string)_structure["TELF1"]; }
			set { _structure["TELF1"] = value; }
		}

		public string TELFX
		{
			get { return (string)_structure["TELFX"]; }
			set { _structure["TELFX"] = value; }
		}

		public Customer()
		{
			RFCTableColumnCollection collection = new RFCTableColumnCollection();
			collection.Add("KUNNR", 20, 0, RFCTYPE.CHAR, 0);
			collection.Add("ANRED", 30, 0, RFCTYPE.CHAR, 20);
			collection.Add("NAME1", 70, 0, RFCTYPE.CHAR, 50);
			collection.Add("PFACH", 20, 0, RFCTYPE.CHAR, 120);
			collection.Add("STRAS", 70, 0, RFCTYPE.CHAR, 140);
			collection.Add("PSTLZ", 20, 0, RFCTYPE.CHAR, 210);
			collection.Add("ORT01", 70, 0, RFCTYPE.CHAR, 230);
			collection.Add("TELF1", 32, 0, RFCTYPE.CHAR, 300);
			collection.Add("TELFX", 62, 0, RFCTYPE.CHAR, 332);

			_structure = new RFCStructure(collection);
		}

		public Customer(RFCStructure structure)
		{
			_structure = structure;
		}
	}

	public class CustomerCollection : IEnumerator<Customer>, IEnumerable<Customer>, IListSource
	{
		RFCStructureCollection _collection;
		int _position;

		Customer IEnumerator<Customer>.Current
		{
			get { return this[_position]; }
		}

		public object Current
		{
			get { return this[_position]; }
		}

		public Customer this[int index]
		{
			get { return new Customer(_collection[index]); }
		}

		public CustomerCollection (RFCStructureCollection collection)
		{
			_collection = collection;
			_position = -1;
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return (IEnumerator)this;
		}

		public IEnumerator<Customer> GetEnumerator()
		{
			return (IEnumerator<Customer>)this;
		}

		public bool MoveNext()
		{
			return ++_position < _collection.Count;
		}

		public void Reset()
		{
			_position = -1;
		}

		public void Dispose()
		{
		}

		public Customer Add()
		{
			return new Customer(_collection.Add());
		}

		#region IListSource Members

		public bool ContainsListCollection
		{
			get { return true; }
		}

		public IList GetList()
		{
			List<Customer> list = new List<Customer>();

			IEnumerator<Customer> e = GetEnumerator();

			if (e != null)
			{
				while(e.MoveNext())
					list.Add(e.Current);
			}

			return list;
		}

		#endregion
	}
}
#pragma warning restore 1591

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jürgen Bäurle
Software Developer (Senior)
Germany Germany
I’m a software developer based in Germany.

Homepage

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161205.3 | Last Updated 6 Nov 2010
Article Copyright 2012 by Jürgen Bäurle
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid