Skip to Content
avatar image
Former Member

Set structure data from SAP.NET Problem

Hi All ,

I Faced a problem in SAP connector 3 , I'm calling custom Function in SAP ERP through WCF Service using VS 2015 .Net Framework 4.0 .

In My Case I have 2 functions first one just get Customer data by Customer Code and it is working very fine , and second one It is suppose to set data in 2 structure in custom function , My problem is Invoke Method it seems to run successfully but there isn't data executed in my ERP .

At the end I don't know the problem from WCF or problem in Calling RFC , There is no exception and I can't trace the application between invoke in C# and at execution in SAP

The sample of calling service is as following :

proxy.Open();
            SaleService.Customer obj_cust = new SaleService.Customer()
            {
               
                CustomerNO = Id , // String in data Contract
                Amount = Amount   // Decimal in Data Contract
            };
             // Call Method set customer to set data 
                Label1.Text = proxy.Set_Customer_Credit(obj_cust);
 if (proxy.State == System.ServiceModel.CommunicationState.Opened)
            {
                proxy.Close();
            }
            else
            {
                proxy.Abort();
            }

and the simple code of Set_Customer_Credit

public string Set_Customer_Credit(Customer cust )
        {
            string str_Error;
            SaleClassLibrary.Connections cfg = new Connections();
            RfcDestinationManager.RegisterDestinationConfiguration(cfg);
            RfcDestination dest = RfcDestinationManager.GetDestination("CON_DES");  
            try
            {
                RfcRepository repo = dest.Repository;
                RfcSessionManager.BeginContext(dest);
                IRfcFunction Set_Cus_Credit = repo.CreateFunction("Z_UPLD_ONLINE"); 
                IRfcStructure HEADER = Set_Cus_Credit.GetStructure("HEADER");
                IRfcStructure Items = Set_Cus_Credit.GetStructure("ITEM");
                // Insert Header Structure with some fixed data for test 
                HEADER.SetValue("COMP_CODE", "6000"); 
                HEADER.SetValue("CAJO_NUMBER", "6120");
                HEADER.SetValue("REF_DOC_NO", cust.CustomerNO.ToString());
                HEADER.SetValue("ALLOC_NMBR", "Test5");
                
                // Insert Items Structure 
                Items.SetValue("TRANSACT_NUMBER", "2");
                Items.SetValue("P_RECEIPTS", cust.Amount);
                Items.SetValue("P_NET_AMOUNT", cust.Amount);
                Items.SetValue("CUSTOMER", cust.CustomerNO.ToString());
                Items.SetValue("BUS_AREA", "0001");
            
                // Set Values
                Set_Cus_Credit.SetValue("FBCJ_ITEM", Items);
                Set_Cus_Credit.SetValue("FBCJ_HEADER", HEADER);
                // Invoke Method
                Set_Cus_Credit.Invoke(dest);
                str_Error = Set_Cus_Credit.GetString("E_ERROR_NUMBER");
               RfcSessionManager.EndContext(dest);
            }
            catch (RfcCommunicationException e)
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(cfg);
                str_Error = e.ToString();
                return str_Error;


            }
            catch (RfcLogonException e)
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(cfg);
                str_Error = e.ToString();
                return str_Error;


            }
            catch (RfcAbapRuntimeException e)
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(cfg);
                str_Error = e.ToString();
                return str_Error;


            }
            catch (RfcAbapBaseException e)
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(cfg);


                str_Error = e.ToString();
                return str_Error;
            }
          
            catch (Exception e)
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(cfg);
                str_Error = e.ToString();
                return str_Error;
            }
            RfcDestinationManager.UnregisterDestinationConfiguration(cfg);
            return str_Error;


I hope to can find any help .

Thanks ,

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers