How to pass Reversal Date & Reason to BAPI_ACC_DOCUMENT_POST?

How to pass Reversal Date & Reason to BAPI_ACC_DOCUMENT_POST?

Know How to pass Reversal Date & Reason to BAPI_ACC_DOCUMENT_POST? One motivation behind why the software engineer’s occupation is the most intriguing one is; you learn new stuff consistently. Regardless, whether you are a fresher or a designer with more than many years of involvement. Each and every other day, you find out about another grammar. You get to be familiar with another idea. Out of nowhere, you unexpectedly comprehend and acknowledge why you have been modifying a specific way your entire life.

Those are the “glimmer of the virtuoso” minutes.

A few days ago, my client gave me an exceptionally basic prerequisite. Make an Invoicing Record with Inversion Reason and Inversion date (It is called Auto Turning around Report in our venture). Kindly note, it isn’t inversion posting. It is a standard posting (Gathering/Deferral Doc) (utilizing t-code FBS1) which is prepared for switch posting (utilizing t-code F.81). Now let’s dive into on the how to pass Reversal Date & Reason to BAPI_ACC_DOCUMENT_POST?

Ordinary Record (t-code FB01) looks like underneath –

Accumulation/Deferral Doc (t-code FBS1) looks like beneath –

Check, it has Inversion Reason (STGRD) and Inversion Date (STODT) as obligatory header field.

With little experience, we discover that BAPI ‘BAPI_ACC_DOCUMENT_POST’ is the one which would assist us with posting bookkeeping archive.

Yet, the interesting part is, the DOCUMENTHEADER boundary has a field called inversion reason, yet it doesn’t have the inversion date.

Since the typical BAPI Boundaries and tables don’t have the necessary fields, hence we want to take help of the EXTENSION2 Tables Boundary of BAPI BAPI_ACC_DOCUMENT_POST.

The high level steps are:

  1. Pass structure ‘ACCIT’, valuepart1 as Reversal Date and valuepart2 as Reversal Reason in EXTENSION2 of BAPI
  2. Implement BADI ‘ACC_DOCUMENT’
  3. Modify C_ACCIT table in method ‘CHANGE’ of BADI ‘ACC_DOCUMENT’

Let’s do it.

1.     Pass values to EXTENSION2 of BAPI

 

2.     Implement BADI ‘ACC_DOCUMENT’

Go to t-code SE18 and provide the BADI name.

Check assuming the BADI is as of now executed in your undertaking. There isn’t custom execution in our undertaking.

Hit Implementation->Create

At the point when you attempt to initiate, it would give the beneath blunder.

BKPFF is the most ideal Reference for us.

When you give the channel, it enacts effectively.

On the off chance that you would be requested the New Upgrade Execution, simply give the name and text and raise a ruckus around town button.

 

3. Logic in method ‘CHANGE’ of BADI implementation

* Work area for Extension2 from BAPI
     DATA: lwa_extension2   TYPE bapiparex.
* Field Symbol for Accounting Interface: Item Information
     FIELD-SYMBOLS <ls_accit> TYPE accit.

*   C_ACCIT would have data. Just update the Reversal Reason and Date
     LOOP AT c_accit ASSIGNING <ls_accit>.

       READ TABLE c_extension2 INTO lwa_extension2
       WITH KEY structure = 'ACCIT'.

       IF sy-subrc = 0.

         <ls_accit>-stodt = lwa_extension2-valuepart1. " Reversal Reason
         <ls_accit>-stgrd = lwa_extension2-valuepart2. " Reversal Date

       ENDIF.

     ENDLOOP.

Enact the technique and afterward run your work which makes the record with Inversion Reason and Inversion Date. After the archive is made, go to t-code FB03 and actually look at the information.

T-Code FB03

Go to the header and check the inversion date and reason.

We are certain; somebody would definitely get this prerequisite in their task. Presently, you know what to do. In the event that there are different fields to be upgraded, the technique is something very similar. Improve the expansion and track down the perfect locations to populate the new augmentation fields.

The following is a code bit telling the best way to utilize the BAPI ‘BAPI_ACC_DOCUMENT_POST’ and furthermore pass the Extension2.

*&---------------------------------------------------------------------*
*&      Form CREATE_AUTO_REVERSING_DOC
*&---------------------------------------------------------------------*
*       Create Auto Reversing Document using BAPI
*----------------------------------------------------------------------*
FORM create_auto_reversing_doc .

   DATA : lwa_documentheader TYPE bapiache09,
          lwa_lease_map      TYPE zfi_lease_map,
          lwa_accountgl      TYPE bapiacgl09,
          wa_ar              TYPE bapiacar09,
          lwa_amount         TYPE bapiaccr09,
          lwa_return         TYPE bapiret2,
          lv_costc           TYPE kostl,
          lv_len             TYPE i,
          lt_accountgl       TYPE STANDARD TABLE OF bapiacgl09,
          lt_ar              TYPE STANDARD TABLE OF bapiacar09,
          lt_amount          TYPE STANDARD TABLE OF bapiaccr09,
          lt_return          TYPE STANDARD TABLE OF bapiret2.
   DATA:
     lt_extension2  TYPE STANDARD TABLE OF bapiparex,
     lwa_extension2 TYPE bapiparex,
     lv_next_month  TYPE sy-datum.

*   Document Header
   lwa_documentheader-obj_type        =     'BKPFF'.
   lwa_documentheader-obj_key         =     '$'.
   lwa_documentheader-obj_sys         =     sy-sysid.
   lwa_documentheader-bus_act         =     'RFBU'.
   lwa_documentheader-username        =     sy-uname.
   lwa_documentheader-doc_date        =     sy-datum.
   lwa_documentheader-comp_code       =     rec_detail-bukrs.   " Company code
   lwa_documentheader-pstng_date      =     sy-datum.           " posting date
   lwa_documentheader-doc_type        =     rec_detail-auto_rev_doc_ty.             " Document type J1 or J0
   lwa_documentheader-ref_doc_no      =     rec_detail-xblnr.   " REFERENCE
   lwa_documentheader-header_txt      =     rec_detail-sgtxt.   " Header text (also Line item level)

   READ TABLE it_lease_map INTO lwa_lease_map WITH KEY lease_group_id = rec_detail-lease_group.
   CLEAR lwa_accountgl.

   lwa_accountgl-itemno_acc  =  1. 
   IF rec_detail-auto_rev_doc_ty = 'J1'.
     lwa_accountgl-gl_account  =  lwa_lease_map-prepay_account.
   ELSEIF rec_detail-auto_rev_doc_ty = 'J0'.
     lwa_accountgl-gl_account  =  lwa_lease_map-acc_account.
   ENDIF.

   lwa_accountgl-de_cre_ind  =  'S'.

   lwa_accountgl-comp_code   =  rec_detail-bukrs.

   APPEND lwa_accountgl TO lt_accountgl .

   CLEAR lwa_accountgl.
   lwa_accountgl-itemno_acc  = 2.

   lwa_accountgl-gl_account  =  rec_detail-hkont.

   lwa_accountgl-de_cre_ind = 'H'.

   lwa_accountgl-comp_code   = rec_detail-bukrs.

   IF rec_detail-co_obj IS NOT INITIAL.

     CASE rec_detail-co_id.
       WHEN '1'.   " Cost Center
         CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
           EXPORTING
             input  = rec_detail-co_obj
           IMPORTING
             output = lwa_accountgl-costcenter.

         CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
           EXPORTING
             input  = lwa_accountgl-costcenter
           IMPORTING
             output = lv_costc.

         CONCATENATE '1'  lv_costc INTO lwa_accountgl-profit_ctr.

       WHEN '2'.   " WBS
         lwa_accountgl-wbs_element = rec_detail-co_obj.
       WHEN '3'.   " Order

         lv_len = strlen( rec_detail-co_obj ).
         IF lv_len LE 12.
