C# 使用sapnco连接SAP

                        RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination("QAS");

                        RfcRepository SapRfcRepository = SapRfcDestination.Repository;

                        //// Create and invhuoke function moduleZCHANNEL_RFC_MESSAGE  
                        IRfcFunction myfun = SapRfcRepository.CreateFunction("ZOA_CREATE_PO");

                        // Set some input values for the structure.  
                        IRfcStructure import = null;

                        //myfun.SetValue("BSART", "NB");
                        myfun.SetValue("BSART", bb.BSART);
                        myfun.SetValue("WERKS_D", bb.WERKS_D);
                        myfun.SetValue("EKORG", bb.EKORG);
                        myfun.SetValue("BUKRS", bb.BUKRS);
                        myfun.SetValue("DZTERM", bb.DZTERM);
                        myfun.SetValue("EVERK", bb.EVERK);
                        myfun.SetValue("LIFNR", bb.LIFNR);
                        myfun.SetValue("KDATE", bb.KDATE);
                        myfun.SetValue("TAX_CODE", bb.TAX_CODE);
                        myfun.SetValue("LGORT", bb.LGORT);
                        myfun.SetValue("TELEPHONE", bb.TELEPHONE);

                        IRfcTable table = myfun.GetTable("ITEM");

                        for (int k = 0; k < bb.Table.Count; k++)
                        {
                            import = SapRfcRepository.GetStructureMetadata("ZOA_CREATE_PO").CreateStructure();
                            import.SetValue("MATNR", bb.Table[k].MATNR);
                            import.SetValue("BSTMG", bb.Table[k].BSTMG);
                            import.SetValue("NET_PRICE", Convert.ToDecimal(bb.Table[k].NET_PRICE));
                            table.Insert(import);
                        }
                        myfun.Invoke(SapRfcDestination); //执行函数
                        string RETURNStr = myfun.GetString("ZTYP");
                        string msg = myfun.GetString("MESSAGE");
                        res = RETURNStr + ";" + msg;


App.config
<?xml version="1.0" encoding="utf-8"?>
<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="QAS" USER="PIUSER" PASSWD="" CLIENT="700"
                 LANG="ZH" ASHOST="192.168.244.21" SYSNR="00"
                 MAX_POOL_SIZE="10" IDLE_TIMEOUT="10"/>
          </destinations>
        </DestinationConfiguration>
      </ClientSettings>
    </SAP.Middleware.Connector>
    <connectionStrings>
      <add name="officialConnection" connectionString="Server=192.168.100.1\DBSH;Database=BPMDB;User Id=sa;Password=;Max Pool Size=1024;min pool size=0;Trusted_Connection=False"/>
      <add name="testConnection" connectionString="Server=192.168.100.183\DBSH;Database=BPMDB;User Id=sa;Password=;Max Pool Size=1024;min pool size=0;Trusted_Connection=False"/>
    </connectionStrings>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
</configuration>

 

 

转载于:https://www.cnblogs.com/KSalomo/p/6475497.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值