FUNCTION MODULE – REVERSAL DOCUMENT NUMBER WITH BAPI_ACC_DOCUMENT_REV_POST FB08 SOURCE CODE

   

Reversal Document Number digunakan untuk data FI yang terlanjur posting di SAP namun datanya salah. Secara standard SAP, untuk mengcancel data yang salah disebut juga Reversal / Pembalikan nilai, dan bisa menggunakan tcode FB08 dengan menginputkan nomor dokumen ([1] Document Number) , kode perusahaan ([2] Company Code), tahun ([3] Fiscal Year) dan Alasan pembatalan ([4] Reversal Reason), contohnya adalah sebagai berikut:

Secara teknikal Abap, jika kita ingin membuat program reversal document bisa menggunakan sample code berikut ini:

FORM cancel_doc USING u_belnr TYPE bkpf-belnr
                      u_gjahr TYPE bkpf-gjahr
                      u_bukrs TYPE bkpf-bukrs
                      u_key   TYPE c.
  DATA: ls_bkpf TYPE bkpf,
        ls_reversal LIKE  bapiacrev,
        lt_return TYPE TABLE OF  bapiret2 WITH HEADER LINE,
        ld_message TYPE c LENGTH 200,
        ls_t000 TYPE t000.
  SELECT SINGLE * FROM bkpf
    INTO ls_bkpf
    WHERE belnr = u_belnr AND gjahr = u_gjahr AND bukrs = u_bukrs.
  IF sy-subrc = 0.
    SELECT SINGLE * FROM t000
      INTO ls_t000
      WHERE mandt = sy-mandt.
    IF sy-subrc = 0.
      CONCATENATE ls_bkpf-belnr ls_bkpf-bukrs ls_bkpf-gjahr INTO ls_reversal-obj_key.
      ls_reversal-reason_rev = '02'.
      ls_reversal-pstng_date = sy-datum.
      ls_reversal-obj_sys = ls_t000-logsys.
      ls_reversal-obj_type = ' BKPFF'.
      ls_reversal-obj_key_r = ls_reversal-obj_key.
      CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_CHECK'
        EXPORTING
          reversal = ls_reversal
          bus_act  = 'RFBU'
        TABLES
          return   = lt_return.
      IF sy-subrc = 0.
        CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_POST'
          EXPORTING
            reversal = ls_reversal
            bus_act  = 'RFBU'
          TABLES
            return   = lt_return.
        IF sy-subrc = 0.
          ld_message = ''.
          LOOP AT lt_return.
            CONCATENATE lt_return-message  lt_return-message_v1 INTO ld_message.
          ENDLOOP.
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
          MESSAGE ld_message TYPE 'I'.
        ELSE.
          ld_message = ''.
          LOOP AT lt_return.
            CONCATENATE lt_return-message  lt_return-message_v1 INTO ld_message.
          ENDLOOP.
          MESSAGE ld_message TYPE 'E'.
        ENDIF.
      ENDIF.
    ELSE.
      MESSAGE 'Data tidak ada di T000 (Logical System)' TYPE 'E'.
    ENDIF.
  ELSE.
    MESSAGE 'Data tidak ada di BKPF' TYPE 'E'.
  ENDIF.
ENDFORM.

Panggil subrutin tersebut dengan menambah PERFORM seperti contoh dibawah ini:

DATA: LD_belnr TYPE bkpf-belnr,
      LD_gjahr TYPE bkpf-gjahr,
      LD_bukrs TYPE bkpf-bukrs,
      LD_key TYPE c.
LD_belnr = '4600000249'.
LD_gjahr = '2700'.
LD_bukrs = '2020'.
LD_key = '1'.
PERFORM cancel_doc USING LD_belnr LD_gjahr LD_bukrs LD_key.

Berikut merupakan source code lengkap program untuk melakukan pembatalan no. dokumen menggunakan BAPI :

DATA: LD_belnr TYPE bkpf-belnr,
      LD_gjahr TYPE bkpf-gjahr,
      LD_bukrs TYPE bkpf-bukrs,
      LD_key TYPE c.
LD_belnr = '4600000249'.
LD_gjahr = '2700'.
LD_bukrs = '2020'.
LD_key = '1'.
PERFORM cancel_doc USING LD_belnr LD_gjahr LD_bukrs LD_key.
 
FORM cancel_doc USING u_belnr TYPE bkpf-belnr
                      u_gjahr TYPE bkpf-gjahr
                      u_bukrs TYPE bkpf-bukrs
                      u_key   TYPE c.
  DATA: ls_bkpf TYPE bkpf,
        ls_reversal LIKE  bapiacrev,
        lt_return TYPE TABLE OF  bapiret2 WITH HEADER LINE,
        ld_message TYPE c LENGTH 200,
        ls_t000 TYPE t000.
  SELECT SINGLE * FROM bkpf
    INTO ls_bkpf
    WHERE belnr = u_belnr AND gjahr = u_gjahr AND bukrs = u_bukrs.
  IF sy-subrc = 0.
    SELECT SINGLE * FROM t000
      INTO ls_t000
      WHERE mandt = sy-mandt.
    IF sy-subrc = 0.
      CONCATENATE ls_bkpf-belnr ls_bkpf-bukrs ls_bkpf-gjahr INTO ls_reversal-obj_key.
      ls_reversal-reason_rev = '02'.
      ls_reversal-pstng_date = sy-datum.
      ls_reversal-obj_sys = ls_t000-logsys.
      ls_reversal-obj_type = ' BKPFF'.
      ls_reversal-obj_key_r = ls_reversal-obj_key.
      CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_CHECK'
        EXPORTING
          reversal = ls_reversal
          bus_act  = 'RFBU'
        TABLES
          return   = lt_return.
      IF sy-subrc = 0.
        CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_POST'
          EXPORTING
            reversal = ls_reversal
            bus_act  = 'RFBU'
          TABLES
            return   = lt_return.
        IF sy-subrc = 0.
          ld_message = ''.
          LOOP AT lt_return.
            CONCATENATE lt_return-message  lt_return-message_v1 INTO ld_message.
          ENDLOOP.
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
          MESSAGE ld_message TYPE 'I'.
        ELSE.
          ld_message = ''.
          LOOP AT lt_return.
            CONCATENATE lt_return-message  lt_return-message_v1 INTO ld_message.
          ENDLOOP.
          MESSAGE ld_message TYPE 'E'.
        ENDIF.
      ENDIF.
    ELSE.
      MESSAGE 'Data tidak ada di T000 (Logical System)' TYPE 'E'.
    ENDIF.
  ELSE.
    MESSAGE 'Data tidak ada di BKPF' TYPE 'E'.
  ENDIF.
ENDFORM.

Wahyu Amaldi, M.Kom has written 87 articles

Hi Reader, thank you for read this article, i hope this article can be useful.
If you will share knowladge to me, dont forget contact to me.

Email 1 : wahyu.amaldi@outlook.com
Email 2 : wahyu.amaldi@ilmuprogram.com

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>