Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

zfields are successfully updated in VBAP but change is not logged

axelgoret
Discoverer
0 Kudos
1,089

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,
t_exten LIKE bapiparex OCCURS 0 WITH HEADER LINE,
t_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
bape_vbap LIKE bape_vbap,
bape_vbapx LIKE bape_vbapx,
order_headerx LIKE bapisdh1x,
       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'.

1 ACCEPTED SOLUTION

DominikTylczyn
Active Contributor
1,015

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.

  • objectid - sales order number goes here with leading zeros up to 10 chars if the number is numeric only
  • yvbap - table with VBAP values before change
  • xvbap - table with VBAP values after change
  • upd_vbap - you transfer X here, which is incorrect. Put U value.

Best regards

Dominik Tylczynski

7 REPLIES 7

DominikTylczyn
Active Contributor
1,015

Why are you calling VERKBELEG_WRITE_DOCUMENT after BAPI_SALESORDER_CHANGE? Change documents should be written by BAPI_SALESORDER_CHANGE itself.

axelgoret
Discoverer
0 Kudos
1,015

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"

juan_suros
Contributor
1,015

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.

DominikTylczyn
Active Contributor
1,016

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.

  • objectid - sales order number goes here with leading zeros up to 10 chars if the number is numeric only
  • yvbap - table with VBAP values before change
  • xvbap - table with VBAP values after change
  • upd_vbap - you transfer X here, which is incorrect. Put U value.

Best regards

Dominik Tylczynski

1,015

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 !

DominikTylczyn
Active Contributor
0 Kudos
1,015

That is how the change document function should be called: Filling the Fields in the Program

thkolz
Contributor
0 Kudos
1,015

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.