Professional Documents
Culture Documents
Community
Technical Articles
Gaurav Karkara
August 29, 2020 | 5 minute read
BAPI_ACC_DOCUMENT_POST –
Vendor Down payment: Update
Purchase order info and PO history
Follow
1 7 4,649
Like
There usually is a requirement to post accounting documents in S/4HANA through
an interface, program or an enhancement. Irrespective of the trigger point, BAPI
RSS Feed ‘BAPI_ACC_DOCUMENT_POST’ does its job well and used extensively in custom
developments.
https://blogs.sap.com/2020/08/29/bapi_acc_document_post-vendor-down-payment-update-purchase-order-info-and-po-history/ 1/7
8/8/23, 11:11 BAPI_ACC_DOCUMENT_POST – Vendor Down payment: Update Purchase order info and PO history | SAP Blogs
generated document number, which doesn’t happen using BAPI. Mostly, having PO
information and PO history update is an important requirement to achieve for
customer for various reasons and above BAPI doesn’t provide for this requirement.
In this blog post, I am going to explain the solution we implemented to achieve above
requirement.
Transaction GGB1 –> Financial Accounting -> Line Item (since we want to substitute
a line item level information) -> Create a substitution using menu Substitution ->
create or edit the one already existing -> Add a new step(Edit -> Insert Step) ->
Choose the particular field that you want to substitute or just use option as ‘Exit’ as
shown below:
Define an exit number starting with 9. You have the option to set some prerequisites
as well e.g. if you want to trigger the substitution for a particular document type.
While you make all above settings and save, system doesn’t ask for any transport
request.
To transport these substitution settings, choose your substitution and use menu
Substitution -> Transport. On the next screen, uncheck ‘Logical Rules’ and execute
thus save your settings in a TR.
https://blogs.sap.com/2020/08/29/bapi_acc_document_post-vendor-down-payment-update-purchase-order-info-and-po-history/ 2/7
8/8/23, 11:11 BAPI_ACC_DOCUMENT_POST – Vendor Down payment: Update Purchase order info and PO history | SAP Blogs
These settings will make substitutions trigger your custom program, instead of
standard program RGGBS000.
FORM U901.
*Write your code here
ENDFORM.
In this subroutine, we check the fields ESRRE and ESRNR from BSEG and
accordingly populate the EBELN and EBELP fields. You may include other pre-
conditions here as well before updating these fields. BSEG and BKPF tables contain
runtime data.
https://blogs.sap.com/2020/08/29/bapi_acc_document_post-vendor-down-payment-update-purchase-order-info-and-po-history/ 3/7
8/8/23, 11:11 BAPI_ACC_DOCUMENT_POST – Vendor Down payment: Update Purchase order info and PO history | SAP Blogs
Above code should update the Purchase order and line item number for a generated
document.
It is also possible that even after writing above logic, required information is not
updated. Then, check below information:
1. Go to SM30 and Open maintenance view ‘VWTYGB01’. Check for BSEG- EBELN
and BSEG-EBELP entries:
If ‘Exclude’ checkbox is ticked, please uncheck it and save the entries, in a
transport.
2. Execute program ‘RGUGBR00’ to regenerate the substitutions. You should run
this program in each system also after TR movements.
You can use above steps to update any other field as well, just do the required coding
in routine and make sure fields are not excluded from substitutions.
PO History Update
To update the PO history, we have to implement a BTE:
https://blogs.sap.com/2020/08/29/bapi_acc_document_post-vendor-down-payment-update-purchase-order-info-and-po-history/ 4/7
8/8/23, 11:11 BAPI_ACC_DOCUMENT_POST – Vendor Down payment: Update Purchase order info and PO history | SAP Blogs
This BTE gets triggered just before posting the document and system has completed
all its checks. It is important not to change any field value in this BTE as there won’t
be any further system checks and an undesired value can get updated in the
database.
We will just read the purchase order information and update the PO history.
Implement the BTE and in the BTE function module, mention below code (make sure
that code is triggering only for your interface using any document value or memory
id, we don’t want standard transaction executing our code):
*-- We are updating this local table to track if we have updated any v
*-- reverse the same after updating PO History.
APPEND INITIAL LINE TO lt_bseg ASSIGNING FIELD-SYMBOL(<lfs_bse
<lfs_bseg_elm> = CORRESPONDING #( <lfs_bseg> ).
ENDIF.
ENDLOOP.
*-- Clear the Po Number and Po Item - If we have updated above, Keepi
LOOP AT lt_bseg ASSIGNING <lfs_bseg_elm>.
READ TABLE t_bseg ASSIGNING <lfs_bseg> WITH KEY bukrs = <lfs_bse
belnr = <lfs_bse
gjahr = <lfs_bse
buzei = <lfs_bse
IF sy-subrc IS INITIAL.
CLEAR: <lfs_bseg>-ebeln,
https://blogs.sap.com/2020/08/29/bapi_acc_document_post-vendor-down-payment-update-purchase-order-info-and-po-history/ 5/7
8/8/23, 11:11 BAPI_ACC_DOCUMENT_POST – Vendor Down payment: Update Purchase order info and PO history | SAP Blogs
<lfs_bseg>-ebelp.
ENDIF.
ENDLOOP.
Alert Moderator
Assigned Tags
SAP S/4HANA
ABAP Development
FIN (Finance)
BAPI_ACC_DOCUMENT_POST
Related Questions
BAPI for F-59
By Fatima Mustafayeva Apr 21, 2023
https://blogs.sap.com/2020/08/29/bapi_acc_document_post-vendor-down-payment-update-purchase-order-info-and-po-history/ 6/7
8/8/23, 11:11 BAPI_ACC_DOCUMENT_POST – Vendor Down payment: Update Purchase order info and PO history | SAP Blogs
Net price from the PO is not updated in Info record, while automatic creation of Info record
By Venu Pappula Nov 11, 2022
BRF+ configuration to trigger PO by email to vendor and purchase group in S4H 2021
By Claire Chambers Jan 18, 2023
1 Comment
Chris Mills
December 14, 2022 at 8:03 am
Hey Gaurav. Hope you've been doing well? Thanks for the post, was just what I needed! I ended up doing it
slightly different using BADI_ACC_DOCUMENT to pull in the fields from extension2 rather than using
substitution but is same result. The BTE idea was very handy. Thanks - Chris
Like 0 | Share
Find us on
Newsletter Support
https://blogs.sap.com/2020/08/29/bapi_acc_document_post-vendor-down-payment-update-purchase-order-info-and-po-history/ 7/7