2023 Aug 08 3:25 PM
Hi,
I have a requirement in which I have to create a custom program to update zfields of certain records in VBAP standard table.
I used BAPI_SALESORDER_CHANGE FM to operate the update and BAPI_TRANSACTION_COMMIT, and it is working, the record is successfully updated. However, the change is not written in changelog of sales order.
Upon further inspection, Tables CDHDR and CDPOS contain no record of the update.
Both the zfields I am updating are correctly appended to VBAP, and also appended in BAPE_VBAP, BAPE_VBAPX, VBAPKOZ and VBAPKOZX, and the data element of both fields have change doc ticked, VBAP table is not ticked for logs.
How could I do to have the changes visible in changelog ?
Below is my source code :
DATA: t_line LIKE bapisditm OCCURS 0 WITH HEADER LINE,
t_linex LIKE bapisditmx OCCURS 0 WITH HEADER LINE,
lt_icdtxt_verkbeleg TYPE TABLE OF cdtxt.
order_headerx-updateflag = 'U'.
t_line-itm_number = ls_vbap-posnr.
t_line-material = ls_vbap-matnr.
t_line-hg_lv_item = ls_vbap-uepos.
APPEND t_line.
t_linex-itm_number = ls_vbap-posnr.
t_linex-updateflag = 'U'.
APPEND t_linex.
CLEAR bape_vbap.
bape_vbap-vbeln = ls_vbap-vbeln.
bape_vbap-posnr = ls_vbap-posnr.
bape_vbap-zz_qte_refer = ls_vbap-kwmeng.
bape_vbap-zz_unit_refer = ls_vbap-vrkme.
t_exten-structure = 'BAPE_VBAP'.
t_exten-valuepart1 = bape_vbap.
APPEND t_exten.
CLEAR bape_vbapx.
bape_vbapx-vbeln = ls_vbap-vbeln.
bape_vbapx-posnr = ls_vbap-posnr.
bape_vbapx-zz_qte_refer = 'X'.
bape_vbapx-zz_unit_refer = 'X'.
t_exten-structure = 'BAPE_VBAPX'.
t_exten-valuepart1 = bape_vbapx.
APPEND t_exten.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = ls_vbap-vbeln
order_header_inx = order_headerx
TABLES
return = t_return
order_item_in = t_line
order_item_inx = t_linex
extensionin = t_exten.
CALL FUNCTION 'VERKBELEG_WRITE_DOCUMENT'
EXPORTING
objectid = CONV cdhdr-objectid( ls_vbap-vbeln )
tcode = sy-tcode
utime = sy-uzeit
udate = sy-datum
username = sy-uname
upd_vbap = 'X'
TABLES
icdtxt_verkbeleg = lt_icdtxt_verkbeleg.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
2023 Aug 09 8:14 AM
Hello axel.goret
As I said in the comment BAPI_SALESORDER_CHANGE should create change documents by itself. I have not found any support note about change documents limitations in the BAPI. So if you have problems with change documents here, I'd suggest opening an OSS incident and seeking SAP support assistance.
If you still need to create sales order change documents manually, outside the BAPI call, you need to do it right - see SAP Help on Filling the Fields in the Program, e.g.
Best regards
Dominik Tylczynski
2023 Aug 08 3:46 PM
2023 Aug 08 3:50 PM
To be honest, it was just to try and see if it worked with VERKBELEG_WRITE_DOCUMENT. Using BAPI_SALESORDER_CHANGE did not log the change. When I go to Environment -> Changes, i get the following message "No changes carried out"
2023 Aug 08 4:51 PM
When calling function module VERKBELEG_WRITE_DOCUMENT, it is not enough to set update parameter upd_vbap.
You must also supply the old and new values of the VBAP structure in table parameters yvbap and xvbap.
2023 Aug 09 8:14 AM
Hello axel.goret
As I said in the comment BAPI_SALESORDER_CHANGE should create change documents by itself. I have not found any support note about change documents limitations in the BAPI. So if you have problems with change documents here, I'd suggest opening an OSS incident and seeking SAP support assistance.
If you still need to create sales order change documents manually, outside the BAPI call, you need to do it right - see SAP Help on Filling the Fields in the Program, e.g.
Best regards
Dominik Tylczynski
2023 Aug 09 9:14 AM
Hello, thanks for taking your time to answer my query, it worked for me, despite my search I did not find the SAP Help page you linked but you ended up solving my problem !
Many thanks !
2023 Aug 09 8:15 AM
That is how the change document function should be called: Filling the Fields in the Program
2023 Aug 09 9:10 AM
How about to do a dummy change for example in the line item text SHORT_TEXT?
t_line-short_text = t_line_short_text && ' '.
t_linex-short_text = abap_true.
From my point of view, you're also missing the following:
t_linex-material = abap_true.
t_linex-hg_lv_item = abap_true.