Hello everybody,
we are having a problem with the function modules CRM_BUPA_MKT_PERM_ADD and CRM_BUPA_MKT_PERM_SAVE_TABS. The problem is very similar to this post: Dump when adding Marketing permissions on Bill account in crm webui
We have implemented function module CRM_BUPA_MKT_PERM_ADD in the BAdI ORDER_SAVE. This BAdI implementation of ours is adding marketing permissions contact persons of leads.
Here is the process of how we are using the function modules:
- User saves a lead and triggers BAdI ORDER_SAVE
- BAdI ORDER_SAVE uses function module CRM_BUPA_MKT_PERM_ADD to add marketing permissions to contact person of lead
- In update process function module CRM_BUPA_MKT_PERM_SAVE_TABS is triggered
For saving the first lead everything is working great because internal table it_but_mktperm_insert[] of function module CRM_BUPA_MKT_PERM_SAVE_TABS contains only one entry (step 3).
When the user saves every next lead the internal table it_but_mktperm_insert[] of function module CRM_BUPA_MKT_PERM_SAVE_TABS in step 3 has more than one entry. In addition to the new entry it also contains the previous ones which will result in the following dump on executing the INSERT statement:
Runtime Error DBSQL_DUPLICATE_KEY_ERROR
Exception CX_SY_OPEN_SQL_DB
Terminated Program SAPLCRM_BUPA_MKTPERM_SAVE
I also created a small program in order to easily repeat this issue:
*&---------------------------------------------------------------------*
*& Report Y09_MKT_PERMS_DUMP
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT y09_mkt_perms_dump.
TABLES: but050.
SELECT-OPTIONS:
o_but050 FOR but050-partner2.
START-OF-SELECTION.
DATA:
lv_partner2 TYPE bu_partner,
ls_data TYPE crmt_but_mktperm_data,
lv_record_guid TYPE crmt_bu_mktperm_guid,
lv_error TYPE crmt_boolean,
lt_return TYPE bus_bapiret2_t.
BREAK-POINT.
LOOP AT o_but050 INTODATA(ls_but050).
CLEAR: lv_partner2, ls_data, lv_record_guid, lv_error, lt_return.
SELECTSINGLE partner1 INTO lv_partner2 FROM but050 WHERE partner2 = ls_but050-LOW.
CHECK sy-subrc =0.
SELECTSINGLE partner_guid INTO ls_data-contpguid FROM but000 WHERE partner = ls_but050-LOW.
CHECK sy-subrc =0.
SELECTSINGLE partner_guid INTO ls_data-partnerguid FROM but000 WHERE partner = lv_partner2.
CHECK sy-subrc =0.
ls_data-channel ='INT'.
ls_data-permission ='002'.
ls_data-origin ='YBO'.
ls_data-valid_from = sy-datum.
CALL FUNCTION'CRM_BUPA_MKT_PERM_ADD'
EXPORTING
is_data = ls_data
iv_x_save ='X'
IMPORTING
ev_record_guid = lv_record_guid
ev_error = lv_error
et_return = lt_return.
CHECK lv_error ISINITIAL.
CHECK lt_return ISINITIAL.
* COMMIT WORK AND WAIT.
"COMMIT inside the loop will cause dump DBSQL_DUPLICATE_KEY_ERROR
"during update process in function module CRM_BUPA_MKT_PERM_SAVE_TABS
ENDLOOP.
COMMIT WORKAND WAIT.
"COMMIT outside the loop will work properly because update process and therefore function
"module CRM_BUPA_MKT_PERM_SAVE_TABS is only triggered once and all entries of internal
"table it_but_mktperm_insert[] will be inserted into db table CRMM_BUT_MKTPERM at once
BREAK-POINT.
How do I solve this situation within the BAdI call of ORDER_SAVE? Putting the COMMIT inside or outside the loop is easy, but how do I do that when it comes to ORDER_SAVE BAdI?
Any help will be appreciated.
Best regards
Sascha