Thursday, February 21, 2008

EDI: Table passed to EDI_SEGMENTS_ADD_BLOCK is empty.

The error "EDI: Table passed to EDI_SEGMENTS_ADD_BLOCK is empty"* was thrown by the SAP .NET connector after sending an IDoc to SAP. The reason was that we've set data fields inside the EDI_DC40 element that SAP had to fill on its own, such as
  • DOCNUM
  • CREDAT
  • CRETIM
  • RCVPOR
  • SNDPOR
  • DOCNUM from the DATAHEADERREC element
Now, we are leaving these empty, and the IDoc can be received by SAP.

Thus, if you get the same error, check which fields you should set, and which SAP should set on its own.

----------
* in German SAP systems: "EDI: Die an EDI_SEGMENTS_ADD_BLOCK übergebene Tabelle ist leer"

Wednesday, February 20, 2008

Short Installation guide to integrate SAP-BizTalk connectivity in Visual Studo 2005

To integrate SAP connectivity into BizTalk 2006 R2 and Visual Studio 2005, you have to follow these steps:

1. Install the runtime version of SAP .NET Connector (NCO) for Visual Studio v1.0.x which is a prerequisite for (2) - you can download the connector from the SAP Marketplace Web site.

2. Install BizTalk Adapter v2.0 for mySAP Buesiness Suite which is available here: https://www.ms2.cn/downloads/details.aspx?FamilyId=7DBF88DE-8C23-4B25-A389-D5ACF1B1FCBE&displaylang=en

3. Install the adapter's Service Pack 1 and ignore the obsolete Error 6000-message by clicking "OK".

Monday, February 4, 2008

Using BizTalk's command xpath(msg,string) correctly

If you want to use BizTalk's xpath()-method in an Expression shape of Visual Studio's BizTalk Orchestration designer, you have to think of the return of the xpath carefully.

If you use the following:

[string] s = xpath(msg1, "/*[local-name()='Root' and namespace-uri()='http://TestBiztalkXPathCommand.Schema1'] /*[local-name()='name' and namespace-uri()='']")

to get the value at node "name", you'll receive the following error while running the orchestration:

...
Inner exception: There is an error in the XML document.
Exception type: InvalidOperationException
Source: System.Xml
[...]
Additional error information:
was not expected.
[...]
Target Site: System.Object Read_string()



The reason is that this XPath statements navigates to an XML node and, thus, an object of the class System.Xml.XmlNode is returned (and not a String). Since the XPath statement is not analyzed while building the DLL, the error occurs while running primary.

Thus, you should add /text() to your XPath statement, so that a string is returned. In this case, the following would work successfully:

[string] s = xpath(msg1, "/*[local-name()='Root' and namespace-uri()='http://TestBiztalkXPathCommand.Schema1'] /*[local-name()='name' and namespace-uri()='']/text()")


Charles Young's blogpost on xpath() was helpful to fix this problem.

Addition (June 3, 2008) : My colleague Christian found out that you should invoke some mysterious "string()"-method inside the xpath statement:

xpathExpression = "/*[local-name()='Root' and namespace-uri()='http://TestBiztalkXPathCommand.Schema1'] /*[local-name()='name' and namespace-uri()='']";
[string] s = xpath(msg1, "string(" + xpathExpression + "/text())")

Thus, you get less XPath errors (I don't know yet how that exactly works; but I know that string(...) is not an XPath expression).

Using CASE in SQL Queries

This morning, I've got to know the CASE functionality of SQL Server (which surely exists in other databases, too). With CASE you can set values for a column under specified conditions, e.g.

SELECT
Column1,
Column2 = CASE
WHEN Column1 = '1' THEN 'Y'
ELSE 'N'
END
FROM Table1

Thus, column2 will be set with 'Y' if column1 has the value '1'; otherweise 'N' will be set.

PS: An overview by Craig S Mullins helps to understand this method in more detail.