Friday, May 30, 2014

WCF SAP Adapter XmlReaderParsingException

If you run into this exception:

A message sent to adapter "WCF-Custom" on send port "SENDPORT" with URI "sap://CLIENT=123;LANG=EN;@a/ABC/00?GWSERV=DEF&RfcSdkTrace=True&AbapDebug=False" is suspended.
 Error details: Microsoft.ServiceModel.Channels.Common.XmlReaderParsingException: The length of the value for the field exceeds the allowed value. Value: 4  Field: TDSPRAS Allowed value: 2

then you should check the IDoc-XML carefully. Since the generated XSD itself does not necessarily check for maxLength (it might only define xsd:string), the IDoc-XML might successfully validate against the schema. However, during run-time the WCF SAP adapter checks the field length against the IDoc specification and fails.

You can find the real field length actually in the flat file attribute pos_length.

Also keep in mind that the length value is doubled (at least, in our case). The exception message says that a length of 2 is allowed, but actually only 1 is allowed. I suspect that there is some encoding reason behind.

Solution: You can enrich the generated XSD by using all pos_length values in MaxLength. This way the error will be seen earlier.

BTW, if you transfer IDoc as a flat file and thus use the Flat file-Assembler, you won't run into that problem since the assembler just cuts the overlength. ;-)

Thursday, May 22, 2014

SAP-Adapter Error "The segment or group definition E2IDKU5 was not found in the IDoc metadata."

During runtime, we received the following error from the WCF SAP adapter:

Microsoft.ServiceModel.Channels.Common.XmlReaderGenerationException ist aufgetreten.
  HResult=-2146233087
  Message=The segment or group definition E2IDKU5 was not found in the IDoc metadata. The UniqueId of the IDoc type is: IDOCTYP/3/PEXR2002//701. For Receive operations, the SAP adapter does not support unreleased segments.
  Source=Microsoft.Adapters.SAP
  StackTrace:
       bei Microsoft.Adapters.SAP.TypedIdocBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)

The reason was that the IDoc contained the element name E2IDKU5 although its segment definition was E2IDKU5001.

So, whenever you run into a similar message, it's worth to check the SAP transaction WE60 to check the segment definition of the element.
 

Monday, May 12, 2014

Typical Problems Making SAP BAPI Calls

This is an uncomplete list of typical problems when you run BAPI calls.

1. If you get an empty result from SAP, you have to pass a stub of the result that you expect (read http://blogs.msdn.com/b/adapters/archive/2008/01/10/when-i-execute-bapis-i-don-t-get-back-any-data-help.aspx for more information).

2. If you get this exception
Microsoft.ServiceModel.Channels.Common.XmlReaderGenerationException: An error occurred when trying to convert the byte array [30-00-30-00-30-00-30-00-30-00-30-00-30-00-30-00] of RFCTYPE RFCTYPE_DATE with length 8 and decimals 0 to XML format. Parameter/field name: CLEAR_DATE   Error message: Die Parameter "Year", "Month", und "Day" beschreiben eine nicht darstellbare DateTime.
 you might want to create the Biztalk BAPI schema with enableSafeTyping=true. Also use this option during run-time. You can then use dates in the form of YYYYMMDD.

If you are aware of (1) and (2), a working BAPI Call would be:
<ns0:GETSTATEMENT xmlns:ns0="http://Microsoft.LobServices.Sap/2007/03/Bapi/BUS3007/">
 <ns0:COMPANYCODE>xxx</ns0:COMPANYCODE>
 <ns0:CUSTOMER>xxx</ns0:CUSTOMER>
 <ns0:DATE_FROM>20140101</ns0:DATE_FROM>
 <ns0:DATE_TO>20140505</ns0:DATE_TO>
 <ns0:NOTEDITEMS>X</ns0:NOTEDITEMS>
 <ns0:LINEITEMS />
</ns0:GETSTATEMENT>
Thanks, Mirko!