SapApi.cs 21 KB

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