SapApi.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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)
  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. //接口API
  249. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM054");
  250. //输入参数
  251. rfcApi.SetValue("IN_ALL", 'Y');
  252. rfcApi.SetValue("IN_WERKS", 5020);
  253. //调用接口
  254. rfcApi.Invoke(rfcDest);
  255. //获取输出
  256. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  257. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  258. IRfcTable table = rfcApi.GetTable("OUT_TABLE");
  259. DataTable dt = GetDataTableFromRFCTable(table);
  260. rfcDest = null;
  261. rfcRep = null;
  262. return dt;
  263. }
  264. /// <summary>
  265. /// 东科与SAP系统之线边仓库存领用接口(库存过账)
  266. /// </summary>
  267. /// <param name="BLDAT">过帐日期</param>
  268. /// <param name="ZDKNO">东科单据号</param>
  269. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  270. /// <param name="ZMSG">消息文本</param>
  271. /// <returns></returns>
  272. public static DataTable ZMMFM045(string BLDAT, string ZDKNO, DataTable dtTable, out string ZTYPE, out string ZMSG)
  273. {
  274. RfcConfigParameters rfcPara = new RfcConfigParameters();
  275. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  276. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  277. rfcPara.Add(RfcConfigParameters.User, user);
  278. rfcPara.Add(RfcConfigParameters.Password, password);
  279. rfcPara.Add(RfcConfigParameters.Client, client);
  280. rfcPara.Add(RfcConfigParameters.Name, "CON");
  281. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  282. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  283. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  284. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  285. RfcRepository rfcRep = rfcDest.Repository;
  286. //接口API
  287. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM045");
  288. //BLDAT DATS 8 0 必填 凭证日期 格式: yyyymmdd
  289. //BUDAT DATS 8 0 必填 过帐日期 格式: yyyymmdd
  290. //WERKS CHAR 4 0 必填 工厂 5020
  291. //LGORT_FM CHAR 4 0 必填 发出库位
  292. //LGORT_TO CHAR 4 0 必填 接收库位
  293. //MATNR CHAR 40 0 必填 物料编号
  294. //BWART CHAR 3 0 必填 移动类型(库存管理) 目前只允许填:311
  295. //MEINS UNIT 3 0 必填 基本计量单位
  296. //MENGE QUAN 13 3 必填 数量
  297. //ZDKNO CHAR 40 0 必填 东科单据号
  298. //输入参数
  299. IRfcTable imTable = rfcApi.GetTable("IT_ITEM");
  300. foreach (DataRow dr in dtTable.Rows)
  301. {
  302. imTable.Append();
  303. imTable.SetValue("BLDAT", BLDAT);
  304. imTable.SetValue("BUDAT", BLDAT);
  305. imTable.SetValue("WERKS", "5000");
  306. imTable.SetValue("LGORT_FM", dr["LGORT_FM"]);
  307. imTable.SetValue("LGORT_TO", dr["TOLOGT"]);
  308. imTable.SetValue("MATNR", dr["MATNR"]);
  309. imTable.SetValue("CHARG", dr["CHARG"] + "");
  310. imTable.SetValue("BWART", "311");
  311. imTable.SetValue("MEINS", dr["MEINS"]);
  312. imTable.SetValue("MENGE", dr["MENGE"]);
  313. imTable.SetValue("ZDKNO", ZDKNO);
  314. }
  315. //调用接口
  316. rfcApi.Invoke(rfcDest);
  317. //获取输出
  318. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  319. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  320. IRfcTable table = rfcApi.GetTable("ET_RETURN");
  321. DataTable dt = GetDataTableFromRFCTable(table);
  322. //string[] columns = new string[] { "BLDAT", "WERKS", "MBLNR", "MJAHR", "MSGTY", "MSGTX" };
  323. //DataTable dt = new DataTable();
  324. //foreach (string clmn in columns)
  325. //{
  326. // dt.Columns.Add(clmn);
  327. //}
  328. //for (int i = 0; i < table.RowCount; i++)
  329. //{
  330. // DataRow dr = dt.NewRow();
  331. // foreach (string clmn in columns)
  332. // {
  333. // dr[clmn] = table.GetString(clmn);
  334. // }
  335. // dt.Rows.Add(dr);
  336. //}
  337. rfcDest = null;
  338. rfcRep = null;
  339. return dt;
  340. }
  341. /// <summary>
  342. /// 冲销凭证接口(撤销过账)
  343. /// </summary>
  344. /// <param name="MBLNR">物料凭证编号</param>
  345. /// <param name="createTime">创建时间</param>
  346. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  347. /// <param name="ZMSG">消息文本</param>
  348. /// <returns></returns>
  349. public static void ZMMFM038(string MBLNR, DateTime createTime, out string ZTYPE, out string ZMSG)
  350. {
  351. RfcConfigParameters rfcPara = new RfcConfigParameters();
  352. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  353. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  354. rfcPara.Add(RfcConfigParameters.User, user);
  355. rfcPara.Add(RfcConfigParameters.Password, password);
  356. rfcPara.Add(RfcConfigParameters.Client, client);
  357. rfcPara.Add(RfcConfigParameters.Name, "CON");
  358. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  359. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  360. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  361. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  362. RfcRepository rfcRep = rfcDest.Repository;
  363. //接口API
  364. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM038");
  365. //输入参数
  366. rfcApi.SetValue("MBLNR", MBLNR);
  367. rfcApi.SetValue("MJAHR", createTime.ToString("yyyy"));
  368. rfcApi.SetValue("BUDAT", createTime.ToString("yyyyMMdd"));
  369. //调用接口
  370. rfcApi.Invoke(rfcDest);
  371. //获取输出
  372. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  373. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  374. rfcDest = null;
  375. rfcRep = null;
  376. }
  377. /// <summary>
  378. /// 测试用,用于把线边仓的货,全挪走
  379. /// </summary>
  380. /// <param name="BLDAT">过帐日期</param>
  381. /// <param name="ZDKNO">东科单据号</param>
  382. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  383. /// <param name="ZMSG">消息文本</param>
  384. /// <returns></returns>
  385. public static DataTable ZMMFM045_TEST(string BLDAT, string ZDKNO, DataTable dtTable, out string ZTYPE, out string ZMSG)
  386. {
  387. RfcConfigParameters rfcPara = new RfcConfigParameters();
  388. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  389. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  390. rfcPara.Add(RfcConfigParameters.User, user);
  391. rfcPara.Add(RfcConfigParameters.Password, password);
  392. rfcPara.Add(RfcConfigParameters.Client, client);
  393. rfcPara.Add(RfcConfigParameters.Name, "CON");
  394. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  395. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  396. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  397. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  398. RfcRepository rfcRep = rfcDest.Repository;
  399. //接口API
  400. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM045");
  401. //BLDAT DATS 8 0 必填 凭证日期 格式: yyyymmdd
  402. //BUDAT DATS 8 0 必填 过帐日期 格式: yyyymmdd
  403. //WERKS CHAR 4 0 必填 工厂 5020
  404. //LGORT_FM CHAR 4 0 必填 发出库位
  405. //LGORT_TO CHAR 4 0 必填 接收库位
  406. //MATNR CHAR 40 0 必填 物料编号
  407. //BWART CHAR 3 0 必填 移动类型(库存管理) 目前只允许填:311
  408. //MEINS UNIT 3 0 必填 基本计量单位
  409. //MENGE QUAN 13 3 必填 数量
  410. //ZDKNO CHAR 40 0 必填 东科单据号
  411. //输入参数
  412. IRfcTable imTable = rfcApi.GetTable("IT_ITEM");
  413. foreach (DataRow dr in dtTable.Rows)
  414. {
  415. imTable.Append();
  416. imTable.SetValue("BLDAT", BLDAT);
  417. imTable.SetValue("BUDAT", BLDAT);
  418. imTable.SetValue("WERKS", "5020");
  419. imTable.SetValue("LGORT_FM", "2205");
  420. imTable.SetValue("LGORT_TO", "1103");
  421. imTable.SetValue("MATNR", dr["MATNR"]);
  422. imTable.SetValue("CHARG", dr["CHARG"] + "");
  423. imTable.SetValue("BWART", "311");
  424. imTable.SetValue("MEINS", dr["MEINS"]);
  425. imTable.SetValue("MENGE", dr["MENGE"]);
  426. imTable.SetValue("ZDKNO", ZDKNO);
  427. }
  428. //调用接口
  429. rfcApi.Invoke(rfcDest);
  430. //获取输出
  431. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  432. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  433. IRfcTable table = rfcApi.GetTable("ET_RETURN");
  434. DataTable dt = GetDataTableFromRFCTable(table);
  435. rfcDest = null;
  436. rfcRep = null;
  437. return dt;
  438. }
  439. /// <summary>
  440. /// IRfcTable转DataTable
  441. /// </summary>
  442. /// <param name="myrfcTable"></param>
  443. /// <returns></returns>
  444. private static DataTable GetDataTableFromRFCTable(IRfcTable myrfcTable)
  445. {
  446. DataTable loTable = new DataTable();
  447. int liElement = 0;
  448. for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++)
  449. {
  450. RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement);
  451. loTable.Columns.Add(metadata.Name);
  452. }
  453. foreach (IRfcStructure Row in myrfcTable)
  454. {
  455. DataRow ldr = loTable.NewRow();
  456. for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++)
  457. {
  458. RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement);
  459. ldr[metadata.Name] = Row.GetString(metadata.Name);
  460. }
  461. loTable.Rows.Add(ldr);
  462. }
  463. return loTable;
  464. }
  465. }