cancel
Showing results for 
Search instead for 
Did you mean: 

.NET SAP Connector RfcInvalidStateException index out of range

Former Member
0 Kudos

Greetings gentlemen!

I'm writing test .NET 4.5 console application which interacts with SAP by calling it's RFC function that returns some IDOCs to me.

For this purpose I'm using "sapnco.x86.3.0.13.1" libraries in properly configured environment (MS BizTalk Server 2013 R2 on this box works fine with SAP and successfully calls the function I need).

So here's my config:

App.config

<?xml version="1.0" encoding="utf-8"?>

<configuration>

  <appSettings>

    <add key="ServerHost" value="<IP>"/>

    <add key="SystemNumber" value="00"/>

    <add key="User" value="<USER>"/>

    <add key="Password" value="<PASSWORD>"/>

    <add key="Client" value="110"/>

    <add key="Language" value="EN"/>

    <add key="PoolSize" value="5"/>

    <add key="PeakConnectionsLimit" value="10"/>

    <add key="IdleTimeout" value="600"/>

    <add key="ConnectionType" value="C"/>  

  </appSettings>

</configuration>

And C# code:

Program.cs

SAPSystemConnect sapConfig = new SAPSystemConnect();

RfcDestinationManager.RegisterDestinationConfiguration(sapConfig);

RfcDestination rfcDest = RfcDestinationManager.GetDestination("DEV");

rfcDest.Ping();

RfcRepository rfcRepository = rfcDest.Repository;

IRfcTable zisTtEdi = rfcRepository.GetTableMetadata("ZIS_TT_EDI").CreateTable();

IRfcStructure zstEdi = rfcRepository.GetStructureMetadata("ZST_EDI").CreateStructure();

zstEdi.SetValue("SIGN", "I");

zstEdi.SetValue("OPTION", "EQ");

zstEdi.SetValue("LOW", "MATMAS05");

zstEdi.SetValue("HIGH", "0");

zisTtEdi.Append(zstEdi);

IRfcFunction rfcFunction = rfcRepository.CreateFunction("Z_IS_GET_IDOC_TO_BIZTALK_11");

rfcFunction.SetValue("IV_CON_NAME", "IKF");

rfcFunction.SetValue("IV_COUNT", 30);

rfcFunction.SetValue("IV_RCVPRN", "ZLOGSYSINT");

rfcFunction.SetValue("IV_STATUS", "12");

rfcFunction.SetValue("ZR_EDI", zisTtEdi);

rfcFunction.Invoke(rfcDest);

object EV_TEST = rfcFunction.GetValue("EV_TEST");

object EV_TIME_BEGIN = rfcFunction.GetValue("EV_TIME_BEGIN");

object EV_TIME_END = rfcFunction.GetValue("EV_TIME_END");

Function description is as follows:

Z_IS_GET_IDOC_TO_BIZTALK_11

{

FUNCTION Z_IS_GET_IDOC_TO_BIZTALK_11 (

  EXPORT ET_DATA:TABLE ZISIDTS_TT_INOUTDATA2 [STRUCTURE ZISIDTS_ST_INOUTDATA2],

  EXPORT EV_TEST:CHAR50,

  EXPORT EV_TIME_BEGIN:BCD[11:7],

  EXPORT EV_TIME_END:BCD[11:7],

  IMPORT IV_CON_NAME:CHAR30 [optional:'IKF'],

  IMPORT IV_COUNT:NUM(5) [optional:200],

  IMPORT IV_RCVPRN:CHAR10 [optional:'ZLOGSYSINT'],

  IMPORT IV_STATUS:CHAR2 [optional:'12'],

  IMPORT ZR_EDI:TABLE ZIS_TT_EDI [STRUCTURE ZST_EDI] [optional:null])"

}

As you can see, the function accepts 4 parameters of simple types and one complex type, a table.

Outputs is table and 3 simple type parameters.

Data structures:

SAP Data structures

input:

{TABLE ZIS_TT_EDI [STRUCTURE ZST_EDI]}

{STRUCTURE ZST_EDI{SIGN:CHAR1, OPTION:CHAR2, LOW:CHAR30, HIGH:CHAR30}}

output:

