C # by calling SAP RFC interfaces series of three, calls the method input output structure of the interface program.
using SAP.Middleware.Connector;
IDestinationConfiguration ID = new RfcConfig(); RfcDestinationManager.RegisterDestinationConfiguration(ID); RfcDestination prd = RfcDestinationManager.GetDestination("PRD_000");//正式区000环境 RfcDestinationManager.UnregisterDestinationConfiguration(ID); RfcRepository repo = prd.Repository; IRfcFunction companyBapi = repo.CreateFunction("ZM_PURCHASE_PO"); //调用函数名 try { var structSAP = companyBapi.GetStructure("pohead"); //表头 structSAP.SetValue("ZRELEASE", "1"); structSAP.SetValue("LIFNR", txtCname.Text.Trim()); //"410001" structSAP.SetValue("CITY1", "福建"); structSAP.SetValue("COUNTRY", "CN"); structSAP.SetValue("ZFORM", "8080"); structSAP.SetValue("ZOABH", lblBH.Text.Trim()); IRfcTable tableSAP = companyBapi.GetTable("IT_PO"); //表体 for (int i = 0; i < gvlist1.Rows.Count; i++) { IRfcStructure st = tableSAP.Metadata.LineType.CreateStructure(); st.SetValue("ESOKZ", "0"); st.SetValue("BNFPO", gvlist1.Rows[i].Cells[3].Text.Trim()); st.SetValue("MENGE", gvlist1.Rows[i].Cells[7].Text.Trim()); st.SetValue("MEINS", gvlist1.Rows[i].Cells[6].Text.Trim()); //计算 单位 "EA" st.SetValue("EEIND", Convert.ToDateTime(gvlist1.Rows[i].Cells[19].Text.Trim()).ToString("yyyyMMdd")); tableSAP.Append(st); } companyBapi.SetValue("pohead", structSAP); companyBapi.SetValue("IT_PO", tableSAP); companyBapi.Invoke(prd); //执行函数 IRfcStructure OPTIONS2 = companyBapi.GetStructure("E_MATNRCOST"); //输出结构 txtSCI04.Text = OPTIONS2.GetString("MAKTX"); txtSCI05.Text = OPTIONS2.GetString("WRKST"); IRfcTable OPTIONS = companyBapi.GetTable("RETURN"); //返回表格值 bool IsFail = false; StringBuilder strMsg = new StringBuilder(); for (int i = 0; i < OPTIONS.RowCount; i++) { OPTIONS.CurrentIndex = i; if (OPTIONS.GetString("TYPE").Equals("E")) { IsFail = true; strMsg.Append (OPTIONS.GetString ( " the MESSAGE " )); strMsg.Append ( " <br> " ); } } IF (IsFail) { SystemTools.displayTips ( " the SAP introduction details on exceptions:! " + strMsg.ToString ( ), 0 , lblInfoMsg); return ; } } the catch (RfcAbapException EX) // this exception specifically configured to obtain a user-defined exception information! ! ! ! { twMsgbox.AjaxAlert (companyBapi.Metadata.GetAbapException (ex.Key) .Documentation); } the catch (RfcAbapRuntimeException EX) // This Exception dedicated to acquiring operation exception during execution RFC! ! ! ! { TwMsgbox.AjaxAlert (companyBapi.Metadata.GetAbapException (ex.Key) .Documentation); } the catch (RfcBaseException EX) // This is the total Exception Exception class, retrieves all exception if there is a plurality of the Catch, can not put The first one! ! ! ! { TwMsgbox.AjaxAlert ( " number does not exist or SAP database connection error message as follows:! " + Ex.Message); }