SapApi.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Web;
  5. using System.Configuration;
  6. using SAP.Middleware.Connector;
  7. /// <summary>
  8. /// SapApi xuwei add 2020-07-15
  9. /// </summary>
  10. public class SapApi
  11. {
  12. //SAP服务器配置参数
  13. public static string appServerHost = ConfigurationManager.AppSettings["SapAppServerHost"].ToString();
  14. public static string systemNumber = ConfigurationManager.AppSettings["SapSystemNumber"].ToString();
  15. public static string user = ConfigurationManager.AppSettings["SapUser"].ToString();
  16. public static string password = ConfigurationManager.AppSettings["SapPassword"].ToString();
  17. public static string client = ConfigurationManager.AppSettings["SapClient"].ToString();
  18. /// <summary>
  19. /// 读取库存单价接口(获取库存数量)
  20. /// </summary>
  21. /// <param name="WERKS">工厂代号</param>
  22. /// <param name="MATNR">物料编号</param>
  23. /// <param name="LGORT">库存地点</param>
  24. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  25. /// <param name="ZMSG">消息文本</param>
  26. /// <returns></returns>
  27. public static DataTable ZMMFM037(string WERKS, List<string> matnrs, string LGORT, out string ZTYPE, out string ZMSG)
  28. {
  29. RfcConfigParameters rfcPara = new RfcConfigParameters();
  30. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  31. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  32. rfcPara.Add(RfcConfigParameters.User, user);
  33. rfcPara.Add(RfcConfigParameters.Password, password);
  34. rfcPara.Add(RfcConfigParameters.Client, client);
  35. rfcPara.Add(RfcConfigParameters.Name, "CON");
  36. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  37. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  38. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  39. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  40. RfcRepository rfcRep = rfcDest.Repository;
  41. //接口API
  42. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM037");
  43. //输入参数
  44. IRfcTable imTable = rfcApi.GetTable("TAB_IN");
  45. foreach (string MATNR in matnrs)
  46. {
  47. imTable.Append();
  48. imTable.SetValue("WERKS", WERKS);
  49. imTable.SetValue("MATNR", MATNR);
  50. imTable.SetValue("LGORT", LGORT);
  51. }
  52. //调用接口
  53. rfcApi.Invoke(rfcDest);
  54. //获取输出
  55. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  56. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  57. IRfcTable table = rfcApi.GetTable("TAB_OUT");
  58. DataTable dt = GetDataTableFromRFCTable(table);
  59. //string[] columns = new string[] { "WERKS", "MATNR", "MEINS", "VBELN", "POSNR", "CHARG", "LGORT", "MENGE", "VERPR", "WAERS" };
  60. //DataTable dt = new DataTable();
  61. //foreach (string clmn in columns)
  62. //{
  63. // dt.Columns.Add(clmn);
  64. //}
  65. //for (int i = 0; i < table.RowCount; i++)
  66. //{
  67. // DataRow dr = dt.NewRow();
  68. // foreach (string clmn in columns)
  69. // {
  70. // dr[clmn] = table.GetString(clmn);
  71. // }
  72. // dt.Rows.Add(dr);
  73. //}
  74. rfcDest = null;
  75. rfcRep = null;
  76. return dt;
  77. }
  78. /// <summary>
  79. /// 读取库存单价接口(获取库存数量)
  80. /// </summary>
  81. /// <param name="WERKS">工厂代号</param>
  82. /// <param name="MATNR">物料编号</param>
  83. /// <param name="LGORT">库存地点</param>
  84. /// <param name="ZMSG">消息文本</param>
  85. /// <returns></returns>
  86. public static DataTable ZMM_WMS016(string WERKS, List<string> matnrs, string LGORT, out string ZMSG)
  87. {
  88. RfcConfigParameters rfcPara = new RfcConfigParameters();
  89. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  90. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  91. rfcPara.Add(RfcConfigParameters.User, user);
  92. rfcPara.Add(RfcConfigParameters.Password, password);
  93. rfcPara.Add(RfcConfigParameters.Client, client);
  94. rfcPara.Add(RfcConfigParameters.Name, "CON");
  95. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  96. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  97. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  98. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  99. RfcRepository rfcRep = rfcDest.Repository;
  100. //接口API
  101. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMM_WMS016");
  102. //输入参数
  103. IRfcTable imTable = rfcApi.GetTable("IT_INPUT");
  104. foreach (string MATNR in matnrs)
  105. {
  106. imTable.Append();
  107. imTable.SetValue("WERKS", WERKS);
  108. imTable.SetValue("MATNR", MATNR);
  109. imTable.SetValue("LGORT", LGORT);
  110. }
  111. //调用接口
  112. rfcApi.Invoke(rfcDest);
  113. //获取输出
  114. ZMSG = rfcApi.GetValue("E_MSG").ToString();
  115. IRfcTable table = rfcApi.GetTable("IT_OUTPUT");
  116. DataTable dt = GetDataTableFromRFCTable(table);
  117. rfcDest = null;
  118. rfcRep = null;
  119. return dt;
  120. }
  121. /// <summary>
  122. /// 读取库存单价接口(获取库存数量)
  123. /// </summary>
  124. /// <param name="WERKS">工厂代号</param>
  125. /// <param name="LGORT">库存地点</param>
  126. /// <param name="ZMSG">消息文本</param>
  127. /// <returns></returns>
  128. public static DataTable ZMM_WMS016(string WERKS, DataTable dtInventory, out string ZMSG)
  129. {
  130. RfcConfigParameters rfcPara = new RfcConfigParameters();
  131. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  132. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  133. rfcPara.Add(RfcConfigParameters.User, user);
  134. rfcPara.Add(RfcConfigParameters.Password, password);
  135. rfcPara.Add(RfcConfigParameters.Client, client);
  136. rfcPara.Add(RfcConfigParameters.Name, "CON");
  137. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  138. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  139. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  140. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  141. RfcRepository rfcRep = rfcDest.Repository;
  142. //接口API
  143. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMM_WMS016");
  144. //输入参数
  145. IRfcTable imTable = rfcApi.GetTable("IT_INPUT");
  146. foreach (DataRow row in dtInventory.Rows)
  147. {
  148. imTable.Append();
  149. imTable.SetValue("WERKS", WERKS);
  150. imTable.SetValue("MATNR", row["IDNRK"]);
  151. imTable.SetValue("LGORT", row["POSITION"]);
  152. }
  153. //调用接口
  154. rfcApi.Invoke(rfcDest);
  155. //获取输出
  156. ZMSG = rfcApi.GetValue("E_MSG").ToString();
  157. IRfcTable table = rfcApi.GetTable("IT_OUTPUT");
  158. DataTable dt = GetDataTableFromRFCTable(table);
  159. rfcDest = null;
  160. rfcRep = null;
  161. return dt;
  162. }
  163. /// <summary>
  164. /// 查询PO的相关信息(获取订单达成数量)
  165. /// </summary>
  166. /// <param name="IN_EBELN">采购凭证号</param>
  167. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  168. /// <param name="ZMSG">消息文本</param>
  169. /// <returns></returns>
  170. public static DataTable ZMMFM_MES_POCX(string IN_EBELN, out string ZTYPE, out string ZMSG)
  171. {
  172. RfcConfigParameters rfcPara = new RfcConfigParameters();
  173. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  174. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  175. rfcPara.Add(RfcConfigParameters.User, user);
  176. rfcPara.Add(RfcConfigParameters.Password, password);
  177. rfcPara.Add(RfcConfigParameters.Client, client);
  178. rfcPara.Add(RfcConfigParameters.Name, "CON");
  179. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  180. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  181. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  182. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  183. RfcRepository rfcRep = rfcDest.Repository;
  184. //接口API
  185. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM_MES_POCX");
  186. //输入参数
  187. rfcApi.SetValue("IN_EKORG", 1000);
  188. rfcApi.SetValue("IN_EBELN", IN_EBELN);
  189. rfcApi.SetValue("IN_AEDAT_FROM", "20220101");
  190. rfcApi.SetValue("IN_AEDAT_TO", "20301231");
  191. //调用接口
  192. rfcApi.Invoke(rfcDest);
  193. //获取输出
  194. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  195. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  196. IRfcTable table = rfcApi.GetTable("GT_OUT");
  197. //EBELN 采购凭证编号
  198. //EBELP 采购凭证的项目编号
  199. //MENGE 采购订单数量
  200. //MEINS 订单计量单位
  201. //ZYSSL 已收/ 退数量数量
  202. //ZWSSL 未收/ 退数量
  203. //ELIKZ 交货已完成标识
  204. //LIFNR 供应商编码
  205. //EKGRP 采购组
  206. //MATNR 物料编码
  207. //string[] columns = new string[] { "EBELN", "EBELP", "MENGE", "MEINS", "ZYSSL", "ZWSSL", "ELIKZ", "LIFNR", "EKGRP", "MATNR" };
  208. DataTable dt = GetDataTableFromRFCTable(table);
  209. //foreach (string clmn in columns)
  210. //{
  211. // dt.Columns.Add(clmn);
  212. //}
  213. //for (int i = 0; i < table.RowCount; i++)
  214. //{
  215. // DataRow dr = dt.NewRow();
  216. // foreach (string clmn in columns)
  217. // {
  218. // dr[clmn] = table.ro.GetString(clmn);
  219. // }
  220. // dt.Rows.Add(dr);
  221. //}
  222. rfcDest = null;
  223. rfcRep = null;
  224. return dt;
  225. }
  226. /// <summary>
  227. /// 物料主数据接口(同步最小包装数用)
  228. /// </summary>
  229. /// <param name="MBLNR">物料凭证编号</param>
  230. /// <param name="createTime">创建时间</param>
  231. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  232. /// <param name="ZMSG">消息文本</param>
  233. /// <returns></returns>
  234. public static DataTable ZMMFM054(out string ZTYPE, out string ZMSG, string syncType, string MATNR, string MTART)
  235. {
  236. RfcConfigParameters rfcPara = new RfcConfigParameters();
  237. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  238. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  239. rfcPara.Add(RfcConfigParameters.User, user);
  240. rfcPara.Add(RfcConfigParameters.Password, password);
  241. rfcPara.Add(RfcConfigParameters.Client, client);
  242. rfcPara.Add(RfcConfigParameters.Name, "CON");
  243. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  244. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  245. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  246. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  247. RfcRepository rfcRep = rfcDest.Repository;
  248. //周期性同步
  249. DateTime dateMinusOneDay = DateTime.Now; ;
  250. //接口API
  251. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM054");
  252. //输入参数
  253. if (syncType == "Manual")
  254. {
  255. //单独获取某物料的主数据信息
  256. //if (!string.IsNullOrEmpty(MATNR))
  257. rfcApi.SetValue("IN_MATNR", MATNR);
  258. //if (!string.IsNullOrEmpty(MTART))
  259. rfcApi.SetValue("IN_MTART", MTART);
  260. rfcApi.SetValue("IN_ALL", "X");
  261. }
  262. else if (syncType == "TimeInterval")
  263. {
  264. //周期性同步
  265. rfcApi.SetValue("IN_ERSDA", dateMinusOneDay.AddDays(-1).ToString("yyyyMMdd"));
  266. }
  267. else
  268. {
  269. //期初全量获取
  270. rfcApi.SetValue("IN_ALL", "X");
  271. }
  272. //rfcApi.SetValue("IN_ERSDA", dateMinusOneDay.ToString("yyyyMMdd"));
  273. rfcApi.SetValue("IN_WERKS", 5000);
  274. //调用接口
  275. rfcApi.Invoke(rfcDest);
  276. //获取输出
  277. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  278. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  279. IRfcTable table = rfcApi.GetTable("OUT_TABLE");
  280. DataTable dt = GetDataTableFromRFCTable(table);
  281. rfcDest = null;
  282. rfcRep = null;
  283. return dt;
  284. }
  285. /// <summary>
  286. /// 东科与SAP系统之线边仓库存领用接口(库存过账)
  287. /// </summary>
  288. /// <param name="BLDAT">过帐日期</param>
  289. /// <param name="ZDKNO">东科单据号</param>
  290. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  291. /// <param name="ZMSG">消息文本</param>
  292. /// <returns></returns>
  293. public static DataTable ZMMFM045(string BLDAT, string ZDKNO, DataTable dtTable, out string ZTYPE, out string ZMSG)
  294. {
  295. RfcConfigParameters rfcPara = new RfcConfigParameters();
  296. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  297. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  298. rfcPara.Add(RfcConfigParameters.User, user);
  299. rfcPara.Add(RfcConfigParameters.Password, password);
  300. rfcPara.Add(RfcConfigParameters.Client, client);
  301. rfcPara.Add(RfcConfigParameters.Name, "CON");
  302. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  303. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  304. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  305. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  306. RfcRepository rfcRep = rfcDest.Repository;
  307. //接口API
  308. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM045");
  309. //BLDAT DATS 8 0 必填 凭证日期 格式: yyyymmdd
  310. //BUDAT DATS 8 0 必填 过帐日期 格式: yyyymmdd
  311. //WERKS CHAR 4 0 必填 工厂 5020
  312. //LGORT_FM CHAR 4 0 必填 发出库位
  313. //LGORT_TO CHAR 4 0 必填 接收库位
  314. //MATNR CHAR 40 0 必填 物料编号
  315. //BWART CHAR 3 0 必填 移动类型(库存管理) 目前只允许填:311
  316. //MEINS UNIT 3 0 必填 基本计量单位
  317. //MENGE QUAN 13 3 必填 数量
  318. //ZDKNO CHAR 40 0 必填 东科单据号
  319. //输入参数
  320. IRfcTable imTable = rfcApi.GetTable("IT_ITEM");
  321. foreach (DataRow dr in dtTable.Rows)
  322. {
  323. imTable.Append();
  324. imTable.SetValue("BLDAT", BLDAT);
  325. imTable.SetValue("BUDAT", BLDAT);
  326. imTable.SetValue("WERKS", "5000");
  327. imTable.SetValue("LGORT_FM", dr["LGORT_FM"]);
  328. imTable.SetValue("LGORT_TO", dr["TOLOGT"]);
  329. imTable.SetValue("MATNR", dr["MATNR"]);
  330. imTable.SetValue("CHARG", dr["CHARG"] + "");
  331. imTable.SetValue("BWART", "311");
  332. imTable.SetValue("MEINS", dr["MEINS"]);
  333. imTable.SetValue("MENGE", dr["MENGE"]);
  334. imTable.SetValue("ZDKNO", ZDKNO);
  335. }
  336. //调用接口
  337. rfcApi.Invoke(rfcDest);
  338. //获取输出
  339. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  340. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  341. IRfcTable table = rfcApi.GetTable("ET_RETURN");
  342. DataTable dt = GetDataTableFromRFCTable(table);
  343. //string[] columns = new string[] { "BLDAT", "WERKS", "MBLNR", "MJAHR", "MSGTY", "MSGTX" };
  344. //DataTable dt = new DataTable();
  345. //foreach (string clmn in columns)
  346. //{
  347. // dt.Columns.Add(clmn);
  348. //}
  349. //for (int i = 0; i < table.RowCount; i++)
  350. //{
  351. // DataRow dr = dt.NewRow();
  352. // foreach (string clmn in columns)
  353. // {
  354. // dr[clmn] = table.GetString(clmn);
  355. // }
  356. // dt.Rows.Add(dr);
  357. //}
  358. rfcDest = null;
  359. rfcRep = null;
  360. return dt;
  361. }
  362. /// <summary>
  363. /// 冲销凭证接口(撤销过账)
  364. /// </summary>
  365. /// <param name="MBLNR">物料凭证编号</param>
  366. /// <param name="createTime">创建时间</param>
  367. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  368. /// <param name="ZMSG">消息文本</param>
  369. /// <returns></returns>
  370. public static void ZMMFM038(string MBLNR, DateTime createTime, out string ZTYPE, out string ZMSG)
  371. {
  372. RfcConfigParameters rfcPara = new RfcConfigParameters();
  373. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  374. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  375. rfcPara.Add(RfcConfigParameters.User, user);
  376. rfcPara.Add(RfcConfigParameters.Password, password);
  377. rfcPara.Add(RfcConfigParameters.Client, client);
  378. rfcPara.Add(RfcConfigParameters.Name, "CON");
  379. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  380. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  381. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  382. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  383. RfcRepository rfcRep = rfcDest.Repository;
  384. //接口API
  385. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM038");
  386. //输入参数
  387. rfcApi.SetValue("MBLNR", MBLNR);
  388. rfcApi.SetValue("MJAHR", createTime.ToString("yyyy"));
  389. rfcApi.SetValue("BUDAT", createTime.ToString("yyyyMMdd"));
  390. //调用接口
  391. rfcApi.Invoke(rfcDest);
  392. //获取输出
  393. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  394. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  395. rfcDest = null;
  396. rfcRep = null;
  397. }
  398. /// <summary>
  399. /// 测试用,用于把线边仓的货,全挪走
  400. /// </summary>
  401. /// <param name="BLDAT">过帐日期</param>
  402. /// <param name="ZDKNO">东科单据号</param>
  403. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  404. /// <param name="ZMSG">消息文本</param>
  405. /// <returns></returns>
  406. public static DataTable ZMMFM045_TEST(string BLDAT, string ZDKNO, DataTable dtTable, out string ZTYPE, out string ZMSG)
  407. {
  408. RfcConfigParameters rfcPara = new RfcConfigParameters();
  409. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  410. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  411. rfcPara.Add(RfcConfigParameters.User, user);
  412. rfcPara.Add(RfcConfigParameters.Password, password);
  413. rfcPara.Add(RfcConfigParameters.Client, client);
  414. rfcPara.Add(RfcConfigParameters.Name, "CON");
  415. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  416. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  417. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  418. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  419. RfcRepository rfcRep = rfcDest.Repository;
  420. //接口API
  421. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM045");
  422. //BLDAT DATS 8 0 必填 凭证日期 格式: yyyymmdd
  423. //BUDAT DATS 8 0 必填 过帐日期 格式: yyyymmdd
  424. //WERKS CHAR 4 0 必填 工厂 5020
  425. //LGORT_FM CHAR 4 0 必填 发出库位
  426. //LGORT_TO CHAR 4 0 必填 接收库位
  427. //MATNR CHAR 40 0 必填 物料编号
  428. //BWART CHAR 3 0 必填 移动类型(库存管理) 目前只允许填:311
  429. //MEINS UNIT 3 0 必填 基本计量单位
  430. //MENGE QUAN 13 3 必填 数量
  431. //ZDKNO CHAR 40 0 必填 东科单据号
  432. //输入参数
  433. IRfcTable imTable = rfcApi.GetTable("IT_ITEM");
  434. foreach (DataRow dr in dtTable.Rows)
  435. {
  436. imTable.Append();
  437. imTable.SetValue("BLDAT", BLDAT);
  438. imTable.SetValue("BUDAT", BLDAT);
  439. imTable.SetValue("WERKS", "5020");
  440. imTable.SetValue("LGORT_FM", "2205");
  441. imTable.SetValue("LGORT_TO", "1103");
  442. imTable.SetValue("MATNR", dr["MATNR"]);
  443. imTable.SetValue("CHARG", dr["CHARG"] + "");
  444. imTable.SetValue("BWART", "311");
  445. imTable.SetValue("MEINS", dr["MEINS"]);
  446. imTable.SetValue("MENGE", dr["MENGE"]);
  447. imTable.SetValue("ZDKNO", ZDKNO);
  448. }
  449. //调用接口
  450. rfcApi.Invoke(rfcDest);
  451. //获取输出
  452. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  453. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  454. IRfcTable table = rfcApi.GetTable("ET_RETURN");
  455. DataTable dt = GetDataTableFromRFCTable(table);
  456. rfcDest = null;
  457. rfcRep = null;
  458. return dt;
  459. }
  460. /// <summary>
  461. /// IRfcTable转DataTable
  462. /// </summary>
  463. /// <param name="myrfcTable"></param>
  464. /// <returns></returns>
  465. private static DataTable GetDataTableFromRFCTable(IRfcTable myrfcTable)
  466. {
  467. DataTable loTable = new DataTable();
  468. int liElement = 0;
  469. for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++)
  470. {
  471. RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement);
  472. loTable.Columns.Add(metadata.Name);
  473. }
  474. foreach (IRfcStructure Row in myrfcTable)
  475. {
  476. DataRow ldr = loTable.NewRow();
  477. for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++)
  478. {
  479. RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement);
  480. ldr[metadata.Name] = Row.GetString(metadata.Name);
  481. }
  482. loTable.Rows.Add(ldr);
  483. }
  484. return loTable;
  485. }
  486. }