C\#SAP RFC 를 어떻게 호출 합 니까?

5439 단어 c#saprfc
구조:

NuGet 패키지 설치:

using SAP.Middleware.Connector;
using System.Data;

namespace DFDN.SDK.ServiceInterface
{
  public class RfcDemo
  {
    public void Loading()
    {
      RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination(GetParameters()); //     
      RfcDestination SapRfcDestinationForConfig = RfcDestinationManager.GetDestination("dad"); //       App.config  
      RfcRepository SapRfcRepository = SapRfcDestination.Repository;

      DataTable dt = new DataTable(); //   
      dt.Columns.Add("DATA1", typeof(string));
      dt.Columns.Add("DATA2", typeof(string));
      dt.Columns.Add("DATA3", typeof(string));

      IRfcFunction func = SapRfcRepository.CreateFunction("Z_RFC_XXXX");
      IRfcTable tSAP = func.GetTable("INPUT_TABLE");

      for (int i = 0; i < dt.Rows.Count; i++)
      {
        string str1 = dt.Rows[i][0].ToString();
        string str2 = dt.Rows[i][1].ToString();
        string str3 = dt.Rows[i][2].ToString();
        IRfcStructure struSAP = tSAP.Metadata.LineType.CreateStructure();
        struSAP.SetValue("str1", str1);
        struSAP.SetValue("str2", str2);
        struSAP.SetValue("str3", str3);
        tSAP.Append(struSAP);
      }

      func.SetValue("INPUT_TABLE", tSAP); //table   
      func.SetValue("WERKS", "A");    //      
      func.SetValue("STATUS", "B");  //    
      func.Invoke(SapRfcDestination); //  

      IRfcTable SAPDataTable = func.GetTable("RETURN_TABLE"); //      

      DataTable table = ToDataTable(SAPDataTable); //  DataTable
      string result = func.GetValue("X").ToString(); //        

    }

    /// <summary>
    /// RfcTable     DataTable
    /// </summary>
    /// <param name="myrfcTable"></param>
    /// <returns></returns>
    public DataTable ToDataTable(IRfcTable myrfcTable)
    {
      DataTable loTable = new DataTable();
      int liElement;
      for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++)
      {
        RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement);

        loTable.Columns.Add(metadata.Name);
      }

      foreach (IRfcStructure Row in myrfcTable)
      {
        DataRow ldr = loTable.NewRow();

        for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++)
        {
          RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement);
          ldr[metadata.Name] = Row.GetString(metadata.Name);
        }
        loTable.Rows.Add(ldr);
      }
      return loTable;
    }

    /// <summary>
    /// SAP RFC       
    /// </summary>
    /// <returns></returns>
    public RfcConfigParameters GetParameters()
    {
      RfcConfigParameters parms = new RfcConfigParameters();

      parms.Add(RfcConfigParameters.AppServerHost, "192.168.0.114");  //SAP  IP

      parms.Add(RfcConfigParameters.SystemNumber, "01"); //SAP  

      parms.Add(RfcConfigParameters.User, "RFC_EDI"); //   

      parms.Add(RfcConfigParameters.Password, "init1"); //  

      parms.Add(RfcConfigParameters.Client, "300"); // Client 

      parms.Add(RfcConfigParameters.Language, "ZH"); //    

      parms.Add(RfcConfigParameters.PoolSize, "10");

      parms.Add(RfcConfigParameters.IdleTimeout, "600");

      parms.Add(RfcConfigParameters.Name, "DAP");

      return parms;
    } 
  }
}

<?xml version="1.0"?>
<configuration>
 <configSections>
  <sectionGroup name="SAP.Middleware.Connector">
   <sectionGroup name="ClientSettings">
    <section name="DestinationConfiguration" type="SAP.Middleware.Connector.RfcDestinationConfiguration,sapnco"/>
   </sectionGroup>
  </sectionGroup>
 </configSections>
 <SAP.Middleware.Connector>
  <ClientSettings>
   <DestinationConfiguration>
    <destinations>
     <add NAME="dad" USER="ddac" PASSWD="qwe" CLIENT="110" SYSNR="00" ASHOST="192.168.0.111" LANG="ZH" GROUP="PUBLIC" MAX_POOL_SIZE="10" IDLE_TIMEOUT="600"></add>
    </destinations>
   </DestinationConfiguration>
  </ClientSettings>
 </SAP.Middleware.Connector>
</configuration>
이상 은 C\#SAP RFC 를 어떻게 호출 하 는 지 에 대한 상세 한 내용 입 니 다.C\#SAP RFC 호출 에 관 한 자 료 는 다른 관련 글 을 주목 하 세 요!

좋은 웹페이지 즐겨찾기