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.1DBSH;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.183DBSH;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>