ABAP 采购申请审批BAPI_REQUISITION_RELEASE_GEN

*&---------------------------------------------------------------------*
*& Form frm_approve_pr
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> PS_HEAD
*&      <-- PS_RETINFO
*&---------------------------------------------------------------------*
FORM frm_approve_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_retinfo-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_r.  " 已批准则无需再批
    ps_retinfo-code     = gc_s.
    ps_retinfo-message  = TEXT-m19. " 采购申请已审批,请勿重复审批
    EXIT.
  ENDIF.

  "采购申请审批
  CALL FUNCTION 'BAPI_REQUISITION_RELEASE_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,BAPI,SAP,采购申请)