接上一篇。
1.如何根据PO单号获取PO内容?
SAP有自带的bapi(BAPI_PO_GET_LIST)来获取PO详细内容;也可以自己写一个RFC来获取PO内容。我这边嫌自带的BAPI内容太多了,就自己写了一个:ZGET_PO_DETAILS 代码如下:
FUNCTION ZGET_PO_DETAILS. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(PONUMBER) TYPE EBELN *" TABLES *" PO_HEADER STRUCTURE ZPOHEADER *" PO_DETAIL STRUCTURE ZPODETAIL *"---------------------------------------------------------------------- TABLES EKKO . TABLES EKPO . DATA:BEGIN OF T_EKKO OCCURS 0. INCLUDE STRUCTURE ZPOHEADER. DATA:END OF T_EKKO. DATA: BEGIN OF T_EKPO OCCURS 0. INCLUDE STRUCTURE ZPODETAIL . DATA:END OF T_EKPO. DATA : AMT TYPE P DECIMALS 2 VALUE '0' . SELECT * INTO CORRESPONDING FIELDS OF TABLE T_EKKO FROM EKKO WHERE EBELN = PONUMBER . SELECT * INTO CORRESPONDING FIELDS OF TABLE T_EKPO FROM EKPO WHERE EBELN = PONUMBER . LOOP AT T_EKPO . AMT = AMT + ( T_EKPO-NETPR * T_EKPO-MENGE ). APPEND T_EKPO TO PO_DETAIL . ENDLOOP. LOOP AT T_EKKO . CLEAR:PO_HEADER. T_EKKO-AMT = AMT . SELECT SINGLE NAME1 INTO T_EKKO-NAME1 FROM LFA1 WHERE LIFNR = T_EKKO-LIFNR . APPEND T_EKKO TO PO_HEADER . ENDLOOP. TRANSPORTING AMT . ENDFUNCTION.
2.工作流中怎样调用RFC?
调用界面很简单,也很容易搞定,如图:
调用RFC代码:
SapRFCHelper srh = new SapRFCHelper(); string PONO = TEBELN.Text.ToString(); string[] param = { "PONUMBER|" + PONO }; DataTable dtD = srh.GetRfcOutTable("SAPDevConn", param, "ZGET_PO_DETAILS", "PO_DETAIL"); Store_F_PODETAIL.DataSource = dtD; Store_F_PODETAIL.DataBind();
3.领导审批后,如何在SAP中也审批?
在领导审批后,我们可以调用SAP自带的标准BAPI(BAPI_PO_RELEASE)来实现PO审批功能,我们只要传递相应的参数进去就好了。
调用代码如下:
//审批po protected bool ApprovePO() { bool pass = true; SapRFCHelper srh = new SapRFCHelper(); string PONO = TEBELN.Text.Trim(); string[] param = { "PURCHASEORDER|" + PONO, "PO_REL_CODE|07", "USE_EXCEPTIONS|X", "NO_COMMIT|" }; DataTable dt = srh.GetRfcOutTable("SAPDevConn", param, "BAPI_PO_RELEASE","RETURN"); if (dt.Rows.Count > 0) { if (dt.Rows[0][0].ToString() == "E") { pass = false; string msg = dt.Rows[0]["CODE"].ToString() + dt.Rows[0]["MESSAGE"].ToString(); X.MessageBox.Alert("提示:", "审批不成功,原因:" + msg).Show(); } } return pass; }
给个PO图片:
工作流运行图片: