100% found this document useful (1 vote)
5K views16 pages

Steps To Use EXTENSION Table in SAP BAPI

The document discusses how to use the EXTENSION2 table parameter of the BAPI_ACC_DOCUMENT_POST API to pass a reversal date and reason when posting an accounting document in SAP. The key steps are: 1. Pass the reversal date and reason values to the EXTENSION2 parameter of the BAPI using the ACCIT structure. 2. Implement the ACC_DOCUMENT BADI to modify the C_ACCIT table in the CHANGE method. 3. In the CHANGE method, read the EXTENSION2 table, and update the reversal date and reason fields in C_ACCIT with the values from EXTENSION2. This allows posting a document with the additional
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
5K views16 pages

Steps To Use EXTENSION Table in SAP BAPI

The document discusses how to use the EXTENSION2 table parameter of the BAPI_ACC_DOCUMENT_POST API to pass a reversal date and reason when posting an accounting document in SAP. The key steps are: 1. Pass the reversal date and reason values to the EXTENSION2 parameter of the BAPI using the ACCIT structure. 2. Implement the ACC_DOCUMENT BADI to modify the C_ACCIT table in the CHANGE method. 3. In the CHANGE method, read the EXTENSION2 table, and update the reversal date and reason fields in C_ACCIT with the values from EXTENSION2. This allows posting a document with the additional
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

26/4/2021 Steps to use EXTENSION table in SAP BAPI |

How to pass Reversal Date & Reason to


BAPI_ACC_DOCUMENT_POST?
By SAP Yard - February 27, 2019

Shares

One reason why the programmer’s job is the most exciting one is; you learn new stuff every
day. No matter, whether you are a fresher or a developer with more than decades of
experience. Every other day, you learn about a new syntax. You get to know about a new
concept. Out of the blue, you suddenly understand and realize why you have been
programming a certain way your whole life.

Those are the “flash of the genius” moments.

The other day, my client gave me a very simple requirement. Create an Invoicing
Document with Reversal Reason and Reversal date (It is called Auto Reversing
Document in our project). Please note, it is not reversal posting. It is a regular posting
(Accrual/Deferral Doc) (using t-code FBS1) which is ready for reverse posting (using t-code
F.81).

Normal Document (t-code FB01) looks like below –

https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 1/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |

Shares

Accrual/Deferral Doc (t-code FBS1) looks like below –

Check, it has Reversal Reason (STGRD) and Reversal Date (STODT) as mandatory header
field.

https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 2/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |

Also Read – My first ABAP Program in S/4HANA

With little experience, we learn that BAPI ‘BAPI_ACC_DOCUMENT_POST’ is the one


which would help us to post accounting document.

But the tricky part is, the DOCUMENTHEADER parameter has a field called reversal reason,
but
Shares it does not have the reversal date.

Since the normal BAPI Parameters and tables do not have the required fields, therefore we
need to take help of the EXTENSION2 Tables Parameter of BAPI
BAPI_ACC_DOCUMENT_POST.

https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 3/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |

Shares

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

Also Check – GPS like tool in SAP using Google Map API

https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 4/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |

2.     Implement BADI ‘ACC_DOCUMENT’


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

Shares

Check if the BADI is already implemented in your project. There is not custom
implementation in our project.

Hit Implementation->Create

https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 5/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |

Shares

When you try to activate, it would give the below error.

BKPFF is the Reference for us.

https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 6/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |

Shares

Once you provide the filter, it activates successfully.

If you would be asked for the New Enhancement Implementation, just give the name and
text and hit the create button.

https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 7/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |

Shares

Also Check – Create your first OData Service

3.     Logic in method ‘CHANGE’ of BADI


implementation

https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 8/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |

Shares

 
<code>* Work area for Extension2 from BAPI
     DATA: lwa_extension2   TYPE bapiparex.
* Field Symbol for Accounting Interface: Item Information
     FIELD-SYMBOLS &lt;ls_accit> TYPE accit.
 
*   C_ACCIT would have data. Just update the Reversal Reason and Date
     LOOP AT c_accit ASSIGNING &lt;ls_accit>.
 
       READ TABLE c_extension2 INTO lwa_extension2
       WITH KEY structure = 'ACCIT'.
 
       IF sy-subrc = 0.
 
         &lt;ls_accit>-stodt = lwa_extension2-valuepart1. " Reversal Reason
         &lt;ls_accit>-stgrd = lwa_extension2-valuepart2. " Reversal Date
 
       ENDIF.
 
     ENDLOOP.</code>

Activate the method and then run your job which creates the document with Reversal
Reason and Reversal Date. After the document is created, go to t-code FB03 and check the
data.

