cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Error "cannot convert Byte[] into BCD[5:2]"

Former Member
0 Kudos

I am trying to call the SAP RFC Z_SZC_OIH_GET_ACCOUNT_STATUS remotely using SAP .NET Connector 3.0

(with file version 3.0.13.0 running on 64-bit .NET Framework 4.0.30319.18408)


However as soon I execute Invoke() on .NET application I get Exception as below on .NET side:


SAP.Middleware.Connector.RfcTypeConversionException: PARAMETER EP_EXPOSURE of FUNCTION Z_SZC_OIH_GET_ACCOUNT_STATUS (SETTER): cannot convert Byte[] into BCD[5:2] ---> SAP.Middleware.Connector.RfcTypeConversionException: Cannot convert byte[] of length 10 into a BCD of length 5

   at SAP.Middleware.Connector.RfcScalarMetadataBcd.ConvertByteArray(Byte[] value, Int32 offset, Int32 len, Object& currentValue)

   at SAP.Middleware.Connector.RfcDataContainer`1.SetValue(Int32 index, Byte[] value, Int32 offset, Int32 len)

   --- End of inner exception stack trace ---

   at SAP.Middleware.Connector.RfcDataContainer`1.SetValue(Int32 index, Byte[] value, Int32 offset, Int32 len)

   at SAP.Middleware.Connector.RfcDataContainer`1.SetValue(Int32 index, Byte[] value)

   at SAP.Middleware.Connector.RfcElement`1.SetValue(Byte[] value)

   at SAP.Middleware.Connector.RfcParameter.RfcDeserialize(RfcConnection conn, 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)

Following is the trace of what is being sent from application:


>>>  Client sending Z_SZC_OIH_GET_ACCOUNT_STATUS (2014-11-05 14:43:43.594)

>>>      IMPORT IP_DATFM (CHAR1)=

>>>      IMPORT IP_LANGUAGE (CHAR1)=E

>>>      IMPORT IP_SOLDTO (CHAR10)=0001001818

>>>      IMPORT IP_XDEZP (CHAR1)=

>>>     -TABLES EOT_MESSAGE_RETURN (TABLE [STRUCTURE BAPIRET2]): 0 rows

>>>     -TABLES ET_ACCOUNT (TABLE [STRUCTURE ZSS_OIH_ACCOUNT_SUMMARY]): 0 rows

>>>     -TABLES ET_PARTNER_ADDR (TABLE [STRUCTURE ZSS_OIH_PARTNERS]): 0 rows

>>>     -TABLES ET_PAYMENTS (TABLE [STRUCTURE ZSS_OIH_INVOICE_HEADER]): 0 rows

>>>      TABLES IT_SALES_ORG (TABLE [STRUCTURE ZSS_OIH_VKORG]): 3 rows

>>>        IT_SALES_ORG[0].VKORG(CHAR4)=2000

>>>        IT_SALES_ORG[0].VKORGT(CHAR75)=

>>>        IT_SALES_ORG[0].VTWEG(CHAR2)=01

>>>        IT_SALES_ORG[0].DVKORG(CHAR4)=

>>>        IT_SALES_ORG[1].VKORG(CHAR4)=2000

>>>        IT_SALES_ORG[1].VKORGT(CHAR75)=

>>>        IT_SALES_ORG[1].VTWEG(CHAR2)=02

>>>        IT_SALES_ORG[1].DVKORG(CHAR4)=

>>>        IT_SALES_ORG[2].VKORG(CHAR4)=2080

>>>        IT_SALES_ORG[2].VKORGT(CHAR75)=

>>>        IT_SALES_ORG[2].VTWEG(CHAR2)=01

>>>        IT_SALES_ORG[2].DVKORG(CHAR4)=

I get two trace files on .NET side, so in other trace file I found some info message which is below:


Invalid LZ-compressed data block received, ignored.

I have tried debugging in .NET application and SAP FM both sides but it seems correct from both ways i.e. in .NET we are sending same parameter as we see in SAP GUI app (for Windows) and in SAP I am getting all the required input parameters & in SAP output parameters are having correct values at the "END_FUNCTION" line of code in FM.

I am able to invoke the FM from SAP GUI and getting result in "Result Screen" however only from the .NET application we are not able to call. The error message comes from the SAP.NET Connector 3.0 library.

If anyone can help or guide into this, kindly reply over here.

Accepted Solutions (1)

