SAP MIR7预制发票删除和MIRO发票冲销(MR8M)

MIR7预制发票删除:BAPI_INCOMINGINVOICE_DELETE

MR8M发票冲销:BAPI_INCOMINGINVOICE_CANCEL

代码示例:

1. 预制发票删除

lv_inv = belnr.
    lv_year = gjahr.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = lv_inv
      IMPORTING
        output = lv_inv.

    CALL FUNCTION 'BAPI_INCOMINGINVOICE_DELETE'
      EXPORTING
        invoicedocnumber = lv_inv
        fiscalyear       = lv_year
      TABLES
        return           = lt_return.
    READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
    IF sy-subrc = 0.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

      return = ls_return.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.

      return-type = 'S'.
      CONCATENATE '预制发票' lv_inv lv_year '删除成功.' INTO return-message.
    ENDIF.

2. MIRO发票冲销

lv_doc = belnr.
    lv_nd = gjahr.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = lv_doc
      IMPORTING
        output = lv_doc.

    IF reasonreversal = '03'.
      CALL FUNCTION 'BAPI_INCOMINGINVOICE_CANCEL'
        EXPORTING
          invoicedocnumber          = lv_doc
          fiscalyear                = lv_nd
          reasonreversal            = reasonreversal
*         postingdate               = postingdate
        IMPORTING
          invoicedocnumber_reversal = lv_rdoc
          fiscalyear_reversal       = lv_rnd
        TABLES
          return                    = lt_return.
    ELSEIF reasonreversal = '04'.
      IF postingdate IS INITIAL.
        postingdate = sy-datum.
      ENDIF.

      CALL FUNCTION 'BAPI_INCOMINGINVOICE_CANCEL'
        EXPORTING
          invoicedocnumber          = lv_doc
          fiscalyear                = lv_nd
          reasonreversal            = reasonreversal
          postingdate               = postingdate
        IMPORTING
          invoicedocnumber_reversal = lv_rdoc
          fiscalyear_reversal       = lv_rnd
        TABLES
          return                    = lt_return.
    ENDIF.

    IF lv_rdoc IS NOT INITIAL AND lv_rnd IS NOT INITIAL.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.

      return-type = 'S'.
      CONCATENATE '发票' lv_doc lv_nd '冲销成功.' INTO return-message.

      invoice_doc_reversal = lv_rdoc. "生成的冲销凭证号
      fiscalyear_reversal = lv_rnd. "生成的冲销年度
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

      READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
      IF sy-subrc = 0.
        return = ls_return.
      ENDIF.
    ENDIF.

你可能感兴趣的:(sap,abap)