T-Code FB03

https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 9/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |

Shares

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

We are sure; someone would surely get this requirement in their project. Now, you know
what to do. If there are other fields to be enhanced, the method is the same. Enhance the
extension and find the right place to populate the new extension fields.

Free Video Training on SAP Debugging – SAP Debugging for Non-Technical


Consultants and ABAP Beginners

Below is a code snippet showing how to use the BAPI ‘BAPI_ACC_DOCUMENT_POST’ and
also pass the Extension2.

 
<code>*&amp;---------------------------------------------------------------------*
*&amp;      Form CREATE_AUTO_REVERSING_DOC
*&amp;---------------------------------------------------------------------*

https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 10/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |
*       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,
Shares
          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.             " Doc
   lwa_documentheader-ref_doc_no      =     rec_detail-xblnr.   " REFERENCE
   lwa_documentheader-header_txt      =     rec_detail-sgtxt.   " Header text (also Line
 
   READ TABLE it_lease_map INTO lwa_lease_map WITH KEY lease_group_id = rec_detail-lease_
   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'
https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 11/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |
           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 ).
Shares
         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 .
https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 12/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |
 
   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
Shares
   lwa_extension2-valuepart1+6(2) = '15'.  " Custom Requirement - Always make the date 15
   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.</code>

Your feedback and comments keep us motivating. Please keep them coming.

COMMENTS PLEASE!!!

We have a very active Telegram (App) SAP Technical Group with more than
4200+ SAP Technical Practitioners from 6 Continents of the SAP World. Please
join it using below link.
Telegram SAP Technical Discuss Group. You need to install the Telegram App first
on your mobile device. Once you have it on your mobile, you can join the group
and also access it from the Web on your computer and laptop.

https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 13/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |

Some Useful Enhancements in SAP

Shares

https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 14/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |

Automatic Population of Values during Table Maintenance

How to find BAdIs

Oracle Upgrade

Adding output message to a quotation/order/delivery/invoice

Add events in the table to meet custom requirements

Calling SAP Menu Areas From Program


Shares
Pop Up Screen with Selection Option using FM POPUP_WITH_TABLE_DISPLAY

Central Address Management (CAM) in MK02

String wrap

Send RV80HGEN as executable program in transport request to activate VOFM routines

Add custom fields in standard MIRO header screen through BADI_FDCB_SUBBAS01

PO re-price issue in BAPI_PO_CHANGE

Steps to add custom Tab in standard MIRO item screen using BADI
MRM_ITEM_CUSTFIELDS

How to change the Maintenance Plan Category in T-code IP02?

Sales Office Data … Can you change it even if config does not allow?

Unwanted error: Maintenance planning plant xxxx not permitted

BAPI_ALM_ORDER_MAINTAIN terminates with the runtime error MESSAGE_TYPE_X

Handle the Handle Classes correctly

Playing Sherlock Holmes to detect CONVT_CODEPAGE runtime error mystery

How to update custom field of PRPS table

GPS like tool in SAP using Google Map API

How to Compel SAP Users to Go To Particular Transactions as per Roles after Log On?

How to Add Customized Node in SPRO?

eWay Bill Setup and Configuration Guide [2018 India Version]

SO10 Enhancement to Add Texts to the Transport Request Automatically

Dynamic Patterns – Let’s Automate the Documentation in SAP ABAP

FI Accounting Validation using T-code GGB0

How to pass Reversal Date & Reason to BAPI_ACC_DOCUMENT_POST?

SOLMAN – Mail Forms Custom Enhancement Guide

SOLMAN – Understanding Attribute Context & Action Profile in Mail Forms

Dynamically Download Data From Any SAP Table in ABAP-740 – Part 1

How to Add a Custom Tab/Sub-Screen in Material Master (T-Code MM01)?

How to Append Standard Tables having Replacement Objects in S/4HANA

How to Add Coding Blocks in SAP FI – Enjoy Transactions?

https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 15/16
26/4/2021 Steps to use EXTENSION table in SAP BAPI |

How to Remove Coding Blocks in SAP FI – Enjoy Transactions?

Shares
SAP Yard
https://sapyard.com/

SAPYard is one stop page for all Technical Folks in SAP. You would find un-conventional explanations,
tutorials, tricks and end to end Free SAP Video Courses and Training. Please like our Facebook Page, follow
us at Twitter, Instagram and also join our LinkedIn Group. Please Subscribe to our Youtube Channel for
Free SAP Video Trainings.

      

https://sapyard.com/how-to-pass-reversal-date-reason-to-bapi_acc_document_post/ 16/16

You might also like