ABAP 采购申请反审批/取消审批BAPI_REQUISITION_RESET_REL_GEN

*&---------------------------------------------------------------------*
*& Form frm_reject_pr
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> PS_HEAD
*&      <-- PS_RETINFO
*&---------------------------------------------------------------------*
FORM frm_reject_pr  USING    ps_head      TYPE  zmms035
                    CHANGING ps_retinfo   TYPE  zmms037.

  DATA: lv_number   TYPE bapi2009ob-preq_no,
        lv_rel_code TYPE bapimmpara-rel_code,
        lt_return   TYPE TABLE OF bapireturn,
        ls_return   TYPE bapireturn,
        lv_subrc    TYPE sy-subrc.

  lv_number = ps_head-banfn.  " 采购申请编号  EBAN-BANFN
  lv_rel_code = 'SA'.         " 采购申请批准代码  T16FC-FRGCO

  SELECT SINGLE
    frgkz
  FROM eban
  WHERE
    banfn = @ps_head-banfn
  INTO @DATA(lv_frgkz).
  IF sy-subrc = 0 AND lv_frgkz = gc_b.  " 此时尚未审批
    ps_retinfo-code     = gc_e.
    ps_retinfo-message  = TEXT-m20. " 采购申请尚未审批,请先审批;
    EXIT.
  ENDIF.

  "采购申请取消审批
  CALL FUNCTION 'BAPI_REQUISITION_RESET_REL_GEN'
    EXPORTING
      number   = lv_number
      rel_code = lv_rel_code
    TABLES
      return   = lt_return.

  lv_subrc = sy-subrc.
  LOOP AT lt_return INTO ls_return WHERE type CA 'AEX'.
"    ps_retinfo-code     = gc_e.
"    ps_retinfo-message  = ps_retinfo-message && ls_return-message.
  ENDLOOP.
  IF sy-subrc = 0 OR lv_subrc NE 0.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = abap_true.
    WAIT UP TO '0.5' SECONDS.
  ENDIF.

ENDFORM.

你可能感兴趣的:(ABAP,采购申请,SAP,BAPI)