SapApi.cs 21 KB

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