Sorun Cevaplayalım

İşinizle ilgili öngörüler edinin, gerçek zamanlı bilgilere göre karar alın.

SAP Eğitim ve Sertifika Dönemleri

Uzmanlığınızı ve deneyiminizi SAP çözümleri kullanarak tasdik edin.

Çözüm Ekibi Başvurusu

Kullanıcılara hızlı ve pratik çözümler üreterek görev almak isteyenler.

SAP BLOG Enlarging the use of BAPI_ACC_DOCUMENT_POST

SAP Blog

Kayıtlı Üye
Katılım
22 Ara 2017
Mesajlar
1,045
Tepki puanı
6
Dear SCN Friends,

I would like to share some tips related to the use of BAPI_ACC_DOCUMENT_POST and how to enlarge the use of this powerfull BAPI for Accounting Post.

For a long time, I’ve been using the BAPI_ACC_DOCUMENT_POST in my solutions. It is much better than the Transaction Call Technique (CALL_TRANSACTION of FB01 for example) for many reasons listed below:

  • You can simulate the document creation usine BAPI_ACC_DOCUMENT_CHECK before commit.
  • The Z Transaction Code is recorded in the BKPF table (Field TCODE) where you can see in the document display (FB03). So, you can track where the posting came from.
  • You don’t have Screen Layout/Field Status errors like in Transaction Call.

Because of these reasons and many others I prefer to use the BAPI_ACC_DOCUMENT_POST.

In the previous months I’ve been researching about this BAPI to find some answers to the following questions that I have in mind:



  • Why is not possible to use the BAPI_ACC_DOCUMENT_POST to posting Noted Items and/or Special G/L Transactions ? There is no input parameter to determine the Special GL Indicators.
  • Why we can’t change the Posting Key of the BAPI_ACC_DOCUMENT_POST ? We don´t have the posting key in the Parameter Tables to use. It determines automatically (40/50 for G/L Accounts, 31/21 for vendor sub-ledger, etc.)
  • Ledger Specific Posting

So, I found out some improvements to be done to enlarge the use of the BAPI_ACC_DOCUMENT_POST that I would like to share to you.

Let’s get straight to the point, technical SAP allow us to Change the Accounting Document thru BAdI BADI_ACC_DOCUMENT (Interface IF_EX_ACC_DOCUMENT). In this BAdI there is a CHANGE Method. Check the parameters bellow:



BADI-Parameters.png




As we can see, Header, Item, Currency and WHT tables are available there to be changed. These structures are much more complete than the input parameters of BAPI*.

* Note that the structure C_EXTENSION2 appears at this point.



I’ve been researching about the use of EXTENSION2 table, and I could not find an specific use of this structure in the FI accounting post. Many posts in the internet mention only the EXTENSION1.



In the processing of BAPI_ACC_DOCUMENT_POST table EXTENSION2 is not used, the Method Change of BAdI is called with the information in EXTENSION2 change the structures of the accounting document ACCHD, ACCIT, ACCCR, ACCWT, etc:



BAPI-BAdI-Source-Code.png




So, the idea here is to use the EXTENSION2 table in BAPI_ACC_DOCUMENT_POST and create some dynaimc ABAP code in the BAdI to add the additional information in the accounting tables.



We have set the logic of the EXTENSION2 as below:



Structure-Extension-2.png




STRUCTURE: The structure to be changed or added (ACCOUNTGL, ACCOUNTRECEIVABLE, ACCOUNTPAYABLE or DOCUMENTHEADER)

VALUEPART1: Line Item ID (ITEMNO_ACC)

VALUEPART2: The Structure/Table to be modified in the BADI (C_ACCHD, C_ACCIT, C_ACCCR, C_ACCWT)

VALUEPART3: The field of the Structure/Table to be modified in the BADI (C_ACCHD, C_ACCIT, C_ACCCR, C_ACCWT)

VALUEPART4: The value to be endered or change in the the Structure/Table to be modified in the BADI.



EXAMPLE


The example below, I will post an Customer Down Payment Request.



The following information/data should be informed in EXTENSION2 table to have the down payment request working:



C_ACCIT-BSTAT Document Status: ‘S’ for noted items

C_ACCIT-ZUMSK Target Special G/L Indicator: ‘A’ for Down Payment Request

