SAP ABAP 采购订单审批BAPI_PO_RELEASE
*&---------------------------------------------------------------------*
*& 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
*& 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