BAPI_ADDRESSORG_CHANGE does not work correctly, I'm trying to update the address and also notes (remark) from XD02 with this BAPI but it does not work, I don't know what I'm doing wrong maybe you guys could help me with this issue.
I tried with this:
* Assign the following object type and object key to a main customer address
objtype = 'KNA1'.
obj_id = lv_kunnr.
CALL FUNCTION 'BAPI_ADDRESSORG_GETDETAIL' " ---> Chequear BAPI, nos elimina el dato wa_excel_data-kunnr
EXPORTING
obj_type = objtype
obj_id = obj_id
context = context
IMPORTING
address_number = lv_adrnr
TABLES
bapiadsmtp = gt_bapiadsmtp
return = return.
IF sy-subrc EQ 0.
READ TABLE gt_tables_for_excel INTO wa_tables_for_excel WITH KEY "addrnumber = lv_adrnr
smtp_addr = wa_excel_data-smtp_addr.
IF sy-subrc EQ 0.
wa_bapiadsmtp-e_mail = wa_excel_data-smtp_addr.
wa_bapiadsmtp-consnumber = 001.
wa_bapiadsmtx-e_mail = 'X'.
wa_bapiadsmtx-updateflag = 'U'.
ELSE.
wa_bapiadsmtp-std_no = 'X'.
wa_bapiadsmtp-e_mail = wa_excel_data-smtp_addr.
wa_bapiadsmtp-consnumber = 001.
wa_bapiadsmtx-updateflag = 'I'.
ENDIF.
APPEND wa_bapiadsmtp TO gt_bapiadsmtp.
APPEND wa_bapiadsmtx TO gt_bapiadsmtx.
CLEAR: wa_bapiadsmtp, wa_bapiadsmtx, wa_bapicomrem, wa_bapicomrex.
CALL FUNCTION 'BAPI_ADDRESSORG_CHANGE'
EXPORTING
obj_type = objtype
obj_id = obj_id
obj_id_ext = obj_id_ext
save_address = 'X'
context = context
IMPORTING
address_number = lv_adrnr
TABLES
bapiadsmtp = gt_bapiadsmtp
bapiadsmt_x = gt_bapiadsmtx
return = return.
IF sy-subrc = 0.
WRITE : / 'ADRT update :', wa_excel_data-name1.
ELSE.
WRITE : / 'ADRT couldn't update : ', wa_excel_data-name1.
ENDIF.
ENDIF.
Some lines of code are commented since I tried everything I could think or found on the docs.
I see that you are looking at sy-subrc after BAPI, but BAPI does not return EXCEPTIONS. This BAPI returns a return table containing the error messages. It is worth checking to see if there are any errors in this. If so, you can go from there to see what exactly needs to be fixed.
Otherwise, I currently see several sources of errors that could lead to poblems. Alternatively, it is not clear.
wa_bapiadsmtx-e_mail = 'X'.save_address = 'X'?CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.Suddenly these questions/solutions came to mind. But I will try to help if you can look them up or clarify.
Updated: the following code works for me.
I checked the corresponding address in the ADRC6 table.
For INSERT, it depends on the number of CONSNUMBER elements to be included, so it is a good idea to select them with the BAPI_ADDRESSORG_GETDETAIL function beforehand. Or use simple 001.
For UPDATE, the record must exist (this can also be checked).
The error messages determine which value you will be able to edit, here you may get errors if you have different time zones or incomplete data. These need to be handled. But BAPI_TRANSACTION_COMMIT is definitely missing for you.