SAP 凭证冲销可以使用BAPI_ACC_DOCUMENT_REV_POST或者BDC录制FB08来做

凭证冲销可以使用BAPI_ACC_DOCUMENT_REV_POST或者BDC录制FB08来做,效果相同

本文介绍使用BAPI_ACC_DOCUMENT_REV_POST做冲销凭证

部分代码实现:
@---------------------------------------------------------------------
*@ BAPI函数用到的变量
DATA: wa_bapidochdrr TYPE bapiacrev,
gt_return TYPE TABLE OF bapiret2 WITH HEADER LINE.
LOOP AT gt_bkpf ASSIGNING WHERE xreversal = ‘’.

  • 给 BAPI 函数相应的参数赋值
    wa_bapidochdrr-obj_type = -awtyp.
    wa_bapidochdrr-obj_key = -awkey.
    wa_bapidochdrr-obj_key_r = -awkey.
    wa_bapidochdrr-pstng_date = -budat.
    wa_bapidochdrr-fis_period = -monat.
    wa_bapidochdrr-comp_code = -bukrs.
    wa_bapidochdrr-ac_doc_no = -belnr.
    wa_bapidochdrr-reason_rev = ‘03’.

  • 取得系统 LOGICAL SYSTEM
    CALL FUNCTION ‘OWN_LOGICAL_SYSTEM_GET’
    IMPORTING
    own_logical_system = wa_bapidochdrr-obj_sys.

  • 调用 BAPI 函数,冲销会计凭证
    CALL FUNCTION ‘BAPI_ACC_DOCUMENT_REV_POST’

  •  EXPORTING
    
  •    obj_type = gv_glvor
    EXPORTING
      reversal = wa_bapidochdrr
      bus_act  = -glvor
    TABLES
      return   = gt_return.
    

    READ TABLE gt_return WITH KEY type = ‘E’.
    IF sy-subrc NE 0.

  • 提交凭证过账
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait   = 'X'
      IMPORTING
        return = i_return.
    
    
    IF i_return IS INITIAL.
      APPEND LINES OF gt_return TO gt_info.
      MESSAGE '会计凭证过账成功' TYPE 'S'.
    ELSE.
      APPEND i_return TO gt_info.
      CLEAR: i_return-number, i_return-id.
      i_return-type = 'E'.
      i_return-message = '过账失败,请用事务代码ST22查看详细信息'.
      APPEND i_return TO gt_info.
      MESSAGE '会计凭证过账失败' TYPE 'E'.
    ENDIF.
    

    ELSE.
    CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.

  • 将返回信息添加到结果信息内表
    APPEND LINES OF gt_return TO gt_info.
    ENDIF.

你可能感兴趣的:(SAP)