冲销凭证BAPI_ACC_DOCUMENT_REV_POST封装FUNCTION

FM: ZF_FI_ACC_DOC_REV_POST

FUNCTION ZF_FI_ACC_DOC_REV_POST.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     REFERENCE(IV_BUKRS) TYPE  BKPF-BUKRS
*"     REFERENCE(IV_BELNR) TYPE  BKPF-BELNR
*"     REFERENCE(IV_GJAHR) TYPE  BKPF-GJAHR
*"     REFERENCE(IV_STGRD) TYPE  BKPF-STGRD DEFAULT '04'
*"  EXPORTING
*"     REFERENCE(OV_BELNR_CX) TYPE  BKPF-BELNR
*"     REFERENCE(OV_GJAHR_CX) TYPE  BKPF-GJAHR
*"     REFERENCE(OV_MESSAGE) TYPE  STRING
*"----------------------------------------------------------------------

  DATA: LV_LGO_SYS    TYPE TBDLS-LOGSYS.

  DATA: LS_REVERSAL TYPE BAPIACREV,
        LV_BUS_ACT  TYPE BAPIACHE09-BUS_ACT,
        LV_OBJ_KEY  TYPE BAPIACREV-OBJ_KEY,
        LT_RETURN   TYPE STANDARD TABLE OF BAPIRET2.

  "Get logical system
  CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
    IMPORTING
      OWN_LOGICAL_SYSTEM             = LV_LGO_SYS
    EXCEPTIONS
      OWN_LOGICAL_SYSTEM_NOT_DEFINED = 1
      OTHERS                         = 2.

  SELECT SINGLE
    AWTYP,
    AWKEY,
    BUDAT,
    MONAT,
    GLVOR
    INTO @DATA(LS_BKPF)
    FROM BKPF
    WHERE BUKRS = @IV_BUKRS
    AND   BELNR = @IV_BELNR
    AND   GJAHR = @IV_GJAHR.


  LS_REVERSAL = VALUE #(
    OBJ_TYPE   = LS_BKPF-AWTYP
    OBJ_KEY    = LS_BKPF-AWKEY
    OBJ_SYS    = LV_LGO_SYS
    OBJ_KEY_R  = LS_BKPF-AWKEY
    PSTNG_DATE = LS_BKPF-BUDAT
    "FIS_PERIOD = LS_BKPF-MONAT
    COMP_CODE  = IV_BUKRS
    "AC_DOC_NO  = LS_OUT-BELNR
    REASON_REV = IV_STGRD ).

  LV_BUS_ACT = LS_BKPF-GLVOR.

  CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_CHECK'
    EXPORTING
      REVERSAL = LS_REVERSAL
      BUS_ACT  = LV_BUS_ACT
    TABLES
      RETURN   = LT_RETURN.

  LOOP AT LT_RETURN INTO DATA(LS_RETURN) WHERE TYPE CA 'AEX'.
    OV_MESSAGE =
      COND #( WHEN OV_MESSAGE = SPACE THEN LS_RETURN-MESSAGE
              ELSE |{ OV_MESSAGE }/{ LS_RETURN-MESSAGE }| ).
  ENDLOOP.

  IF OV_MESSAGE IS NOT INITIAL.
    RETURN.
  ENDIF.

  CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_POST'
    EXPORTING
      REVERSAL = LS_REVERSAL
      BUS_ACT  = LV_BUS_ACT
    IMPORTING
*     OBJ_TYPE =
      OBJ_KEY  = LV_OBJ_KEY
*     OBJ_SYS  =
    TABLES
      RETURN   = LT_RETURN.

  LOOP AT LT_RETURN INTO LS_RETURN WHERE TYPE CA 'AEX'.
    OV_MESSAGE =
      COND #( WHEN OV_MESSAGE = SPACE THEN LS_RETURN-MESSAGE
              ELSE |{ OV_MESSAGE }/{ LS_RETURN-MESSAGE }| ).
  ENDLOOP.

  IF SY-SUBRC NE 0.
    OV_BELNR_CX = LV_OBJ_KEY(10).
    OV_GJAHR_CX = LV_OBJ_KEY+14(4).

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT = 'X'.
  ENDIF.

ENDFUNCTION.

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王小磊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值