...by Daniel Szego
quote
"Simplicity is the ultimate sophistication."
Leonardo da Vinci

Thursday, July 10, 2014

Integrating K2 with SAP (without K2 connect) - Part 1

​So, ever wanted to integrate your K2 envrionment with SAP ? Well actually you have some possibilities. The first option is certainly K2 connect that is meant to provide a tool to easily configure data from SAP as smart objects. If you do not have or you do not want to use K2 connect, one option is certainly to make an integration via the web services of SAP integrating either with Endpoints WCF or Endpoints Web services smart object service.
However you need to have a version from SAP Netweaver and publish some web services. So what happens, if you do not want to use K2 connect and you want to do the integration without web services and netweaver for some reasons, with the help of the old fashioned BAPI integration.  Well, it is possible, but you need deveopers. We demonstrate in the followings how :
Firtly you need of course Visual Studio 2010 or 2012 and an SAP connector. 
Among the other you can consider the following options: 
- ERP Connect from Theobald : 
  http://theobald-software.com/en/erpconnect-productinfo.htm
  You can download a trial version but buying a final version is also not so expensive. 
- SAP .Net connector :
  You can download the product from the SAP Marketplace. Unfortunately if you are not an SAP Partner,     it might be a little bit difficult.
- Reverse engineering librfc32.dll :
  At installing the SAP GUI, a librfc32.dll is installed as well, theoreticaly it is capable of doing the SAP     connection, I mean of course if you are good ar reverse engineering. 

In the following, we use ERP Connect from Theobald. 
In the following use case we want read out a list of cost center names and cost center codes for a given controlling area code.  

STEP 1: Choose and test a BAPI.
Reading out cost cetner information is possible with the help of the BAPI_COSTCENTER_GETLIST Bapi. 
You can directly test the BAPI by starting se37 transaction.


with Display you can see the code and with "Test/Execute" you can diretly test the BAPI with different input parameter conbination. 




STEP 2: Open Visual studio and create an initial project producing a class library on framework 4.5.



Three important things however: 
- Install ERP Connect on the development platform and do not forget to reference the ERPConnect45.dll
- Add reference for the SourceCode.SmartObjects.Services.ServiceSDK.dll, it can be found under C:\Program Files (x86)\K2 blackpearl\Host Server\Bin\
- Install the librfc32.dll exactly in a way as it is described in (otherwise you well get hot error messages in the future):
Configure librfc32.dll on an 64 bit environment​
STEP 3: Make code. 
The major point gonna be to implement a custom smartobject service, you can have a basic approcach for example from the following link:
create a descendent class from the ServiceAssemplyBase : it is the parent class for all custom SmartObject serv​ice.

public class SPEGServiceBrokerClass : ServiceAssemblyBase
 {
     public SPEGServiceBrokerClass()
     {
     }
override the GetConfigSession procedure and set the properties that you need : ConfigSession contains the possible parameters of SmartObject Service Instance that you can set for instance  in the SmartObject Services Tester Program. See the following screenshot :



In our example we only add on such a property that is the ControllingAreaNumber

private ServiceConfiguration _serviceConfiguration;

public ServiceConfiguration ServiceConfig
{
    get { return _serviceConfiguration; }
    set { _serviceConfiguration = value; }
}

// configuring the basic properties
public override string GetConfigSection()
{
    this.Service.ServiceConfiguration.Add("ControllingAreaNumber"truestring.Empty);
    return base.GetConfigSection();
}

​To be continued in Part 2