Wednesday, March 18, 2020

Implement BADI BADI_ACC_DOCUMENT for Enabling Parameter Extension2 .

Implement BADI BADI_ACC_DOCUMENT for Enabling Parameter Extension2 in BAPI_ACC_DOCUMENT_POST.


Implement BADI BADI_ACC_DOCUMENT.




BAPI_ACC_DOCUMENT_POST is meanly used to create FI documents like as GL, AP, and AR (TCode F-02). This BAPI, there are EXTENTION2 table parameters that can be used to throw data for which fields are not provided by BAPI BAPI_ACC_DOCUMENT_POST, such as the Ref field. Key 1 Header (BKPF-XREF1_HD), or even for the need to change the key post from the journal to be made.

However, this EXTENTION2 parameter will only function if BADI_ACC_DOCUMENT has been implemented. Following are the steps for implementing BADI_ACC_DOCUMENT:

Copy class CL_EXM_IM_ACC_DOCUMENT to custome class YCL_EXM_IM_ACC_DOCUMENT via SE24. Activate.
Run TCode SE19 and create BADI_ACC_DOCUMENT in the Create Implementation >> New BAdI section.

Write the name of the BAdI Enhancement Implementation along with the Composite Enhancement Implementation (if there is no composite yet, create it first.


• Enter the name of the BAdI custome in step 3 and the name of the custom class in step 1, and select the name BAdI Definitioan = BADI_ACC_DOCUMENT.

1.Save & Activate.



1.On the Technical Tab, double click the custom class for BAdI custom coding according to the requirement.



1.Double click the ~ CHANGE method to start coding.

  • Save & Activate
  • ABAP program, the passing parameter extension2 is as follows


  DATA:  ld_header LIKE bapiache09,
         ld_objkey LIKE bapiache09-obj_key,
         lt_gl     LIKE bapiacgl09 OCCURS 0 WITH HEADER LINE,
         lt_ap     LIKE bapiacap09 OCCURS 0 WITH HEADER LINE,
         lt_amt    LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE,
         lt_ext    LIKE bapiparex OCCURS 0 WITH HEADER LINE,
         lt_ret    LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
         ld_itemno LIKE bapiacgl09-itemno_acc,

  CONSTANT: c_struct TYPE TE_STRUC VALUE 'XREF1_HD'.

    CLEAR lt_ext.
    ADD 1 TO ld_itemno.
    lt_ext-structure   = c_struct.
    lt_ext-valuepart1  = ld_itemno.
    lt_ext-valuepart2  = 'Test Ref Key Header'.
    APPEND lt_ext.

    CLEAR lt_ext.
    ADD 1 TO ld_itemno.
    lt_ext-structure   = c_struct.
    lt_ext-valuepart1  = ld_itemno.
    lt_ext-valuepart2  = 'Test Ref Key Header'.
    APPEND lt_ext.

*isi parameter ld_header, lt_gl, lt_amt sesuai requirement.
    CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
      EXPORTING
        documentheader = ld_header
      IMPORTING
        obj_key        = ld_objkey
      TABLES
        accountgl      = lt_gl
        accountpayable = lt_ap
        currencyamount = lt_amt
        return         = lt_ret
        extension2     = lt_ext
      EXCEPTIONS
        OTHERS         = 1.

    IF ld_objkey IS INITIAL OR ld_objkey EQ '$'.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ENDIF.
 The CHANGE method does the following coding:
  DATA: wa_extension   TYPE bapiparex,
        wa_accit       TYPE accit,
        ld_posnr       TYPE posnr_acc.

  LOOP AT c_extension2 INTO wa_extension.
    ld_posnr = wa_extension-valuepart1.
    READ TABLE c_accit WITH KEY posnr = ld_posnr
          INTO wa_accit.
    IF sy-subrc IS INITIAL.
      IF wa_extension-structure = 'XREF1_HD'.
        wa_accit-xref1_hd = wa_extension-valuepart2.
        MODIFY c_accit FROM wa_accit index sy-tabix TRANSPORTING xref1_hd.
      ENDIF.
    ENDIF.
  ENDLOOP.




No comments:

Post a Comment