Accepted Solutions (1)

former_member197445
Contributor
0 Kudos

What is the data type of PARAMETER EP_EXPOSURE?  If it's a decimal numeric type, set and get value using a .NET variable of type Decimal or Double.  Can you show the code where your setting or getting that particular parameter, please?

Former Member
0 Kudos

For "the data type of PARAMETER EP_EXPOSURE":

In Function Builder screen:

EP_EXPOSURE shows associated type as ZSS_OIH_CREDIT_DATA-EXPOSURE

And ZSS_OIH_CREDIT_DATA-EXPOSURE's Data Type is CURR and Length is '19' and 'Decimal Pl' is '2'. Additionally Abap Type is 'P' and Internal Length is '10'

For "set and get value using a .NET variable of type Decimal or Double":

I am not converting the value at all here. I am using SAP.NET connector it get the result for me at runtime as I execute Invoke() method on .NET application.

For "Can you show the code where your setting or getting that particular parameter":


C# Code for this question is as below:


try

{

  var sapCfg = new SAPSystemConnect(); // This class implements IDestinationConfiguration interface for setting RfcConfigParameters

  RfcDestinationManager.RegisterDestinationConfiguration(sapCfg);

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

  RfcRepository repo = rfcDest.Repository;

  IRfcFunction remoteFunction = repo.CreateFunction(txtFunctionName.Text);

  remoteFunction.SetValue("IP_SOLDTO", "0001001818");

  remoteFunction.SetValue("IP_LANGUAGE", "E");

  var salesOrg = remoteFunction.GetTable("IT_SALES_ORG");

  salesOrg.Append();

  salesOrg.SetValue("VKORG", "2000");

  salesOrg.SetValue("VTWEG", "01");

  salesOrg.Append();

  salesOrg.SetValue("VKORG", "2000");

  salesOrg.SetValue("VTWEG", "02");

  salesOrg.Append();

  salesOrg.SetValue("VKORG", "2080");

  salesOrg.SetValue("VTWEG", "01");

  remoteFunction.Invoke(rfcDest); // I get exception here itself

  var exposureValue = remoteFunction.GetDouble("EP_EXPOSURE");

}

catch (Exception ex)

{

  Logger.LogException(ex.ToString());

}

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Harsh,

latest version is 3.0.14, could you please give this version a try? If it still does not work, please open a ticket. Attach traces at level 4 so that we can see the bytestream in the traces that shall be interpreted.

Best regards,

Markus

former_member197445
Contributor
0 Kudos

I am not 100% certain, but it seems like the data type ZSS_OIH_CREDIT_DATA-EXPOSURE is your problem.  I'm sure there are ways of setting the metadata within your C# code, but the easiest thing to do would be to change that data type to the Data Element name specified in SE11 for Structure ZSS_OIH_CREDIT_DATA, Component EXPOSURE.  For example:

In hypothetical output parament EP_DOCNUM I set the Associated type to VBAK-VBELN.  If you directly enter Component type VBELN instead, the Data Type will be specified directly.  Make sense?

Former Member
0 Kudos

Can you provide link where I can find the new version of SAP.NET Connector?

Secondly can I download it as normal user login or I need some partner or customer login to download it?

Former Member
0 Kudos

I will check what you are trying to say.

What I understand from your description is:

Currently

EP_EXPOSURE <- map to -> ZSS_OIH_CREDIT_DATA-EXPOSURE <- map to -> CURR

You are saying to change to,

1. EP_EXPOSURE <- map to -> EXPOSURE

OR may be

2. EP_EXPOSURE <- map to -> CURR

Can you confirm which is right description?

P.S.: .NET developer on this side..

former_member197445
Contributor
0 Kudos

Correct.  Or you could use a standard SAP Data element, such as TV_EXPOSU, which conveniently for you has the description "Currency Exposure."  I did a few tests, and the .NET connector seems to have on-and-off issues with currency export parameters.  I was not able to reproduce your error, but got other errors when using currency.  As a last resort, if you have an ABAPer at your disposal (I myself have the benefit of being able to write my own RFCs), you could even change the export parameter to an FLTP (float).

Former Member
0 Kudos

Thanks works now.

In SAP, changed Data type of EP_EXPOSURE to TV_EXPOSU.

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Harsh,

sure: https://service.sap.com/connectors -> SAP Connector for Microsoft .NET and go to the download section for 3.0.

Best regards,

Markus

Answers (0)