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 …

Advertisements

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

  1. Hello,

    Sorry for interrupting, but I have a problem with SAP receive location in BizTalk 2010 environment (SapErrorMessage=Name or password is incorrect.)

    I have two receive locations for my testing, one is of type SAP adapter and the other one is WCF-custom with sap-binding.
    I’m using two only because I want to see is there maybe a problem in receive location type.

    I’ve done everything from the help manual

    “SAP RFC SDK 6.40 UNICODE.
    This is available as part of SNOTE* 27517.
    The instructions to download the SDK are available at http://go.microsoft.com/fwlink/?LinkId=94691.
    After you have downloaded and extracted the SDK, copy all the DLLs from the \rfcsdk\bin and
    \rfcsdk\lib folders and copy them to the relevant location mentioned just preceding this table.”

    I have installed biztalk adapters 32/64 bit from Biztalk dvd.

    Environment:

    Windows Server 2008 SP2 64 bit, Biztalk 2010.

    In machine.config (32/64 bit) i have

    Also I’ve read about AcceptCredentialsInUri but i don’t see any place where I can put this property to True.

    In my production/test environment with Biztalk 2006 and win server 2003 everything works great.

    When I run command sapinfo -v I get:

    This RFC library belongs to the SAP R/3 Release ***640,0,395 UNICODE ***

    and command: sapinfo ashost=appserver sysnr=XX I got this information:

    SAP release: 620
    SAP kernel release: 640

    ———————–
    Could you please give me some directions what should I do or where to look at. (Username and password are OK – i’m using them from my existing test environment)

    When I create receive location and when i try to enable it I got this error message:

    The Messaging Engine failed to add a receive location “IDOC_Custom” with URL
    “sap://Client=355;lang=EN@A/server_name/11?ListenerGwHost=server_name&ListenerGwServ=XXXX&ListenerProgramId=XXXXX” to the adapter “WCF-Custom”.
    Reason: “Microsoft.ServiceModel.Channels.Common.ConnectionException:
    Details: ErrorCode=RFC_OK. ErrorGroup=RFC_ERROR_LOGON_FAILURE.
    SapErrorMessage=Name or password is incorrect. Please re-enter. AdapterErrorMessage=. —> Microsoft.Adapters.SAP.RFCException:
    Details: ErrorCode=RFC_OK. ErrorGroup=RFC_ERROR_LOGON_FAILURE. SapErrorMessage=Name or password is incorrect. Please re-enter. AdapterErrorMessage=.
    at Microsoft.Adapters.SAP.RfcClientConnection.Open()
    at Microsoft.Adapters.SAP.SAPConnection.Open(TimeSpan timeout)
    — End of inner exception stack trace —
    at Microsoft.Adapters.SAP.SAPConnection.Open(TimeSpan timeout)
    at Microsoft.ServiceModel.Channels.Common.Design.ConnectionPool.GetConnection(Guid clientId, TimeSpan timeout)
    at Microsoft.ServiceModel.Channels.Common.Design.ConnectionPool.GetConnectionHandler[TConnectionHandler](Guid clientId, TimeSpan timeout, MetadataLookup metadataLookup, String& connectionId)
    at Microsoft.ServiceModel.Channels.Common.Channels.AdapterChannelListener`1.OnOpen(TimeSpan timeout)
    at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
    at Microsoft.Adapters.Internal.LayeredChannelBindingElement.LayeredChannelListener`1.OnOpen(TimeSpan timeout)
    at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
    at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
    at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
    at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
    at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
    at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfReceiveEndpoint.Enable()
    at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfReceiveEndpoint..ctor(BizTalkEndpointContext endpointContext, IBTTransportProxy transportProxy, ControlledTermination control)
    at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfReceiver`2.AddReceiveEndpoint(String url, IPropertyBag adapterConfig, IPropertyBag bizTalkConfig)”.

    Thanks

  2. Hi – I think the theme is Coraline is just a standard theme 😉 so we just added content – Good luck with your blog.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s