C_ACCHD-GLVOR Business Transaction: ‘RFST’ FI: Statistical postings



The standards of BAPI_ACC_DOCUMENT_POST does not allow the modification on these parameters, so the BAdI changind the accounting data with the information in EXTENSION2 will help us. Check the parameters:



BADI-Parameters-2.png




Check how the structure EXTENSION2 is filled:



Structure-Extension-2-Filled.png




Note that the DOCUMENTHEADER there is no VALUPART1, the line item because is a change in the header of the document C_ACCHD table.



Let´s see how the BAdI source code is being designed to interpret that and change the tables.



BAdI-Debug.png




Check the ABAP source code below that we developed to dynamicly interpret the EXTENSION2 and change the structures:



METHOD if_ex_acc_document~change.

*** Local variable
DATA: lt_extension2 TYPE STANDARD TABLE OF bapiparex.

*** Pointers
FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE,
<fs_header> TYPE any,
<fs_field> TYPE any,
<fs_ext> TYPE bapiparex,
<fs_ext2> TYPE bapiparex.

*** Delete duplicate records
lt_extension2[] = c_extension2[].
SORT lt_extension2 BY structure ASCENDING
valuepart1 ASCENDING
valuepart2 ASCENDING.
DELETE ADJACENT DUPLICATES FROM lt_extension2 COMPARING structure
valuepart1
valuepart2.

*** Read all values to update
LOOP AT lt_extension2 ASSIGNING <fs_ext>.

*** Search inside a internal table
IF NOT <fs_ext>-valuepart1 IS INITIAL.

*** Get Table value
UNASSIGN <fs_table>.
ASSIGN (<fs_ext>-valuepart2) TO <fs_table>.

*** Found data
CHECK sy-subrc = 0.

*** Try get values
TRY.

*** Get table
READ TABLE <fs_table> WITH KEY
('BAPI_PARAM') = <fs_ext>-structure
('BAPI_TABIX') = <fs_ext>-valuepart1
ASSIGNING <fs_header>.

*** Found record - Update Fields
CHECK sy-subrc = 0.

*** Get all fields of same position
LOOP AT c_extension2 ASSIGNING <fs_ext2>
WHERE structure = <fs_ext>-structure
AND valuepart1 = <fs_ext>-valuepart1
AND valuepart2 = <fs_ext>-valuepart2.

*** Get field
UNASSIGN <fs_field>.
ASSIGN COMPONENT <fs_ext2>-valuepart3 OF STRUCTURE <fs_header>
TO <fs_field>.

*** Update new value
CHECK sy-subrc = 0.

<fs_field> = <fs_ext2>-valuepart4.

ENDLOOP.

*** Error at read table
CATCH cx_root.
UNASSIGN <fs_table>.
ENDTRY.

*** Header Case
ELSE.

*** Get Header
UNASSIGN <fs_header>.
ASSIGN (<fs_ext>-valuepart2) TO <fs_header>.

*** Found data
CHECK sy-subrc = 0.

*** Get all fields of same position
LOOP AT c_extension2 ASSIGNING <fs_ext2>
WHERE structure = <fs_ext>-structure
AND valuepart1 = <fs_ext>-valuepart1
AND valuepart2 = <fs_ext>-valuepart2.

*** Get field
UNASSIGN <fs_field>.
ASSIGN COMPONENT <fs_ext2>-valuepart3 OF STRUCTURE <fs_header>
TO <fs_field>.

*** Update new value
CHECK sy-subrc = 0.

<fs_field> = <fs_ext2>-valuepart4.

ENDLOOP.

ENDIF.

ENDLOOP.

ENDMETHOD.



In the end, the document is posted



Document-Posted-1.png




This can be done with another fields or purpose, not only for Down Payment or Special G/L documents.



I never saw this kind of solution to enlarge the use of the BAPI_ACC_DOCUMENT_POST in other customers. So I hope I could share some help for you guys that is looking for something related to this post.



Please, if you will do something like this solutton, pay attention in the fields that you change in the accounting posting to not generate inconsistence postings. For example, in the special g/l transactions you must define Business Transaction as ‘RFST’ otherwise FAGLFLEXA and FAGLFLEXT will be filled when should not.



Test the scenarios carefully and enjoy it !



Best regards,



Gabriel Coleti

Okumaya devam et...
 
Üst