*     Back fill zeros to Order
           CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
             EXPORTING
               input  = rec_detail-co_obj
             IMPORTING
               output = lwa_accountgl-orderid
             EXCEPTIONS
               OTHERS = 1.

         ENDIF.
       WHEN '4'. " Order

         lv_len = strlen( rec_detail-co_obj ).
         IF lv_len LE 12.
*     Back fill zeros to Order
           CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
             EXPORTING
               input  = rec_detail-co_obj
             IMPORTING
               output = lwa_accountgl-orderid
             EXCEPTIONS
               OTHERS = 1.

         ENDIF.
       WHEN '5'. " Profit Center

         lv_len = strlen( rec_detail-co_obj ).
         IF lv_len LE 10.
*     Back fill zeros to profit center
           CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
             EXPORTING
               input  = rec_detail-co_obj
             IMPORTING
               output = lwa_accountgl-profit_ctr
             EXCEPTIONS
               OTHERS = 1.
         ENDIF.
       WHEN OTHERS.
* do nothing
     ENDCASE.

   ENDIF.

   APPEND lwa_accountgl TO lt_accountgl .

*     Amount
   CLEAR lwa_amount.
   lwa_amount-itemno_acc = 1 .
   lwa_amount-currency   = 'USD' .
   lwa_amount-amt_doccur =  v_auto_rev_amount .
   APPEND lwa_amount TO lt_amount .

   CLEAR lwa_amount.
   lwa_amount-itemno_acc = 2 .
   lwa_amount-currency   = 'USD' .
   lwa_amount-amt_doccur = v_auto_rev_amount * -1 .
   APPEND lwa_amount TO lt_amount .

   CLEAR v_auto_rev_amount.

   REFRESH lt_extension2[].
* Pass the Reversal Reason and Date to the BAPI
   lwa_extension2-structure = 'ACCIT'.   " Accounting Interface: Item Information
   CALL FUNCTION '/MRSS/RMOR_GET_NEXT_MONTH'
     EXPORTING
       iv_date         = sy-datum
     IMPORTING
       ev_current_date = lv_next_month.
   lwa_extension2-valuepart1 = lv_next_month. " Reversal Month Date
   lwa_extension2-valuepart1+6(2) = '15'.  " Custom Requirement - Always make the date 15th of the next Month
   lwa_extension2-valuepart2 = '03'.  " Reversal Reason 03 = Accrual
   APPEND lwa_extension2 TO lt_extension2.
*   Post Accounting Document
   CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
     EXPORTING
       documentheader    = lwa_documentheader
     TABLES
       accountgl         = lt_accountgl
       accountreceivable = lt_ar
       currencyamount    = lt_amount
       return            = lt_return
       extension2        = lt_extension2.

   READ TABLE lt_return INTO lwa_return WITH KEY type  = 'S'
                                 id    = 'RW'
                                number = '605' .
   IF sy-subrc = 0 .
     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' .
     WRITE: lwa_return-type,
            lwa_return-id,
            lwa_return-number,
            lwa_return-message,
            lwa_return-message_v1,
            lwa_return-message_v2,
            lwa_return-message_v3,
            lwa_return-message_v4.
   ELSE.
     LOOP AT lt_return INTO lwa_return WHERE type = 'E' .
       WRITE: lwa_return-type,
              lwa_return-id,
              lwa_return-number,
              lwa_return-message,
              lwa_return-message_v1,
              lwa_return-message_v2,
              lwa_return-message_v3,
              lwa_return-message_v4.
     ENDLOOP.
   ENDIF.

ENDFORM.

Your criticism and remarks keep us rousing. Kindly keep them coming.

 

YOU MAY BE INTERESTED IN

ABAP for SAP HANA. ALV Report On SAP HANA – Opportunities And Challenges

ABAP Evolution: From Monolithic Masterpieces to Agile Architects

Extensive Tips and Tricks for Interactive SAP ALV

 

WhatsApp WhatsApp us