cancel
Showing results for 
Search instead for 
Did you mean: 

Error: SAP.Middleware.Connector.RfcTypeConversionException

Former Member
0 Kudos

Hello all,

I am trying to write a simple call and I am getting this error:

Error: SAP.Middleware.Connector.RfcTypeConversionException: FIELD VERPR of STRUCTURE ZFPST_ARTIKEL (SETTER): cannot convert Byte[] into BCD[6:2] ---> SAP.Middleware.Connector.RfcTypeConversionException: Cannot convert byte[] into a BCD: 5A at position 1 is illegal bei SAP.Middleware.Connector.RfcScalarMetadataBcd.ConvertByteArray(Byte[] value, Int32 offset, Int32 len, Object& currentValue) bei SAP.Middleware.Connector.RfcDataContainer`1.SetValue(Int32 index, Byte[] value, Int32 offset, Int32 len) --- Ende der internen Ausnahmestapelüberwachung --- bei SAP.Middleware.Connector.RfcDataContainer`1.SetValue(Int32 index, Byte[] value, Int32 offset, Int32 len) bei SAP.Middleware.Connector.RfcStructure.RfcDeserializeField(RfcConnection conn, Int32 length, Int32 fieldIndex, Byte[] src, Int32 srcOffset, Boolean isPartnerUnicode) bei SAP.Middleware.Connector.RfcStructure.RfcDeserialize(RfcConnection conn, Int32 length, Byte[] src) bei SAP.Middleware.Connector.RfcTable.RfcDeserialize(RfcConnection conn, Int32 srcLength, Int32 rowLength, TableCompression compression) bei SAP.Middleware.Connector.RfcConnection.ReadUpTo(RFCGET readState, RfcFunction function, RFCID toRid) bei SAP.Middleware.Connector.RfcConnection.RfcReceive(RfcFunction function) bei SAP.Middleware.Connector.RfcFunction.RfcDeserialize(RfcConnection conn, IRfcIOStream stream) bei SAP.Middleware.Connector.RfcFunction.RfcCallReceive(RfcConnection conn, IRfcIOStream stream, RFCID rid) bei SAP.Middleware.Connector.RfcFunction.RfcCallReceive(RfcConnection conn) bei SAP.Middleware.Connector.RfcFunction.Invoke(RfcDestination destination) bei SAPConnect._Default.Page_Load(Object sender, EventArgs e) in C:Userse00062documentsvisual studio 2010ProjectsSAPConnectSAPConnectDefault.aspx.cs:Zeile 53.

Here is my code. The error is accuring on the second funcArtikel.Invoke()

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SAP.Middleware.Connector;

namespace SAPConnect
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                RfcConfigParameters rfc = new RfcConfigParameters();
                rfc.Add(RfcConfigParameters.Name, "T31");
                rfc.Add(RfcConfigParameters.AppServerHost, "the real address is not shown here");
                rfc.Add(RfcConfigParameters.Client, "111");
                rfc.Add(RfcConfigParameters.Codepage, "4110");
                rfc.Add(RfcConfigParameters.User, "user");
                rfc.Add(RfcConfigParameters.Password, "pw");
                rfc.Add(RfcConfigParameters.SystemNumber, "27");
                rfc.Add(RfcConfigParameters.Language, "DE");
                rfc.Add(RfcConfigParameters.PoolSize, "5");
                rfc.Add(RfcConfigParameters.PeakConnectionsLimit, "10");
                rfc.Add(RfcConfigParameters.IdleTimeout, "500");

                RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfc);

                RfcRepository rfcRep = rfcDest.Repository;

                IRfcFunction funcArtikel = rfcRep.CreateFunction("Z_FPGETS_ARTIKEL");
               
                funcArtikel.Invoke(rfcDest);

                IRfcTable tblReturn = funcArtikel.GetTable("RETURN");
                IRfcTable tblArtikel = funcArtikel.GetTable("T_ARTIKEL");
                IRfcTable tblLifnr = funcArtikel.GetTable("T_LIFNR");

                funcArtikel.SetValue("I_EAN11", "4006984001992");
                funcArtikel.SetValue("I_EKORG", "0001");
                funcArtikel.SetValue("I_MAX_ANZ", 2);
                funcArtikel.SetValue("I_VKORG", "0001");
                funcArtikel.SetValue("I_VTWEG", "01");
                funcArtikel.SetValue("I_WERKS", "$ZBG");
                funcArtikel.SetValue("I_VERKSP_B", 999999.99);
                funcArtikel.SetValue("I_VERKSP_V", 0);
                funcArtikel.SetValue("I_KT", "400042");
                
                funcArtikel.Invoke(rfcDest);

