FB08 会计凭证冲销

BAPI冲不了object typeAWTYP BKPF的凭证,参考note 1799990

所以用BDC

 

BDC DEMO

        perform frm_bdc_init.

        perform frm_bdc_dynnr using 'SAPMF05A' '0105'.

        perform frm_bdc_field using space 'RF05A-BELNS' t_data-belnr.

        perform frm_bdc_field using space 'BKPF-BUKRS' t_data-bukrs.

        perform frm_bdc_field using space 'RF05A-GJAHS' t_data-gjahr.

        perform frm_bdc_field using space 'UF05A-STGRD' '01'. "冲销原因

        perform frm_bdc_field using space 'BDC_OKCODE' '=BU'.

        perform frm_bdc_call using 'FB08' changing t_data-rtype l_msgtext.

        t_data-rtmsg = t_data-rtmsg && '冲销凭证' && t_data-belnr && l_msgtext.

        read table gt_messtab with key msgtyp = 'S' msgid = 'F5' msgnr = '312'.

        if sy-subrc = 0.

          t_data-belnr_fb08 = gt_messtab-msgv1.

        endif.

 

BAPI DEMO

*        data: ls_bkpf type bkpf.

*        data: l_msgtext(255).

*        data: l_bapiacrev type bapiacrev.

*        data: l_bus_act type glvor.

*        data: lt_return type standard table of bapiret2.

*        data: ls_return type bapiret2.

 

        clear ls_bkpf.

        select single * into ls_bkpf from bkpf where bukrs = t_data-bukrs

          and gjahr = t_data-gjahr

          and belnr = t_data-belnr.

        "给 BAPI 函数相应的参数赋值

        clear l_bapiacrev.

        l_bapiacrev-obj_type     = ls_bkpf-awtyp.

        l_bapiacrev-obj_key      = ls_bkpf-awkey.

        l_bapiacrev-obj_key_r    = ls_bkpf-awkey.

        l_bapiacrev-pstng_date   = ls_bkpf-budat.

        l_bapiacrev-fis_period   = ls_bkpf-monat.

        l_bapiacrev-comp_code    = ls_bkpf-bukrs.

*  l_bapiacrev-ac_doc_no    = ls_bkpf-belnr.

        l_bapiacrev-reason_rev   = '03'.

        clear l_bus_act.

        l_bus_act = ls_bkpf-glvor.

        "取得系统 LOGICAL SYSTEM

        call function 'OWN_LOGICAL_SYSTEM_GET'

          importing

            own_logical_system = l_bapiacrev-obj_sys.

        " 调用 BAPI 函数,冲销会计凭证

        refresh lt_return.

        set update task local.

        call function 'BAPI_ACC_DOCUMENT_REV_POST'

          exporting

            reversal = l_bapiacrev

            bus_act  = l_bus_act

          tables

            return   = lt_return_rev.

 

        read table lt_return_rev into data(ls_return_rev) with key type = 'E'.

        if sy-subrc ne 0.

          call function 'BAPI_TRANSACTION_COMMIT'

            exporting

              wait = 'X'.

          t_data-rtype = 'S'.

        else.

          t_data-rtype = 'E'.

        endif.

 

        clear l_msgtext.

        call function 'TB_MESSAGE_BUILD_TEXT'

          exporting

            langu = sy-langu

            msgid = sy-msgid

            msgno = sy-msgno

            msgv1 = sy-msgv1

            msgv2 = sy-msgv2

            msgv3 = sy-msgv3

            msgv4 = sy-msgv4

          importing

            text  = l_msgtext.

 

        concatenate t_data-rtmsg '冲销凭证' t_data-belnr l_msgtext into t_data-rtmsg.

 

猜你喜欢

转载自blog.csdn.net/cylcylcylcylwo/article/details/113968188