*&---------------------------------------------------------------------*
*& Form frm_release_po
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> <LFS_ALV_W>_EBELN
*&---------------------------------------------------------------------*
FORM frm_release_po USING u_ebeln TYPE ekko-ebeln.
DATA:lv_rel_code LIKE bapimmpara-rel_code.
DATA:lt_return TYPE TABLE OF bapireturn,
ls_return TYPE bapireturn.
DATA:lv_str TYPE string,lv_offset TYPE i.
DATA:BEGIN OF ls_grp,
frgco TYPE t16fc-frgco,
END OF ls_grp,
lt_grp LIKE TABLE OF ls_grp.
FIELD-SYMBOLS:<lfs_v1> TYPE any.
* 获取采购订单的审批代码
* 根据PO获取审批组和审批策略,然后获取审批级别代码
SELECT k~ebeln,k~frgzu,s~frgc1,s~frgc2,s~frgc3,s~frgc4,
s~frgc5,s~frgc6,s~frgc7,s~frgc8
FROM t16fs AS s
INNER JOIN ekko AS k
ON k~frggr = s~frggr
AND k~frgsx = s~frgsx
WHERE k~ebeln = @u_ebeln
AND k~frgrl = @abap_true "FRGRL 字段标示审批是否结束
INTO TABLE @DATA(lt_t16fs).
READ TABLE lt_t16fs ASSIGNING FIELD-SYMBOL(<lfs_t16fs>) INDEX 1.
IF sy-subrc EQ 0.
DO 8 TIMES.
lv_str = sy-index.
lv_str = 'FRGC' && lv_str.
CONDENSE lv_str NO-GAPS.
ASSIGN COMPONENT lv_str OF STRUCTURE <lfs_t16fs> TO <lfs_v1>.
IF sy-subrc EQ 0.
IF <lfs_v1> IS NOT INITIAL.
DATA(lv_x) = <lfs_t16fs>-frgzu+lv_offset(1).
IF lv_x IS INITIAL."未审批
ls_grp-frgco = <lfs_v1>.
APPEND ls_grp TO lt_grp.
ENDIF.
ENDIF.
ENDIF.
lv_offset = lv_offset + 1.
ENDDO.
CLEAR lv_str.
ENDIF.
* 循环审批码将PO逐级release
* 调用BAPI审批PO
LOOP AT lt_grp INTO ls_grp.
CALL FUNCTION 'BAPI_PO_RELEASE'
EXPORTING
purchaseorder = u_ebeln
po_rel_code = ls_grp-frgco
TABLES
return = lt_return.
LOOP AT lt_return INTO ls_return
WHERE type = 'E' OR type = 'A'.
lv_str = lv_str && '|' && ls_return-message.
DATA(lv_flag) = abap_true.
ENDLOOP.
SHIFT lv_str LEFT DELETING LEADING '|'.
IF lv_flag EQ abap_true.
EXIT.
ENDIF.
WAIT UP TO 1 SECONDS.
ENDLOOP.
IF lv_flag EQ abap_true."失败
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE."成功
ENDIF.
ENDFORM.
SAP ABAP 采购订单审批BAPI_PO_RELEASE
最新推荐文章于 2024-05-17 20:49:17 发布
本文介绍了一个使用ABAP编程语言实现的采购订单(PO)分层级审批流程。通过查询审批组和策略来确定审批代码,并利用BAPI接口逐级完成采购订单的审批过程。该文涉及ABAP数据操作、条件判断及接口调用等关键技术。
摘要由CSDN通过智能技术生成