{TABLE ZISIDTS_TT_INOUTDATA2 [STRUCTURE ZISIDTS_ST_INOUTDATA2]}

{STRUCTURE ZISIDTS_ST_INOUTDATA2{UNEXD_:CHAR30, UNEXD:CHAR30, SENDER_:CHAR10, RECEIVER_:CHAR10, DB:CHAR30, FL:CHAR30, FVAL:CHAR255, ACT:CHAR1, IMPORDER:BCD[3:0], IMPORDER2_:BCD[3:0], HLEVEL:NUM(2), TEXP:CHAR25, TIMP:CHAR25, COUNTER:BCD[2:0], CONTENT:CHAR30, RESULT:CHAR3, NUMIDOC:NUM(16)}}

And when I'm calling "rfcFunction.Invoke(rfcDest);" I got exception:

RfcInvalidStateException

>> Error entry 2015-02-10 17:20:07.176 [Thread 10]

[ASHOST=*** SYSNR=00 USER=*** PASSWD=******** CLIENT=110 LANG=EN POOL_SIZE=5 MAX_POOL_SIZE=10 IDLE_TIMEOUT=600 NAME=DEV]

SAP.Middleware.Connector.RfcInvalidStateException: index 7 out of range

   at SAP.Middleware.Connector.DataBuffer`1.get_Item(Int32 index)

   at SAP.Middleware.Connector.RfcXRfcParser.UnescapeTag(ByteBuffer buffer, Int32 first, Int32 last)

   at SAP.Middleware.Connector.RfcXRfcParser.ProcessBeginTag()

   at SAP.Middleware.Connector.RfcXRfcParser.parse()

   at SAP.Middleware.Connector.RfcConnection.ReadRfcXmlData(RfcFunction function, RfcParameter& param, Int32 length)

   at SAP.Middleware.Connector.RfcConnection.ReadUpTo(RFCGET readState, RfcFunction function, RFCID toRid)

   at SAP.Middleware.Connector.RfcConnection.RfcReceive(RfcFunction function)

   at SAP.Middleware.Connector.RfcFunction.RfcDeserialize(RfcConnection conn, IRfcIOStream stream)

   at SAP.Middleware.Connector.RfcFunction.RfcCallReceive(RfcConnection conn, IRfcIOStream stream, RFCID rid)

   at SAP.Middleware.Connector.RfcFunction.RfcCallReceive(RfcConnection conn)

   at SAP.Middleware.Connector.RfcFunction.Invoke(RfcDestination destination)

BisTalk is able call this function without any problem.

Furthermore, when exception is raise, thru debugger I can see, that:

rfcFunction.GetValue("ET_DATA");

returns me "EXPORT TABLE ZIS_TT_EDI" filled with data (however not all records are present).

And when I change "IV_STATUS" to any other value, making this function to return empty table - no exception is raised.

Am I missing something?

Can you please explain to me the reason of such behavior?

Thank you!

Accepted Solutions (0)

Answers (1)

Answers (1)

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Alexey,

could you please try with 3.0.14, which is the latest patch level? In case the issue persists, I guess it makes sense to open a ticket on BC-MID-CON-NCO and attach traces for the working and the non-working invocation with trace level 4.

Best regards,

Markus

Former Member
0 Kudos

Hello Markus,

Just tried latest version "sapnco30dotnet40P_14-20007347" which is 3.0.14 version for x86, but no luck.

I didn't use SAP NCo before, so can you check out please, whether I'm doing it right?

When I comment line, where I'm adding input table parameter:

    rfcFunction.SetValue("ZR_EDI", zisTtEdi);

getting RfcInvalidStateException "index 9 out of range", but how could that be, if:
rfcFunction.Metadata.ParameterCount - returns '9'

and

rfcFunction.Metadata.TryNameToIndex("ZR_EDI") returns 8

how could that be?

Why "sapnco" cannot correctly handle parameters of the function?

Regards

Former Member
0 Kudos

Just made minor changes to my configuration:

...

  <configSections>

    <sectionGroup name="SAP.Middleware.Connector">

      <section name="GeneralSettings" type="SAP.Middleware.Connector.RfcGeneralConfiguration, sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23, processorArchitecture=x86"/>

      <sectionGroup name="ClientSettings">

        <section name="DestinationConfiguration" type="SAP.Middleware.Connector.RfcDestinationConfiguration, sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23, processorArchitecture=x86" />

      </sectionGroup>

    </sectionGroup>

  </configSections>

  <SAP.Middleware.Connector>

    <GeneralSettings defaultTraceLevel="4" traceEncoding="UTF-8" traceType="PROCESS" />

    <ClientSettings>

      <DestinationConfiguration>

        <destinations>

          <add NAME="Dev" USER="***" PASSWD="***" CLIENT="110" LANG="EN" ASHOST="***" SYSNR="00" MAX_POOL_SIZE="5" IDLE_TIMEOUT="600" TRACE="2"/>

        </destinations>

      </DestinationConfiguration>

    </ClientSettings>

  </SAP.Middleware.Connector>

...

And I'm not calling "RfcDestinationManager.RegisterDestinationConfiguration" now - just "RfcDestinationManager.GetDestination("Dev")".

So, as you can see, I've enabled detailed tracing in "GeneralSettings" config section, this what it tells me:

**** Trace file opened by process 12968 at 2015-02-11 14:08:33 (UTC+02:00 FLE Standard Time)

SAP .NET Connector 3.0 with file version 3.0.14.0 running on 32-bit .NET Framework 4.0.30319.34014

Program: C:\Users\***\Documents\Visual Studio 2013\Projects\TestSAP\TestSAP\bin\Debug\TestSAP.vshost.exe

Working directory: C:\Users\***\Documents\Visual Studio 2013\Projects\TestSAP\TestSAP\bin\Debug

Operating system:  Standard Server 64-bit

Processor: 4x AMD64 (or x64)

SAP release: 721, Kernel release: 721, Kernel patch level: 327

Hostname: ***, IP address: ***, IP_v6 address:

Default trace level: RemoteFunctionCall,PublicAPI,InternalAPI,RfcData

2015-02-11 14:08:33.152 [Thread 10] RfcDestinationManager.RegisterDefaultConfiguration(SAP.Middleware.Connector.RfcDestinationCollection)

2015-02-11 14:08:33.161 [Thread 10] RfcDestinationManager.RegisterDefaultConfiguration OK

2015-02-11 14:08:33.186 [Thread 10] ------ Destination Dev: tracing RemoteFunctionCall,PublicAPI ------

2015-02-11 14:08:33.195 [Thread 10] RfcDestination.Ping() <Dev (ORIGINAL) [USER=*** PASSWD=*** CLIENT=110 LANG=EN ASHOST=*** SYSNR=00 MAX_POOL_SIZE=5 IDLE_TIMEOUT=600 NAME=Dev TRACE=2]>

2015-02-11 14:08:33.277 [Thread 10] RfcDestination.Ping OK

2015-02-11 14:08:33.294 [Thread 10] RfcRepository.GetTableMetadata(ZIS_TT_EDI) <RfcRepository DEV using destination Dev (ORIGINAL) [USER=*** PASSWD=*** CLIENT=110 LANG=EN ASHOST=*** SYSNR=00 MAX_POOL_SIZE=5 IDLE_TIMEOUT=600 NAME=Dev TRACE=2]>

2015-02-11 14:08:33.320 [Thread 10] ------ Using RFC_FUNCTION_SEARCH to check for availability of RFC_METADATA_GET at destination Dev (ORIGINAL) [USER=*** PASSWD=*** CLIENT=110 LANG=EN ASHOST=*** SYSNR=00 MAX_POOL_SIZE=5 IDLE_TIMEOUT=600 NAME=Dev TRACE=2]: AVAILABLE ------

2015-02-11 14:08:33.367 [Thread 10] RfcRepository.GetTableMetadata returned ZIS_TT_EDI

2015-02-11 14:08:33.368 [Thread 10] RfcRepository.GetStructureMetadata(ZST_EDI) <RfcRepository DEV using destination Dev (ORIGINAL) [USER=*** PASSWD=*** CLIENT=110 LANG=EN ASHOST=*** SYSNR=00 MAX_POOL_SIZE=5 IDLE_TIMEOUT=600 NAME=Dev TRACE=2]>

2015-02-11 14:08:33.369 [Thread 10] RfcRepository.GetStructureMetadata returned ZST_EDI

2015-02-11 14:08:33.370 [Thread 10] RfcRepository.CreateFunction(Z_IS_GET_IDOC_TO_BIZTALK_11) <RfcRepository DEV using destination Dev (ORIGINAL) [USER=*** PASSWD=*** CLIENT=110 LANG=EN ASHOST=*** SYSNR=00 MAX_POOL_SIZE=5 IDLE_TIMEOUT=600 NAME=Dev TRACE=2]>

2015-02-11 14:08:33.371 [Thread 10] RfcRepository.GetFunctionMetadata(Z_IS_GET_IDOC_TO_BIZTALK_11) <RfcRepository DEV using destination Dev (ORIGINAL) [USER=*** PASSWD=*** CLIENT=110 LANG=EN ASHOST=*** SYSNR=00 MAX_POOL_SIZE=5 IDLE_TIMEOUT=600 NAME=Dev TRACE=2]>

2015-02-11 14:08:33.429 [Thread 10] RfcRepository.GetFunctionMetadata returned Z_IS_GET_IDOC_TO_BIZTALK_11

2015-02-11 14:08:33.432 [Thread 10] RfcRepository.CreateFunction returned Z_IS_GET_IDOC_TO_BIZTALK_11

2015-02-11 14:08:33.436 [Thread 10] RfcFunction.Invoke(Dev (ORIGINAL) [USER=*** PASSWD=*** CLIENT=110 LANG=EN ASHOST=*** SYSNR=00 MAX_POOL_SIZE=5 IDLE_TIMEOUT=600 NAME=Dev TRACE=2]) <FUNCTION Z_IS_GET_IDOC_TO_BIZTALK_11>

2015-02-11 14:08:33.442 [Thread 10] Connection Details: Dev:***|110|E|4103|DEV|00|UA-KV-SAP-DEV|?GROUP?|?SNC_MODE?

2015-02-11 14:08:33.740 [Thread 10] RfcFunction.RfcDeserialize threw RfcInvalidStateException: index 7 out of range --- see log for details

2015-02-11 14:08:33.767 [Thread 10] RfcFunction.RfcCallReceive threw RfcInvalidStateException: index 7 out of range --- see log for details

2015-02-11 14:08:33.785 [Thread 10] RfcFunction.Invoke threw RfcInvalidStateException: index 7 out of range --- see log for details

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Alexey,

well, why rfcFunction.SetValue("ZR_EDI", zisTtEdi); leads to that "index 9 out of range" I can't tell you, because SetValue internally will do a NameToIndex(("ZR_EDI"). The exception you see looks really odd. This should not be the case. However, you could also change the approach. Instead of creating a table from a MetaData instance, you could simply get the table from the function module.

via IRfcTable zisTtEdi=rfcFunction.getTable("ZR_EDI"). then zisTtEdi.Append() and afterwards thezisTtEdi.SetValue() chain. the intermediate IRfcStructure is not needed.

Best regards,

Markus

Former Member
0 Kudos

Thank you for reply.

I've already tried that as well, still with structure however. According to your advice I modified my code as follows:

IRfcFunction rfcFunction = rfcRepository.CreateFunction("Z_IS_GET_IDOC_TO_BIZTALK_11");

rfcFunction.SetValue("IV_CON_NAME", "IKF");

rfcFunction.SetValue("IV_COUNT", 30);

rfcFunction.SetValue("IV_RCVPRN", "ZLOGSYSINT");

rfcFunction.SetValue("IV_STATUS", "12");

IRfcTable zisTtEdi = rfcFunction.GetTable("ZR_EDI");

zisTtEdi.Append();

zisTtEdi.SetValue("SIGN", "I");

zisTtEdi.SetValue("OPTION", "EQ");

zisTtEdi.SetValue("LOW", "MATMAS05");

zisTtEdi.SetValue("HIGH", "0");

rfcFunction.Invoke(rfcDest);

But unfortunately, still getting "SAP.Middleware.Connector.RfcInvalidStateException: index 7 out of range"

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Alexey,

please open a ticket for this and the traces should be of level 4. 2 Will not provide sufficient information about the cause.

Best regards,

Markus