浮头导航网

专注编程技术分享的开发者社区

程序调用SAP接口的几种写法_sapjson接口调用

1、传一个参数 返回表 的方式:

using SAP.Middleware.Connector;

IRfcFunction myfun = null;

RfcDestination destination = RfcDestinationManager.GetDestination("DEV");

RfcFunctionMetadata
BAPI_COMPANYCODE_GETDETAIL_MD =
destination.Repository.GetFunctionMetadata("
ZMM_GET_STOCK_QUANTITY_MUL_MH"); //接口名称

myfun = BAPI_COMPANYCODE_GETDETAIL_MD.CreateFunction(); //

myfun.SetValue("IV_PLANT", "AAA"); // 传入参数

myfun.Invoke(destination);

IRfcTable tSAP = myfun.GetTable("ET_STOCK"); // 返回表名

sql = " IF OBJECT_ID('tempdb..#TT') IS NOT NULL DROP TABLE #TT ";

sql += " CREATE TABLE #TT(MaterialID [varchar](50),MaterialName [varchar](500),MaterialSpec [varchar](50),Qty numeric(18,3))";

for (int i = 0; i < tSAP.RowCount; i++)

{

IRfcStructure stru = tSAP[i];

sql += " Insert into #TT(MaterialID,MaterialName,MaterialSpec,Qty)" +

"values('" + stru.GetValue("MATERIAL").ToString() + "','" + stru.GetValue("MAKTX").ToString() + "','"

+ stru.GetValue("GROES").ToString() + "','" + stru.GetValue("LABST").ToString() + "') ";

}

2、传多个参数 返回表:

IRfcFunction myfun = null;

RfcDestination destination = RfcDestinationManager.GetDestination("DEV");

RfcFunctionMetadata
BAPI_COMPANYCODE_GETDETAIL_MD =
destination.Repository.GetFunctionMetadata("ZPP_AAAAA"); //接口名称

myfun = BAPI_COMPANYCODE_GETDETAIL_MD.CreateFunction(); //


IRfcStructure aa = myfun.GetStructure("IS_MRP"); //结构名称

aa.SetValue("MATNR", "" + SWldm + ""); //物料 参数1

aa.SetValue("WERKS", "" + FactoryID + "");//工厂 参数2


myfun.Invoke(destination);


IRfcTable tSAP = myfun.GetTable("ET_MRP"); //返回表



sb.AppendLine(" IF OBJECT_ID('tempdb..#Ta') IS NOT NULL");

sb.AppendLine(" DROP TABLE #Ta");

sb.AppendLine(" CREATE TABLE #Ta(DELKZ [varchar](50),EXTRA [varchar](500),MNG01 DECIMAL(18,2),MNG02 DECIMAL(18,2),DAT00 DATETIME)");

for (int i = 0; i < tSAP.RowCount; i++)

{

IRfcStructure stru = tSAP[i];

sb.AppendLine(" Insert into #Ta(DELKZ,EXTRA,MNG01,MNG02,DAT00) ");

sb.AppendLine(" VALUES ( '" + stru.GetValue("DELKZ").ToString() + "', '" + stru.GetValue("EXTRA").ToString() + "','" + stru.GetValue("MNG01").ToString() + "','" + stru.GetValue("MNG02").ToString() + "','" + stru.GetValue("DAT00").ToString() + "') ");

}

3、传表 返回表的方式:

IRfcFunction myfun = null;

RfcDestination destination = RfcDestinationManager.GetDestination("DEV");

RfcFunctionMetadata
BAPI_COMPANYCODE_GETDETAIL_MD =
destination.Repository.GetFunctionMetadata("ZPP_WIP"); //调用函数名称

myfun =
BAPI_COMPANYCODE_GETDETAIL_MD.CreateFunction(); //定义输入函数


DataTable dtInv;

string sql = " SELECT FactoryID,MaterialID FROM dbo.sap_jczl_WarehouseQty GROUP BY FactoryID,MaterialID ";

if (!AF.execSql(sql, sqlconn, out dtInv, out errMsg))

{

jsonString = "错误:连接数据库失败!" + errMsg;

return;

}

IRfcTable tSAP = myfun.GetTable("IT_TAB");//传进去表名

if (dtInv.Rows.Count > 0)

{

for (int i = 0; i < dtInv.Rows.Count; i++)

{

IRfcStructure struSAP = tSAP.Metadata.LineType.CreateStructure();

struSAP.SetValue("PLANT", "AAA");

struSAP.SetValue("MATERIAL", dtInv.Rows[i]["MaterialID"].ToString());

tSAP.Append(struSAP);


}

myfun.SetValue("IT_TAB", tSAP); //传进去table 参数

myfun.Invoke(destination);


IRfcTable dtSAPData = myfun.GetTable("ET_TAB_SUM");//返回表名

//string errRow = "", errMessage = "";

var sb = new System.Text.StringBuilder();

sb.AppendLine("");

for (int i = 0; i < dtSAPData.RowCount; i++)

{

IRfcStructure stru = dtSAPData[i];

sb.AppendLine(" UPDATE sap_jczl_WarehouseQty SET WIPshl='" + stru.GetValue("ZWIP").ToString().Trim() + "' WHERE MaterialID='" + stru.GetValue("MATNR").ToString().Trim() + "' AND FactoryID='AAA

' ");

}

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言