Steps To Use EXTENSION Table in SAP BAPI
Steps To Use EXTENSION Table in SAP BAPI
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.
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).
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
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 |
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
1. Pass structure ‘ACCIT’, valuepart1 as Reversal Date and valuepart2 as Reversal Reason in
EXTENSION2 of BAPI
Let’s do it.
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 |
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
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
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
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 <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.</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
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.
Below is a code snippet showing how to use the BAPI ‘BAPI_ACC_DOCUMENT_POST’ and
also pass the Extension2.
<code>*&---------------------------------------------------------------------*
*& Form CREATE_AUTO_REVERSING_DOC
*&---------------------------------------------------------------------*
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 |
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 |
Oracle Upgrade
String wrap
Steps to add custom Tab in standard MIRO item screen using BADI
MRM_ITEM_CUSTFIELDS
Sales Office Data … Can you change it even if config does not allow?
How to Compel SAP Users to Go To Particular Transactions as per Roles after Log On?
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 |
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