Tag Archives: SAP WCF

BizTalk SAP Integration – Part 2 (Connecting to SAP using WCF Lob Adapter)

Making a Connection to SAP with BizTalk Server and SAP WCF Adapter

So this part of the process was a lot easier than I thought it would be.  I asked the SAP Basis guys for a login to their test system. This account needed quite a high level of access but was setup as a service account so no client SAP GUI login was possible.

I opened a new BizTalk Project in VS2005. Right click on the project and select add generated items.

This brings up the dialog screen which allows you to connect to a SAP instance and brose the available IDOCs. You will need to  have the following information available to you beforehand

  • SAP System Name or IP address
  • SAP Gateway Name
  • SAP username and password

A list of the IDOCs and versions you intend to use (note : if you are intending to connect to multiple versions of SAP then you will need the specific IDOC versions they are using. They may also be using altered IDOCs , some organisations add additional fields, or even remove fields to cut the size of the IDOC down. In this case you must have the specific versions in use as you will be downloading each IDOC as an XML schema which will be validated by BizTalk. If BizTalk doesn’t recognise the schema then it will suspend the message). I fell foul of this when I only downloaded schemas from one particular system on version 640 and was also expected to communication with another SAP Instance on version 46C.

Do yourself a big favour here and get a written confirmation of exactly which IDOCs and their versions you will be expected to work with. The number of these impacts your estimates and if there are more of these than you expected then add additional time to your development for your maps and discussions on which fields are going to be used.

Visual Studio steps to download schemas

For each IDOC you have the choice for Inbound Schemas and Outbound schemas. (Which means – loading IDOCs into SAP or received from SAP!).  You have the option to name each schema so make sure you do this as it mkes for a clearer solution later on and will help with your selections for your Transforms in BizTalk.

You will receive a couple of schemas when you download.

1. The IDOC format schema which contains all the fields in the IDOC.(Segments)

2. A Receive/Response formatted schema (which uses the above)

2. The Standard SAP property Schema which defines the standard SAP IDOC Header records. (You only need one of these in each project as you can point all your IDOCs at this)

Here is the Microsoft link which gives more detail – http://msdn.microsoft.com/en-us/library/cc185460(BTS.10).aspx

SAP IDOC Headers

SAP IDOCs all contain a header section. This contains key information for SAP which changes depending on the direction of the DOC (inbound or outbound from SAP). Here is an example of the IDOC header.  The key information I use for validation and to recognise the source of the data is SNDPOR (Sending System Port), SNDPRN (Sending System/Partner), IDOCTYP (Type of IDOC this one is a Customer Master), MESTYP (Type of Message).  This information is also used by the adapter to find the correct schema to validate.

This is a example of a populated SAP header

<IDOC_CONTROL_REC_40><EDI_DC40 xmlns="http://Microsoft.LobServices.Sap/2007/03/Types/Rfc/">
<TABNAM>EDI_DC40</TABNAM>
<MANDT>626</MANDT>
<DOCNUM>0000000004436611</DOCNUM>
<DOCREL>640</DOCREL>
<STATUS>30</STATUS>
<DIRECT>1</DIRECT>
<OUTMOD>2</OUTMOD>
<EXPRSS></EXPRSS>
<TEST></TEST>
<IDOCTYP>DEBMAS06</IDOCTYP>
<CIMTYP></CIMTYP>
<MESTYP>DEBMAS</MESTYP>
<MESCOD></MESCOD>
<MESFCT></MESFCT>
<STD></STD>
<STDVRS></STDVRS>
<STDMES>DEBMAS</STDMES>
<SNDPOR>SAPT66</SNDPOR>
<SNDPRT>LS</SNDPRT>
<SNDPFC></SNDPFC>
<SNDPRN>T66CLNT444</SNDPRN>
<SNDSAD></SNDSAD>
<SNDLAD></SNDLAD>
<RCVPOR>BIZTALKPTR</RCVPOR>
<RCVPRT>LS</RCVPRT>
<RCVPFC></RCVPFC>
<RCVPRN>BIZTALKDEV</RCVPRN>
<RCVSAD></RCVSAD>
<RCVLAD></RCVLAD>
<CREDAT>2009-03-05T00:00:00</CREDAT>
<CRETIM>0001-01-01T13:18:46</CRETIM>
<REFINT></REFINT>
<REFGRP></REFGRP>
<REFMES></REFMES>
<ARCKEY></ARCKEY>
<SERIAL>20090305120803</SERIAL>
</EDI_DC40>
</IDOC_CONTROL_REC_40>
<IDOC_DATA_REC_40>

Setting up the Connections

The next step here is to setup a connection to SAP.  What you do here depends on whether you are sending or receiving IDOCs. (I was doing both)

Receiving IDOCS from SAP

Before we do anything, there is an adapter gotcha we have to fix.  The SAP WCF Adapter needs an assembly which contains the SAP Property Schema for the idoc header. This is a standard assembly from Microsoft and you can find it in <sap wcf install path>\

Next step is to create a Receive Port and Receive Location ..

Change the bindings to this..

add user and password

verify the final URI (connection string)

Start the receive location and wait for the SAP Guys to send a idoc. Make sure you have tracking turned on and verify the receipt of the IDOC using HAT and also keep an eye on the application log for errors.  This took me a little while to get running as the receive location connects up to the Gateway and authenticates so its your first real test of the user account settings.

Troubleshooting Checklist

Make sure you have done all of these things …!

1. Got a valid user account to connect to SAP (the receive location will disable itself if this is incorrect)

2. Added the Biztalk Property Schema adapter resource to your BizTalk application (or reference another application with the resource)

3. Enabled access through any firewalls on ports 32<XX> to the SAP Server (uses standard client access ports)

4. Ensured the SAP team hae set up and registered a valid program ID on the SAP Gateway and pointed their RFC location to this. (the receive location will disable itself if this is incorrect)

5. Check your URI!

The minimum you need is this;

SAP//Client=    (leave blank for dynamic)

lang=EN (optional)

A/{ip address or name here}/00

ListenerGWHost={ip address or name}

ListenerGWServer={name usually sapgw00 but if multiple SAP instances then may be different}

ListenerProgramId={the registered program ID}

Hope this helps, for me this part took a while as we had many different instances to connect to and lots of firewalls to deal with.

There are Microsoft resources here also that have more details …