1,BAPI简介
可以使用BAPI_REQUISITION_RELEASE_GEN对采购申请进行整体的审批,也就是说,无论采购申请有多少行项目,使用此BAPI可以统一审批。
<img class="alignnone size-full wp-image-6158" src="//pic.ikafan.com/imgp/L3Byb3h5L2h0dHAvd3d3LmJhaWR1c2FwLmNvbS93cC1jb250ZW50L3VwbG9hZHMvMjAxOS0wNS0wNV8xMS0yMy0xNS5qcGc=.jpg" width="702" height="273" />
BAPI中的采购申请的审批代码(rel_code),可以从T16FC-FRGCO中读取
<img class="alignnone size-full wp-image-6159" src="//pic.ikafan.com/imgp/L3Byb3h5L2h0dHAvd3d3LmJhaWR1c2FwLmNvbS93cC1jb250ZW50L3VwbG9hZHMvMjAxOS0wNS0wNV8xMy0yMi0yOS5qcGc=.jpg" width="673" height="316" />
2,例子代码
写一个简单的例子代码,实现PR的审批组下逐级审批功能。
Note:eban-frgrl = ‘X‘标识采购申请没有审批完成。
REPORT ytest_pr_release. DATA: BEGIN OF ls_grp, frggr TYPE t16fc-frggr, "审批组 frgco TYPE t16fc-frgco, "审批代码 END OF ls_grp, lt_grp LIKE TABLE OF ls_grp, lt_return TYPE STANDARD TABLE OF bapireturn, ls_return TYPE bapireturn. PARAMETERS:p_banfn TYPE eban-banfn. * 根据PR获得审批组,从而获取审批码 SELECT t16fc~frggr t16fc~frgco INTO TABLE lt_grp FROM eban INNER JOIN t16fc ON eban~frggr = t16fc~frggr "审批组 WHERE eban~banfn = p_banfn AND eban~frgrl = ‘X‘."FRGRL 字段标示审批是否结束(X未结束,需要审批, ‘’ 审批结束) * 循环审批码将PR逐级release SORT lt_grp BY frggr frgco. DELETE ADJACENT DUPLICATES FROM lt_grp COMPARING frggr frgco. LOOP AT lt_grp INTO ls_grp. CALL FUNCTION ‘BAPI_REQUISITION_RELEASE_GEN‘ EXPORTING number = p_banfn rel_code = ls_grp-frgco TABLES return = lt_return. LOOP AT lt_return INTO ls_return WHERE type = ‘A‘ OR type = ‘E‘ OR type = ‘X‘. * * MESSAGE ls_return-message TYPE ‘S‘ DISPLAY LIKE ‘E‘. * STOP. ENDLOOP. ENDLOOP. MESSAGE ‘审批完毕,请通过ME53N查看审批结果‘ TYPE ‘S‘.
3,简单测试
随便找一个有2个行项目的未审批完成PR,me53n查看一下各个行项目的审批状态,
10行,有两级审批-00,01,其中第一级00已经审批通过,
<img class="alignnone size-medium wp-image-6160" src="//pic.ikafan.com/imgp/L3Byb3h5L2h0dHAvd3d3LmJhaWR1c2FwLmNvbS93cC1jb250ZW50L3VwbG9hZHMvMjAxOS0wNS0wNV8xMy0yOS01MC03NDB4NTQwLmpwZw==.jpg" width="740" height="540" srcset="http://www.baidusap.com/wp-content/uploads/2019-05-05_13-29-50-740x540.jpg 740w, http://www.baidusap.com/wp-content/uploads/2019-05-05_13-29-50-768x561.jpg 768w, http://www.baidusap.com/wp-content/uploads/2019-05-05_13-29-50.jpg 956w" sizes="(max-width: 740px) 100vw, 740px" />
20行,2级审批全没有批准,
<img class="alignnone size-medium wp-image-6161" src="//pic.ikafan.com/imgp/L3Byb3h5L2h0dHAvd3d3LmJhaWR1c2FwLmNvbS93cC1jb250ZW50L3VwbG9hZHMvMjAxOS0wNS0wNV8xMy0zMS0yOC03NDB4NTMxLmpwZw==.jpg" width="740" height="531" srcset="http://www.baidusap.com/wp-content/uploads/2019-05-05_13-31-28-740x531.jpg 740w, http://www.baidusap.com/wp-content/uploads/2019-05-05_13-31-28-768x551.jpg 768w, http://www.baidusap.com/wp-content/uploads/2019-05-05_13-31-28.jpg 913w" sizes="(max-width: 740px) 100vw, 740px" />
运行程序后,PR各个行项目的2级审批应该全部批准。
<img class="alignnone size-full wp-image-6162" src="//pic.ikafan.com/imgp/L3Byb3h5L2h0dHAvd3d3LmJhaWR1c2FwLmNvbS93cC1jb250ZW50L3VwbG9hZHMvMjAxOS0wNS0wNV8xMy0zNy0yMS5qcGc=.jpg" width="650" height="198" />
<img class="alignnone size-full wp-image-6163" src="//pic.ikafan.com/imgp/L3Byb3h5L2h0dHAvd3d3LmJhaWR1c2FwLmNvbS93cC1jb250ZW50L3VwbG9hZHMvMjAxOS0wNS0wNV8xMy0zOC0wMi5qcGc=.jpg" width="664" height="199" />
PR凭证可以通过ME54N重置审批状态。
以上。
原文地址:https://www.cnblogs.com/datie/p/11429138.html