I have no clue why I am getting that error and have been troubleshooting for the last 2 days. Anyone have an idea?

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Also, you should make yourself sure that the parameter which returns an error is a Structure (not a table, neighter a variable). If its a Table, an conversion error will splash. Else, if its a direct variable, it must be set directly to your BAPI (RFCFunction) object.


        Dim BAPI_User_Get_Detail As IRfcFunction = myRFCRepository.CreateFunction("BAPI_USER_GET_DETAIL")
        BAPI_User_Get_Detail.SetValue("USERNAME", USERNAME)

Edited by: Nicolas Peterson on Feb 13, 2012 3:04 PM

Former Member
0 Kudos

Thanks for the reply, I will see if I have to do something with the structure. I do know the function has the Metadata elements as I shown above, plus the two tables, one of which I am trying to call against. I will let you know if I have any success or not.

Former Member
0 Kudos

I looked further into what the function allows me. It seems I have the function call "Z_FPGETS_ARTIKEL". The Metadata Elements are the following:

		Elements	Count = 26	System.Collections.Generic.List<SAP.Middleware.Connector.RfcParameterMetadata>
+		[0]	{EXPORT RETURN:TABLE BAPI_WRF_RETURN_TTY [STRUCTURE BAPIRET2]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[1]	{IMPORT I_BEPO:CHAR15 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[2]	{IMPORT I_COLOR:CHAR18 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[3]	{IMPORT I_EAN11:CHAR18 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[4]	{IMPORT I_EKORG:CHAR4}	SAP.Middleware.Connector.RfcParameterMetadata
+		[5]	{IMPORT I_IDNLF:CHAR35 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[6]	{IMPORT I_KT:CHAR18 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[7]	{IMPORT I_LIFNR:CHAR10 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[8]	{IMPORT I_LIFNR_ILN:STRUCTURE ZFPST_ILN [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[9]	{IMPORT I_LIFNR_NAME:CHAR35 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[10]	{IMPORT I_MAKTX:CHAR40 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[11]	{IMPORT I_MARC:CHAR1 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[12]	{IMPORT I_MATNR:CHAR18 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[13]	{IMPORT I_MAX_ANZ:INT4}	SAP.Middleware.Connector.RfcParameterMetadata
+		[14]	{IMPORT I_SB:CHAR18 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[15]	{IMPORT I_SIZE1:CHAR18 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[16]	{IMPORT I_SIZE2:CHAR18 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[17]	{IMPORT I_SORT:CHAR1 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[18]	{IMPORT I_TB:CHAR18 [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[19]	{IMPORT I_VERKSP_B:BCD[6:2] [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[20]	{IMPORT I_VERKSP_V:BCD[6:2] [optional:null]}	SAP.Middleware.Connector.RfcParameterMetadata
+		[21]	{IMPORT I_VKORG:CHAR4}	SAP.Middleware.Connector.RfcParameterMetadata
+		[22]	{IMPORT I_VTWEG:CHAR2}	SAP.Middleware.Connector.RfcParameterMetadata
+		[23]	{IMPORT I_WERKS:CHAR7}	SAP.Middleware.Connector.RfcParameterMetadata
+		[24]	{TABLES T_ARTIKEL:STRUCTURE ZFPST_ARTIKEL}	SAP.Middleware.Connector.RfcParameterMetadata
+		[25]	{TABLES T_LIFNR:STRUCTURE ZFPST_LIEFERANT}	SAP.Middleware.Connector.RfcParameterMetadata

The error is coming from the Field "VERPR" is a decimal stored as a BCD[6:2]. That field is in table "T_ARTIKEL".

Former Member
0 Kudos

I will look later on your specific transaction problems. If you have any concerns or issues working with metadatas, I posted a sample code snippet on "How to use metadata".

I'll come back to you soon.

Former Member
0 Kudos

I have not gotten anywhere. I even went into the sapco.dll during debugging and can see exactly where the error occurs. For some reason, the error keeps coming up when RFcScalarMetadataBcd.ConvertByteArray is called. I tried so many different Codepages.

What is strange though, when I change the language from DE to EN, or E, I get no errors but there is nothing returned.

Anyone else have a clue or suggestion that I can try?

Just like to add: When I remove the Invoke() then there is no error, I get the table column headers but of course, no datarows......

Edited by: ziorus on Feb 16, 2012 2:19 PM

Former Member
0 Kudos

HI ziorus,

Do u want insert values into database please find below code. please check your bapi returns table or function i think in standard bapi it returns "RETURN " in irfcfunction.

And one more important thing is please check your input datatypes are matched with you sap table datatype are not.

IRfcFunction funcArtikel = rfcRep.CreateFunction("Z_FPGETS_ARTIKEL");

IRfcTable tblReturn = funcArtikel.GetTable("RETURN");

IRfcTable tblArtikel = funcArtikel.GetTable("T_ARTIKEL");

IRfcTable tblLifnr = funcArtikel.GetTable("T_LIFNR");

funcArtikel.SetValue("I_EAN11", "4006984001992");

funcArtikel.SetValue("I_EKORG", "0001");

funcArtikel.SetValue("I_MAX_ANZ", 2);

funcArtikel.SetValue("I_VKORG", "0001");

funcArtikel.SetValue("I_VTWEG", "01");

funcArtikel.SetValue("I_WERKS", "$ZBG");

funcArtikel.SetValue("I_VERKSP_B", 999999.99);

funcArtikel.SetValue("I_VERKSP_V", 0);

funcArtikel.SetValue("I_KT", "400042");

funcArtikel.Invoke(rfcDest);

DO u have any concerns regarding the coding above coding snippets. Please find below my wiki link. In that one i posted all the content about the c#.net code.

http://wiki.sdn.sap.com/wiki/pages/editpage.action?pageId=263291953

Best Regards,

Harish.Y

Former Member
0 Kudos

Before calling the Invoke() Method, your must set your importation parameters.

Importation parameters can be direct variable, structures or table.

See example below to change a USER informations.

Importations Parameters : USERNAME (Variable) ADDRESS (Structure) & ADDRESSX (Structure).

myUSERNAME is an argument of the Sub, InitializeConnection is a function that returns a RFCConfigParameters object with the connection credentials.


        Dim myRFCDestination As RfcDestination = RfcDestinationManager.GetDestination(InitializeConnection)
        Dim myRFCRepository As RfcRepository = myRFCDestination.Repository

        Dim BAPI_User_Change As IRfcFunction = myRFCRepository.CreateFunction("BAPI_USER_CHANGE")

        'Open Structure
        Dim myRFC_address As IRfcStructure = BAPI_User_Change.GetStructure("ADDRESS")
        Dim myRFC_addressx As IRfcStructure = BAPI_User_Change.GetStructure("ADDRESSX")
        Dim myRFCr As IRfcTable = BAPI_User_Change.GetTable("RETURN")
        
        'Set parameters LASTNAME in structures
        myRFC_address.SetValue(LASTNAME, "Bonjour")
        myRFC_addressx.SetValue(LASTNAME, "Bonjour")

        'Apply parameters to BAPI (variables & Structures)
        With BAPI_User_Change
            .SetValue("USERNAME", myUSERNAME)
            .SetValue("ADDRESS", myRFC_address)
            .SetValue("ADDRESSX", myRFC_addressx)
            .Invoke(myRFCDestination)
        End With

        'Read returned items
        If myRFCr.RowCount = 0 Then
            'Un message est tout le temps retourné
        Else
            Dim myError As String = ""
            For i = 0 To (myRFCr.RowCount - 1)
                myRFCr.CurrentIndex = i
                myError = myError & i & ": " & myRFCr.GetString("MESSAGE") & vbNewLine
            Next
        End If

Edited by: Nicolas Peterson on Feb 13, 2012 2:56 PM